Bug: HotKey translates the key code wrongly when using non-QWERTY layout
DivineDominion opened this issue · 2 comments
I noticed this in the KeyHolder example app with a keyboard layout switch as explained in #70:
- Switch from QWERTY to NEO2 keyboard layout
- Press modifier keys and the physical "C" key on my keyboard
Expected: the hotkey is triggered when I press the same physical keys again.
Actual: the hotkey is triggered when I press the same modifiers, but with a different character key (i.e. the one that corresponds to the character that's printed on the physical keyboard)
This is all very confusing to explain :)
So the C
key on my keyboard corresponds to the character "C" with the QWERTY layout.
Changing the layout to NEO2, for example, the C
key corresponds to the character "Ä". To type the character "C", I have to hit the R
key on the keyboard.
The physical key combo ⌘⇧⌥⌃C
with the NEO2 layout stores the key code for "C". But to triggerer the HotKey
, I have to press different keys on the keybard than the one I used to record the hotkey, i.e. in this case ⌘⇧⌥⌃R
on the physical keyboard, because the R
key types the "C" character.
The translation of pressed keys into QWERTY key codes does work, but it's apparently not used to install the keyboard listener.
@Econa77 It does what the comment says when you remove the attempt to translate the key code to the current layout:
Using the QWERTY key code instead of the 'current' key code fixes the inconsistency, but it changes the behavior. Magnet is designed to react to the character, independent of the layout (at least when the app restarts), not to the physical key.
- When you start the app in QWERTY and bind
⌘⇧⌥⌃C
, then restart the app with NEO2 layout, you can invoke the HotKey with the correct physical key (there,R
corresponds to "C"). - When you start the app in NEO2 and bind
⌘⇧⌥⌃Ä
("Ä" is at the physicalC
key), it will not store the character correctly. Probably because Sause'sKey
enum doesn't recognize this key. The HotKey falls back to the QWERTYKeyCode which is for the letter "C", since the current layout's key mapping returnsnil
, but now you have to hit⌘⇧⌥⌃R
on the keyboard to enter the "C" character, which is not the same keys you pressed to record the shortcut.
In other words, shortcut recording only works properly for keys on a QWERTY keyboard with keyboard layouts that contain the QWERTY key caps characters, but not umlauts or greek alphabet characters etc.
I understand that it's nonsensical to record a shortcut for a key combo that doesn't exist on QWERTY, but if users don't use a non-QWERTY layout all day, the current behavior is inconsistent.