keyboard-map
keyboard-map copied to clipboard
The map should always identify digit keys as 0-9, even if the layout requires Shift to type the digit
KeyboardEvent.get()
returns the key which would be typed if the current physical key were pressed with no modifiers.
On some layouts, numeric keys (0-9) type national or punctuation characters instead, and the digits must be accessed by holding Shift. For example, on AZERTY, [Digit3] types " (double quote). To type 3, you have to press Shift+[Digit3], or have CapsLock on.
I propose the following exception:
On layouts on which numeric keys (0-9) require Shift to type digits (examples: AZERTY, Czech QWERTZ, Lithuanian),
.get()
should always return the digit.
On such locales, shortcuts which use [Digit0] - [Digit9] are generally referred to using the digit, even if the digit is not the "base" (unmodified) key. I'm sure French or Czech users would find it strange to see shortcuts referred to as Ctrl+(
(AZERTY 5), '
(AZERTY 4) or Alt++
(Czech 1).
Here are examples of Microsoft's Windows shortcut cheatsheets for French and Czech. Notice it says "Touche de logo Windows + numéro" and "Ctrl+1" (WordPad section).
https://support.microsoft.com/fr-fr/help/12445/windows-keyboard-shortcuts https://support.microsoft.com/cs-cz/help/12445/windows-keyboard-shortcuts
PS. In my Web app, I have some commands bound to Alt+1, Alt+2, etc. and it would be easier if KeyboardMap.get()
returned the digit in such cases, rather than the unmodified key. Right now the workaround is to compare KeyboardMap.get("Digit1") with "1" to detect such layouts and fall back to using KeyboardEvent.code
. Can't just use .code
all the time, because there are actually layouts where the digits on keycaps don't match KeyboardEvent.code
.