Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong keyboard scan codes in Emscripten #6235

Closed
KivApple opened this issue Sep 15, 2022 · 2 comments
Closed

Wrong keyboard scan codes in Emscripten #6235

KivApple opened this issue Sep 15, 2022 · 2 comments
Assignees
Milestone

Comments

@KivApple
Copy link

KivApple commented Sep 15, 2022

If you have non-QWERTY keyboard (e. g. French AZERTY) you will get wrong scan codes in SDL_KeyboardEvent while running your code compiled with Emscripten in browser. There are no such problem while running your application natively (tested on Windows and Mac OS X). Also this website https://www.toptal.com/developers/keycode shows correct scan codes, so it is not a browser bug or a JavaScript API limitation. SDL uses deprecated EmscriptenKeyboardEvent::keyCode which seems to be filled from JavaScript's event.keyCode which contains wrong value even in JavaScript (if check using the website above). SDL should use a modern attribute EmscriptenKeyboardEvent::code which filled with the correct values on non-QWERTY keyboards (at least it shows correct values on the website).

OS: Windows, Mac OS X
Browser: Google Chrome
Latest stable Emscripten version with builtin SDL2 library

@slouken slouken added this to the 2.26.0 milestone Sep 15, 2022
@icculus icculus self-assigned this Sep 27, 2022
@icculus
Copy link
Collaborator

icculus commented Sep 27, 2022

Threw this together real fast from testsprite2.c ...

https://icculus.org/~icculus/emscripten/testsprite-keyboard-logging/

Bring up the console and hit some keys, and it reports this for me pressing the 'q' key with my QWERTY keyboard set to US English:

INFO: SDL EVENT: SDL_KEYDOWN (timestamp=10898 windowid=1 state=pressed repeat=false scancode=20 keycode=113 mod=0)
INFO: SDL EVENT: SDL_TEXTINPUT (timestamp=10899 windowid=1 text='q')
INFO: SDL EVENT: SDL_KEYUP (timestamp=10980 windowid=1 state=released repeat=false scancode=20 keycode=113 mod=0)

...switched the keyboard layout to French AZERTY, and the same key does this...

INFO: SDL EVENT: SDL_KEYDOWN (timestamp=99416 windowid=1 state=pressed repeat=false scancode=4 keycode=97 mod=0)
INFO: SDL EVENT: SDL_TEXTINPUT (timestamp=99417 windowid=1 text='a')
INFO: SDL EVENT: SDL_KEYUP (timestamp=99508 windowid=1 state=released repeat=false scancode=4 keycode=97 mod=0)

So yeah, the keycode should change, but the scancode should not be changing. @KivApple is right, I'm going to try his suggestions.

@icculus
Copy link
Collaborator

icculus commented Sep 27, 2022

Gonna track this over in #2098, which has a patch already.

@icculus icculus closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants