These are my notes and tests about keyboard events in web browsers.
The current browser recommendations are to use KeyboardEvent.key
[1] to match the current keyboard layout, and KeyboardEvent.code
[2] to match the physical key location. Try using Dvorak or a non-US keyboard layout to see how the key
will change, but the code
will stay the same for the same physical key.
The Keyboard API[3]
I don’t think there’s an event to be notified when the keyboard layout changes.
For non-web, SDL has SDL_GetKeyName(SDL_GetKeyFromScancode(SDL_SCANCODE_W)); to get the name of the key given the physical code (so “W” on AZERTY would return “Z”). On web, the keysym is only correct on events, but not outside of events. I have a SDL test page — see the “with event” and “without event” printed, and press some keys to see the with event data.
Source: keyboard.js