I have a game where I want to capture keyboard input as it’s typed…it’s a typing game. Type a letter A and something happens. So no text input field.
On my PC I’m using this and it works great:
void Update ()
{
foreach (char letter in Input.inputString)
{
wordManager.TypeLetter(letter);
}
}
For iOS I’ve tried the following but doesn’t seem to work.
private void OnGUI()
{
Event e = Event.current;
if (e.keyCode == KeyCode.Return)
{
returnPressed = true;
}
if (e.keyCode == KeyCode.Space)
{
spacePressed = true;
}
// do a bunch of bools for each keyboard button pressed?!
}
Last I checked, I don’t think Apple will let you make your own graphic keyboard: they want you to use the in-built system one that Unity brings up for you when you edit an InputField.
There are ways to make that keyboard appear, I believe by using the MobileKeyboard API:
Unity provides some level of integration and I haven’t used it. It might be necessary for you to write some native iOS keyboard integration to get the exact behavior you want and still be compliant with Apple’s policies.
void DoStuffWhenSubmitted(string input)
{
// do stuff here
}
void DoStuffWhenValueChanged(string input)
{
if (input != “”)
{
input = input.ToLower();
char letter = input[0];
wordManager.TypeLetter(letter); // send letter to a manager to do stuff with
MyInputfield.text = “”;
}