`glfwSetKeyCallback()` : inconsistent behavior on non QWERTY keyboard layouts
#20,334 opened on 2023年9月25日
説明
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.
.keyCode is not an hardware scancode, and it breaks compatibility and consistency between GLFW in C and Emscripten.