emscripten-core / emscripten-core/emscripten
`glfwSetKeyCallback()` : inconsistent behavior on non QWERTY keyboard layouts
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
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 the `Q` 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 to `glfwSetKeyCallback()` will receive **INCORRECT scancodes**.
This is because `library_glfw.js` makes use of the outdated `KeyboardEvent.keyCode` instead of [`KeyboardEvent.code`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/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
Contributor guide
Assessment
This issue has not been assessed yet.