UWP, input fields and focus: How can I automatically type in an input field in a UWP app without any use of a mouse?

Hi,

I am creating a mouseless game which involves the player typing into an input field which is automatically put into focus as it appears via these 2 lines:

EventSystem.current.SetSelectedGameObject(this.gameObject, null);
GetComponent<InputField>().OnPointerClick(new PointerEventData(EventSystem.current));

I found this to work perfectly in Windows and Mac builds and in the editor, but when I tested UWP, something was not working right. When the input field is created, I couldn’t type into the input field like I could in Windows/Mac build despite it being in focus. I know it is in focus because the caret is activated (it wouldn’t be if input field is not in focus, I’ve tested). The interesting thing is if I click with my mouse anywhere on the window of the running app, or if I go to another window (say my web browser) and go back to the app via taskbar, alt+tab or just clicking into it, I am then able to type into the input field (in that instance and every other instance following without clicking anything, as long as I don’t close and reload the app).

I have tested both from Visual Studio and via an installed sideload app and both result with this same problem. With the game designed to be played without a mouse, having to click the window to type (even just once) defeats the the whole purpose of what I’m trying to do, so having this seemingly tiny problem be such a major roadblock has been super dismaying. It’s also worth noting that the game receives all my other inputs, e.g. navigating with arrows, escape to pause, etc. It is only when it has to do with an input field in a UWP app and only for the first time in a session.

Does anyone have any idea as to what’s happening? Any way to fix this or delve deeper into the problem? Does it have anything to do with focus of the UWP app window with the whole having to click the window first? I’m thinking it’s plausible, so I’ve been trying to find a way to force focus on the window without luck; any pointers here? I’m a bit of a greenhorn in programming and making UWP apps, so any help would be great help, thanks!

You might try checking the “force module active” on the standard input module component of your EventSystem object.