- Home /
Access to iPhone "Done" button with Unity 4.6 InputField?
"TouchScreenKeyboard.done" works if you open a keyboard independently of an Input Field, but what about the keyboard that comes up for an InputField? Is it possible to tell when that "Done" button has been used?
There doesn't seem to be a property of InputField to address its keyboard (other than KeyboardType); nor does On Submit (Event Trigger) seem to do anything with that button. I'm guessing there must be some way to address the keyboard, and then I'll be all set!
("Cancel" does reset the field text, so that's useful at least. But I wouldn't mind customizing that function as well.)
If that keyboard is NOT accessible from code, I'm considering a workaround: track whether the InputField loses focus, and assume "Done" has been tapped if so. Which is actually not always true: it loses focus from tapping anything in my UI. But I can set a variable to true when tapping every OTHER button--so if it's false, then by process of eli$$anonymous$$ation, the focus loss must have come from "Done" or "Cancel." (Luckily, for my purposes, I don't think I need to tell those two apart.) Just a thought... kind of hacky though.
Is it impossible to know the user has tapped Done (or Cancel)?
The following does not work (the condition never happens because it refers to a non-existent keyboard, not the InputField's keyboard):
private var keyboard : TouchScreen$$anonymous$$eyboard;
function Update () {
if (keyboard && keyboard.done) {
editorAccept(); //(The function I want to call)
}
}
(Another thing that doesn't work is On End Edit: that triggers whenever the user taps anything in the UI--not just for Done and Cancel.)
FWIW, I'm allowing the white editing box at the top of the keyboard; and newlines are allowed, so Return is not the same as Done.
Thanks for any ideas or leads! It makes the app feel broken when Done doesn't do anything.
(If it can be done in Unity 5, that's fine too—I've bought it and will start using it when it's been out longer.)
If InputField's own Done and Cancel are not exposed to scripting at all, is there a way to take an indepedently-opened keyboard and attach it to the InputField so it behaves the same as the InputField's own?
I've tried just opening a keyboard with TouchScreen$$anonymous$$eyboard.Open, but its connection to the field is unreliable at best. (No doubt affected by other things I'm doing with the field and UI.) Sometimes text in the field appears above the keyboard, sometimes not; and sometimes typed text gets put in the field, sometimes not.
But if I could make my TouchScreen$$anonymous$$eyboard.Open keyboard attach to the InputField fully, the way the field's own keyboard was, maybe that's a useful approach?
Unfortunately I can't find any documentation of how InputField works on mobile.