- Home /
TextField eats all keys as of 3.4.0
This code appears to no longer work:
unity3d.com - GUI.GetNameOfFocusedControl documentation (uses Return key to confirm a text field as alternative to a button)
It seems now that TextField eats all keys (even releasing of Shift and Ctrl, messing up their states).
Any ideas for workarounds? This is making my game unusable every time I show a TextField. Is there some new input method support or something that I can turn off to maybe avoid whatever added this bug?
Answer by Waz · Jul 28, 2011 at 04:46 AM
I found Input.eatKeyPressOnTextFieldFocus:
Input.eatKeyPressOnTextFieldFocus = false;
Since TextField doesn't even correctly restore state of CTRL, you basically have to do this if you use Shift or Ctrl state in your game.
How do you use it in a script??? In a Awake function, i wrote " Input.eat$$anonymous$$eyPressOnTextFieldFocus = false; ", but i get an error: BCE0019: 'eat$$anonymous$$eyPressOnTextFieldFocus' is not a member of 'UnityEngine.Input'.
Yes, just set it once in one object's Awake function. Are you using 3.4.0?
This works for Unity 4 but it also gives the following warning...
warning CS0618: UnityEngine.Input.eat$$anonymous$$eyPressOnTextFieldFocus' is obsolete: eat$$anonymous$$eyPressOnTextFieldFocus property is deprecated, and only provided to support legacy behavior.'
Should I be worried???
Answer by twburger · Mar 20, 2014 at 11:55 PM
More specific to the exact question:
I think you may need Event.Use
void Use(); Description Use this event.
Call this method when you've used an event. The event's type will be set to EventType.Used, causing other GUI elements to ignore it.
if (Event.current.isKey) {
switch (Event.current.keyCode) {
case KeyCode.Return:
case KeyCode.KeypadEnter:
val = editingValue;
applying = true;
Event.current.Use(); // Ignore event I used it
break;
}
}
Your answer