Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: HotKey translates the key code wrongly when using non-QWERTY layout #73

Open
DivineDominion opened this issue Apr 6, 2021 · 2 comments

Comments

@DivineDominion
Copy link
Contributor

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.

@DivineDominion DivineDominion changed the title Bug: HotKey translates the key code wrongly Bug: HotKey translates the key code wrongly when using non-QWERTY layout Apr 6, 2021
@DivineDominion
Copy link
Contributor Author

The HotKeyCenter explains this well with a QWERTY/DVORAK example:
image

I didn't change layouts during app runtime, though, so it apparently doesn't do what the comment says.

@DivineDominion
Copy link
Contributor Author

DivineDominion commented Apr 6, 2021

@Econa77 It does what the comment says when you remove the attempt to translate the key code to the current layout:

image

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 physical C key), it will not store the character correctly. Probably because Sause's Key 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 returns nil, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant