gravitle icon indicating copy to clipboard operation
gravitle copied to clipboard

Use code instead of key

Open stefnotch opened this issue 4 months ago • 0 comments

Pet peeve of mine: Could you fix the keyboard input to work with all keyboard layouts?

So, the idea behind WASD is that they're arranged like

  W
A S D

The names of the keys don't actually matter, what matters is their physical location. This also means that on a French AZERTY keyboard, it's actually ZQSD.

Now detecting and handling every keyboard layout would be silly. Which is why KeyboardEvent.code exists. That gives you keys according to their physical location, or alternatively, it gives you keys as they would be arranged on a typical US keyboard layout.

document.addEventListener('keydown', (event) => { keystate[event.key] = true; }, false);
document.addEventListener('keyup', (event) => { keystate[event.key] = false; }, false);

That'd be relevant in places like https://github.com/loicbourgois/gravitle/blob/41191f7f25d8c5e6894f71c267ed8b4ae41acbcf/front/pages/garage/main.js#L392

stefnotch avatar Feb 09 '24 20:02 stefnotch