- Home /
Input not registering while TextField is selected
Hi everybody, I've been having problems with the TextField function and I'm not really sure how to solve it. I'm creating a typer game prototype, where the player writes types actions in a textField. The idea is for players to type their action and then press 'Return' to submit the string to the system. The problem comes from the fact that, if the textField is selected, Input.GetKey() does not register the 'Return' key. It is not until the user clicks outside the text field that Input starts registering keys again. I could place a button next to the text field, but I want the game to be keyboard only. Does anyone have any suggestions so I can listen to other keys while the TextField is selected? Any info, or other solution you can think of would really help.
Answer by Bunny83 · Jun 02, 2012 at 06:43 PM
Strangely they removed Input-eatKeyPressOnTextFieldFocus from the Input documentation. However this has been asked several times:
http://answers.unity3d.com/questions/136063/cant-input-when-focus-a-text-field.html
http://answers.unity3d.com/questions/214041/closing-textfield-via-inputgetkeydown-not-working.html
Hey thanks a bunch. I look through the forums for similar questions but couldn't find them. Thanks for pointing me in the right direction.
Answer by BitFish · Jun 21, 2012 at 06:52 PM
This has worked well for me:
text = GUI.TextField(new Rect(0,0,100,400), text);
bool enterClicked = text.Contains("\r") || text.Contains("\n");
nameField = nameField.Trim('\r', '\n');
if(enterClicked) DoSomething();
Answer by unimechanic · Jul 03, 2013 at 04:12 PM
This example should help:
http://forum.unity3d.com/threads/188202-Simple-dynamic-list-editor