- Home /
Question by
Olgo · Jul 15, 2014 at 08:04 PM ·
guifocusgetkeydown
How does unity focus GUI when different keys are pressed?
The following script enables a text field, the last function enables it using either the enter key or forward slash key. The problem is you need to press forward slash twice, just to get it to work the same way you would by pressing enter.
Does unity do anything with GUI focus when enter is pressed as opposed to when slash or any other key is pressed?
Thanks
void EventLogWindowContent (int id){
if( displayInputField ){
GUI.SetNextControlName(eventLogWindowName);
input = GUI.TextField( someRect, input );
if( Event.current.Equals( Event.KeyboardEvent( "None" ) ) && Time.frameCount > inputDisplayedOnFrame + 1 ){
ProcessInputField();
}
}
GUI.depth = 9;
}
void ProcessInputField(){
//do some stuff
displayInputField = false;
input = "";
inputDisplayedOnFrame = 0;
GUI.UnfocusWindow();
}
void DisplayInputField(){
// ------------ LOOK AT THE FOLLOWING LINE - depicts only difference in key pressed ----------------
if( ( Input.GetKeyDown( Chat ) || Input.GetKeyDown( KeyCode.Slash ) ) && !pGUI.displayInputField ){
pGUI.displayInputField = true;
pGUI.inputDisplayedOnFrame = Time.frameCount;
}
}
Comment
Your answer
Follow this Question
Related Questions
How to Focus GUI.TextArea in Unity for Android 0 Answers
How can I force a TextArea to get focus? 1 Answer
Input.GetKeyDown not working properly on a GUI textbox 0 Answers
How to keep focus on a GUI Slider 0 Answers
TextField not getting focus on iOS 1 Answer