Open SuperUserNameMan opened 11 months ago
Sounds like this is a straightforward bug in our GLFW. Do you think there is any risk to simply switching from keyCode
to just `code? Would you be interesting in sending a PR to that effect? I imagine to could be hard to test such as change :(
Do you think there is any risk to simply switching from
keyCode
to justcode
?
Alas, keyCode
returns an integer, and code
returns a string.
https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_code_values
Would you be interesting in sending a PR to that effect?
Alas (again), I'm not good enough with the javascript universe, and i'm a total noob with emscripten. Plus, according to this page, there seems to be some browser and OS variations that I might not be competent to handle correctly.
I imagine to could be hard to test such as change :(
I think that changing the keyboard layout at OS level could help with testing. And if the OS has a virtual keyboard, it might help too.
glfwSetKeyCallback()
should always return QWERTY scancodes whatever is the active layout.glfwSetCharCallback()
(which seems to work correctly) should always return the char associated with the key depending on the active layout.
This is going to be complicated to explain, so please, be patient with me :
My keyboard is AZERTY layout.
My
A
key is located at the same location than theQ
key of a QWERTY keyboard. At the hardware level, they share the same scancode, because : same location = same scancode.Using keyboard scancodes is helpful when you make a video-game that maps "WASD" keys to directions, because the location of these "WASD" keys are always the same whatever is the layout of the user's keyboard. The game can work out of the box without remapping the keyboard.
Here is the issue :
When I use GLFW in C, the callback passed to
glfwSetKeyCallback()
will receive correct scancodes. When I use GLFW in Emscripten, the callback passed toglfwSetKeyCallback()
will receive INCORRECT scancodes.This is because
library_glfw.js
makes use of the outdatedKeyboardEvent.keyCode
instead ofKeyboardEvent.code
..keyCode
is not an hardware scancode, and it breaks compatibility and consistency between GLFW in C and Emscripten.https://github.com/emscripten-core/emscripten/blob/9bdb310b89472a0f4d64f36e4a79273d8dc7fa98/src/library_glfw.js#L410-L433
https://github.com/emscripten-core/emscripten/blob/9bdb310b89472a0f4d64f36e4a79273d8dc7fa98/src/library_glfw.js#L379-L382
https://github.com/emscripten-core/emscripten/blob/9bdb310b89472a0f4d64f36e4a79273d8dc7fa98/src/library_glfw.js#L149-L161