Unity TouchScreenKeyboard detect return key

Hi,

I’m using TouchScreenKeyboard.Open in my Unity - iOS app and I can open the keyboard in iPad using that and enter some text and submit it when the Done button is clicked.

Now the client wants to submit the text when the user clicks the Return key in the keyboard, instead of clicking the Done button. But I couldn’t find a way to catch the Return key click in Unity side.

I tried code like if (Input.GetKey(KeyCode.Return)) { but it never get called.

Can you please tell me how to catch the keyboard keys pressed events or at least return key pressed event in Unity or in iOS side when using the unity TouchScreenKeyboard.Open.

Thanks

First of all you should specify what keyboard you want to use.
If it is just a simple one-line input you can create your keyboard with TouchScreenKeyboard keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default);. This already has a done button integrated and no return key.
But if you really want the return button to be recognized you will need to set the keyboard to multiline input and catch the return button like this:

System.Collections.IEnumerator WaitForReturnKey ()
    {
        TouchScreenKeyboard keyboard = TouchScreenKeyboard.Open("",
            TouchScreenKeyboardType.Default, true, true);
        yield return new WaitUntil(() => keyboard.text.Contains(System.Environment.NewLine));
        string result = keyboard.text.Replace(System.Environment.NewLine, "");
        keyboard.active = false;
    }

I was only able to test it on android so I hope it works on iOs too.