Hi,
The code below behaves differently on a Mac than on a PC. I think this might be since Unity3.
The problem is that on a Mac, I do not get Input.anyKeyDown or Input.GetKeyDown once the Textfield has focus.
The reason I want to do this is so that I can detect if the enter or arrow keys are pressed while a chat window is open and automatically send or close the window, and return to navigation mode.
I had some look at events. I think I could detect a return this way but not arrows.
Is there another way to do this and is this a bug that I should report?
using UnityEngine;
using System.Collections;
public class KeyFocusTest : MonoBehaviour {
// Use this for initialization
public string myText = "Set focus here";
void OnGUI()
{
myText = GUI.TextField( new Rect( 0,0, 300, 300 ), myText );
}
// Update is called once per frame
void Update ()
{
if (Input.anyKeyDown)
{
Debug.Log("anyKeyDown!");
}
if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("GetKeyDown:Return!");
}
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
Debug.Log("GetKeyDown:LeftArrow!");
}
}
}