iPhone Keyboard

Hello folks!

This is my first post on the forums but I’ve been lurking for a few months now. Wow you guys are awesome!

I am using version 1.5 on a game and trying to work with the keyboard (entering a high score user name). I may be having a brain lapse but for the life of me I can’t figure it out!

I’m using a GUI.Textfield() call to enter the name and when you click into the field, it opens up the native keyboard. What I can’t figure out is how to tell when the user is finished entering the name (i.e. iPhoneKeyboard.done). It says that I need an instance of the iPhoneKeyboard in order to access this non-static variable but I can’t figure out how to create an instance of it. In the Awake() function I tried to set:

	var keyboard : iPhoneKeyboard = GameObject.FindObjectOfType(iPhoneKeyboard);

but it gives me a typing error. I also tried casting the result of the function call to iPhoneKeyboard but had no success.

Could some kind soul please give me some guidance?

Most appreciated!

find can only find what has been created already, it does not create things for you.

Checkout the documentation: file:///Applications/Unity%20iPhone/Unity%20iPhone.app/Contents/Documentation/Documentation/ScriptReference/iPhoneKeyboard.html

the 3 variables it offers give you all you need, as you don’t need nor really can instantiate the keyboard, there can only be 1 keyboard at a time so having different objects makes 0 sense

@dreamora: That’s all fine and well if you’re using iPhoneKeyboard.Open() to get an instance of the iPhone’s keyboard. The question is: how do we get access to .done on the instance of the iPhoneKeyboard that GUI.TextField() created when the user clicked on the text field?

Right now the only solution I’ve come up with is to have another “Done” button the user has to press after he’s pressed the iPhoneKeyboard’s “Done” button. Or create a button that opens my own instance of iPhoneKeyboard.

Please tell me I’m wrong : )

Cheers,
~Rob

This is what I did, maybe not elegant, but at least works

  • Extracted from a larger script:
private var keyboard : iPhoneKeyboard;
var tempString : String = "";
var playerName : String = "";

function OnGUI () {
	
	if (GUI.Button (Rect (0, 110, 480, 40), "Your Name:", myStyle)){
		// Open Keyboard
		keyboard = iPhoneKeyboard.Open(tempString, iPhoneKeyboardType.Default, false, false, false, false, "Enter Your Name Here");
			
	}	

	// Whilst keyboard is active, take keyboard input:
	if (keyboard){
		
    	        playerName = keyboard.text;

        }
}

But it would be good if someone would add to this little example a way to automatically move on once the input has been taken and the done button has been pressed…?

Use something like the following:

var keyboard : iPhoneKeyboard;

...

if(keyboard.done) {
     // handle whatever you need to 
     // now that the user has clicked on "Done"
}

That’s what we were already doing (see the second workaround in my post above). It still doesn’t solve the problem of getting a reference to the instance of iPhoneKeyboard that GUI.TextField creates when it is clicked on.

I use a while iPhoneKeyboard.Open thingo

I had the same problem… I specified to work only when keyboard is not null. This is the code (c sharp).
if (slot<5)
{
keyboard = iPhoneKeyboard.Open(“”);
}

// mover frase anterior al comienzo
}
}
if ((keyboard != null))
{
if (keyboard.done == true)
{
ResetOkButton();
//okbuttonsignal = true;

}
}