How to get typed letter from native keyboard without input field?

Hi there,

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?!
}

Any ideas on how I can get this working?

Thanks

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.

Thanks @Kurt-Dekker

This is how I solved this one in the end:

public class NativeKeyboardInput : MonoBehaviour
{
public TMP_InputField MyInputfield;

void Start()
{
MyInputfield.onSubmit.AddListener(DoStuffWhenSubmitted);
MyInputfield.onValueChanged.AddListener(DoStuffWhenValueChanged);
MyInputfield.Select();
}

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 = “”;
}

}
private void Update()
{
if (!MyInputfield.isFocused)
{
print(“LOST FOCUS”);
MyInputfield.Select();
}
}
}

Please use the dedicated forums available rather than the 2D forum. The UI and TMP forum is here.

Also, so you know, when posting code please use code-tags.

Thanks.

Thanks and sorry