emscripten-core / emscripten-core/emscripten

Improve support in SDL2 for keyboard input on mobile browsers

Open
#21,960 8 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Mobile browsers (with virtual keyboards) don't support `keypress` events, and for `keydown` events [set the code to 229](https://developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event) for most keys. But, there is pretty good support through the `input` event - at least it supports all actual textual input keys plus the backspace key (one of the few keys actually returned in `keydown` events). It would be good if Emscripten (and then SDL) supported the `input` event with little/no manual work by the user.

(I just discovered something new: the `input` event doesn't seem to fire if Chrome dev tools have breakpoints in the event handler. Makes it very hard to test and debug these events! This did not used to be the case.)

What this might involve:

1. Creating an input element, as the `input` event won't fire on document or window. This should be a `` not an `<input>` because of [this other unfixed Chrome bug](https://stackoverflow.com/questions/72988591/prevent-android-keyboard-in-chrome-from-showing-password-management-on-html-inpu).
2. The `input` event needs to be handled differently, as it has different properties, or you can access what was typed via the textarea's `.value`. When I've used it (not in an Emscripten project) I also had to empty it each time. And if the character was space, blur then refocus, as otherwise it thinks there are still spaces and backspace doesn't work.
3. Adding something like `emscripten_set_keydown_callback_on_thread` and then using it in SDL. I don't know if it could be directly used or if it would need to be mapped into something more like a `keydown` event.
4. Maybe also ignore `keydown` events which have a code of 229 and don't send them to the wasm? That's what I've previously done, but it may not be necessary.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.