Advice for keyboard input in mobile WebGL games wanted

1,592 views
Skip to first unread message

Floh

unread,
Jan 10, 2018, 7:37:54 AM1/10/18
to emscripten-discuss
Hi, not strictly an emscripten question, but maybe someone has already solved this:

I'm looking for advice on how to best implement keyboard input in a mobile HTML5 game with the WebGL canvas stretched to 100% client size.

Ideally I want this behaviour:

- user taps on a non-HTML input field implemented with a custom WebGL UI 
- the mobile keyboard comes up, user starts typing, and each key press is communicated to the game and rendered through the custom UI
- on a specific key or when tapping outside the keyboard, the onscreen keyboard disappears

So ideally no HTML input element would be involved.

Questions:

- is it possible to control the mobile onscreen keyboard (show, hide and get key events) without an HTML input element?
- if not, is it possible to have a hidden input element instead which serves as a proxy to bring up the keyboard?

I'd also be thankful for any pointers to sample code, or good articles on the topic (it seems to be quite difficult to google for this, or I don't know the right magic incantations)

Thanks a lot,
-Floh.

Александр Гурьянов

unread,
Jan 10, 2018, 7:58:22 AM1/10/18
to emscripte...@googlegroups.com
Hi. I have experience with android development, and can answer from
android side.

- is it possible to control the mobile onscreen keyboard (show, hide
and get key events) without an HTML input element?
Unfortunately no. It can be made only in custom webview, if you create
android app with webview and provide javascript api for showing/hiding
keyboard.

- if not, is it possible to have a hidden input element instead which
serves as a proxy to bring up the keyboard?
Theoretically yes, but I don't believe in this solution. It's because
Android OS does not provide full control over virtual keyboard, you
can only send intention to open/hide keyboard but os decide should
keyboard stay on screen or not.

I have a game on android, that uses webview with js api to
showing/hiding keyboard. This works in most cases, but on some "buggy"
phones keyboard can dissapear in wrong time and game start be
unplayble. So as for me best solution is drop system keyboard, and use
pure js onscreen keyboard as part of game. Like this
https://mottie.github.io/Keyboard/, or any other. Another advantage
that this solutin will work on android and ios.
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to emscripten-disc...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages