- Home /
Android Textfield locks out input until esc
I'm using GUI.Textfield, or GUILayout.Textfield, on Android build Unity 3.5
On Android:
Go to enter something in the textfield by tapping on it.
You MUST be in Portrait viewing, screen is longer top to bottom than left to right
It will bring up the virtual keyboard. No problems.
Instead of entering something, tap on the top part of the screen where the preview of the previous screen is. You'll go back to the previous screen.
Now if you try to tap on any textfield, no virtual keyboard will pop up.
This persists until you hit the back button which simulates the ESC key.
There seems to be no way in unity to fire input events through script. Otherwise I would just simulate a escape hit myself.
2nd Minor Issue: In the same vein, I'd like to make a button, which when pressed would act as if the user tapped on a textfield (on another part of the screen.) As a reminder before the user can go forward.
EDIT: 2nd Issue can be solved with TouchKeyboard.open as suggested below.
Again this would be solved if you could simulate touches or input.
Any help is appreciated.
Answer by Seth-Bergman · Jul 29, 2012 at 06:29 AM
try : TouchScreenKeyboard.Open;
http://docs.unity3d.com/Documentation/ScriptReference/TouchScreenKeyboard.Open.html
http://docs.unity3d.com/Documentation/ScriptReference/TouchScreenKeyboard.html
2nd Part of the problem solved (popup keyboard when pressing button) but the original issue isn't.
None of TouchScreen$$anonymous$$eyboard variables change when you click on the preview screen, the keyboard disappears, and all the TouchScreen$$anonymous$$eyboard variables stay the same (active, done, hideinput, visible, area, done) It's still listed as visible, save the keyboard isn't there.
I have no way of knowing if the keyboard is supposed to be there or not. I even tried "If active, setting it to active continuously". As expected didn't work either.
Answer by Sirellyn · Jul 29, 2012 at 10:38 PM
Here's the workaround I found. It's not great, but it least it handles the issue:
At the bottom of you OnGui() function just insert the following:
if (TouchScreenKeyboard.visible) {
if (GUI.Button(new Rect(0,0,Screen.width,Screen.height), "", skin.GetStyle("/*Insert style thats completely transparent here*/"))) {
keyboard.active = false;
}
}
Remember to declare TouchScreenKeyboard keyboard = new TouchScreenKeyboard(); at the top of your class.
So you just create a huge invisible button that overtakes the screen. When you tap on it, it will clear the keyboard. (if it's active). Most users will tap again if an input didn't work without thinking twice about it.
Again not elegant, but it works.