Up/Down arrow in Text Field

Hi,

I’ve tried for several hours and read all posts on textfield handling, but everything covers only basic keys like Return, etc. and I’m kinda stuck now.

Basically I want to know when a user has pressed the Up-Arrow or Down-Arrow in a textfield. I need to make sure this is only applied when the key is down, i.e. before any repaint events etc.

Below a code that can be applied directly. It seems impossible to me to get it to print BLEH if you press the UpArrow like this. Any advice? Again, it is important this is done at the KeyDown event, not any other.

public class Testing : MonoBehaviour {
	
	private string input = "";

	void OnGUI() {		
		GUI.SetNextControlName("Input");
		this.input = GUILayout.TextField(this.input);
		
		GUI.FocusControl("Input");
		
		if ((Event.current.keyCode == KeyCode.UpArrow) && (Event.current.type == EventType.KeyDown)) {
			print ("BLEH");
		}
	}

}

Well, it turns out that once the textfield is there, it will eat all input. So in order to get the above example to work, simply put the key logic right before the textfield is displayed:

public class Testing : MonoBehaviour {
	
	private string input = "";

	void OnGUI() {		
		if ((Event.current.keyCode == KeyCode.UpArrow) && (Event.current.type == EventType.KeyDown)) {
			print ("BLEH");
		}

		GUI.SetNextControlName("Input");
		this.input = GUILayout.TextField(this.input);
		
		GUI.FocusControl("Input");
		
	}

}