- Home /
iPhoneKeyboard.Open cannot handle multiple entries. Is it a bug?
How can a player enter two entries, like a name and a password? The iPhoneKeyboard.Open of one replaces the other! What is the code below missing? Any ideas?
static var inputText : String = "text"; static var inputText2 : String = "text2"; private var keyboard : iPhoneKeyboard; private var keyboard2 : iPhoneKeyboard;
function OnGUI() { if (GUI.Button(Rect(10, 10, 200, 32), inputText)) keyboard = iPhoneKeyboard.Open(inputText);
if (keyboard) inputText = keyboard.text;
if (GUI.Button(Rect(10, 50, 200, 32), inputText2)) keyboard2 = iPhoneKeyboard.Open(inputText2);
if (keyboard2) inputText2 = keyboard2.text; }
Answer by Jaap Kreijkamp · Mar 09, 2010 at 03:43 AM
You can have only one keyboard active at the same time, so before opening a new keyboard check if the current one is done
. A way to do it nicely would be something like (code written on the fly and I'm no javascript programmer so could be some small syntax errors in it):
var text1 : string; var text2 : string; var isTyping : boolean;
function OnGUI() { if (GUI.Button(Rect(10, 10, 200, 32), text1) && !isTyping) { StartCoroutine(COInputText1()); } if (GUI.Button(Rect(10, 50, 200, 32), text2) && !isTyping) { StartCoroutine(COInputText2()); } }
function COInputText1() { isTyping = true; var keyboard : IphoneKeyboard; keyboard = IPhoneKeyboard.Open(text1); yield keyboard; text1 = keyboard.text; isTyping = false; }
function COInputText2() { isTyping = true; var keyboard : IphoneKeyboard; keyboard = IPhoneKeyboard.Open(text2); yield keyboard; text2 = keyboard.text; isTyping = false; }
Your answer
Follow this Question
Related Questions
Input Text Rotated incorrectly... is this a BUG? 1 Answer
Text Prompt Problem 1 Answer
How do you bring up the mobile keyboard without this area? 1 Answer
How do I remove the Top Bar from the iPhone Keyboard? 1 Answer
Remove "Preview text line" above keyboard input text on Android and iPhone 1 Answer