bion33 / Storm

Storm is an extension for military gameplay on the NationStates website. It makes frequently used actions more convenient by assigning hotkeys to them. Please open an issue if you'd like to see a feature added or if something doesn't work as it should.
GNU General Public License v3.0
1 stars 0 forks source link

e.keyCode is deprecated #5

Closed drehtisch closed 3 years ago

drehtisch commented 3 years ago

2021-01-18 17_26_35-Window

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode

You should avoid using this if possible; it's been deprecated for some time. Instead, you should use KeyboardEvent.code, if it's implemented. Unfortunately, some browsers still don't have it, so you'll have to be careful to make sure you use one which is supported on all target browsers.

bion33 commented 3 years ago

I see an issue with the alternative "KeyboardEvent.key": the numpad number key values are the same as the top-row number key values, so I couldn't distinguish them.

Moreover, on an AZERTY layout the top-row number key values aren't numbers at all, but subject to the keyboard layout itself, meaning that it wouldn't be so easy to provide a default keyboard layout that works for everyone.

This isn't even considering keyboards which don't follow the latin alphabet, which would be affected even worse... although those are probably not in use at all on NS.

bion33 commented 3 years ago

So most likely, we'll have to use KeyboardEvent.code. But then there's the issue that the code does not necessarily represent the button on a non-US keyboard layout...