emscripten-ports / SDL2

Other
166 stars 64 forks source link

Virtual/screen keyboard support #80

Open Beuc opened 5 years ago

Beuc commented 5 years ago

Hi,

AFAICS there is no on-screen keyboard support in the Emscripten SDL2 port, which is a problem on mobile platforms.

There doesn't seem to be a browser API to control the virtual keyboard (or maybe I missed it?), so we could:

Beuc commented 5 years ago

(clarified a mistake about fullscreen)

Beuc commented 4 years ago

Several "javascript virtual keyboards" exist, notably https://github.com/hodgef/simple-keyboard which has no dependencies (though none of them describe why they were developed in the first place).

I'm not sure what stack should provide the virtual keyboard. I'm wondering what's the SDL team's stance on shipping additional javascript+css code in SDL2 to handle an IME?

Beuc commented 4 years ago

Alternatively, I made a test with an off-screen HTML text input, to leverage the browser's built-in support. This properly show/hides the virtual keyboard on focus/unfocus, and JS events allowed tracking what was typed. Keycodes are caught and forwarded to the application as well, for consistency with SDL2/Android.

https://www.beuc.net/tmp/ti1.html

Limitations:

With these limitations it sounds like this isn't the right approach, but I'd be happy to discuss this further. ti1.zip

Beuc commented 4 years ago

Also here's a sample SDL2 app for comparing the behavior between desktop/web/android: https://github.com/renpy/renpyweb/blob/master/tests/testtextinput.c

Beuc commented 4 years ago

Referencing emscripten-discuss thread for info: https://groups.google.com/forum/#!topic/emscripten-discuss/FN-8Tdxi1D8

Also given there was 0 reaction here after 1 year, it is unlikely that any solution will be implemented at the SDL2 layer :/

feliwir commented 3 years ago

@Beuc I'd find a solution for that problem useful aswell

Beuc commented 3 years ago

@feliwir In the end we had to re-implement a keyboard in-game: https://github.com/renpy/renpy/pull/2336 Browsers' behavior was too inconsistent, or maybe I just missed a better solution.

ghost commented 3 years ago

I too could use this functionality. The off-screen text field thing is the type of workaround that would be consistent with Emscripten's approach. Myself, I'll try superimposing a visible text field first. A special soft keyboard like you're apparently doing for Ren'Py would be a bit heavy and non-native, but for a VN it's probably not a problem.

ghost commented 3 years ago

HTML form superimposed over the canvas activates the soft keyboard but does not accept input (input being received by SDL with preventDefault). This means the form submit event is not recognized if you press the virtual enter key. Instead, there seems to be some weird keyboard issue where Enter isn't received at all or differs from the US QWERTY key code.

Any ideas?

EDIT: The Return scancode is the same on Android's soft keyboard (the "Go" button) as on a physical keyboard (the "Enter" key). Even though Emscripten input events are blocking, user code can detect Return and its ilk via soft keyboard, as long as other issues are resolved like lag.

uyjulian commented 3 years ago

Related: https://twitter.com/danlucraft/status/1225763866765905922

ghost commented 3 years ago

they create an invisible contenteditable div that they update to always contain the text of the line you are working on, and that has the focus and is where text input is sent.

Could work. I use a text field with 0 opacity, but don't tell Google because of "security" or whatever.