soffes / HotKey

Simple global shortcuts in macOS
MIT License
921 stars 82 forks source link

kVK_ANSI_ virtual keycodes don't match output in Dvorak or non-QWERTY international keyboard layouts #2

Open pkamb opened 7 years ago

pkamb commented 7 years ago

Cool and useful framework! This is just a heads up, not a request for an immediate fix or anything, about an issue I have some experience with having written some keyboard apps and being a Dvorak typist.

The kVK_ANSI_A virtual keycodes reference physical key locations on a standard QWERTY hardware keyboard. If the typist is using a different software keyboard layout, the key codes will no longer match the output letter specified in the name.

So tables like:

case .o: return UInt32(kVK_ANSI_O)
...
case UInt32(kVK_ANSI_O): self = .o

will only work for typists using a U.S. QWERTY keyboard.

Those constants with "ANSI" in the name are labeled according to the key position on an ANSI-standard US keyboard. For example, kVK_ANSI_A indicates the virtual keycode for the key with the letter 'A' in the US keyboard layout. Other keyboard layouts may have the 'A' key label on a different physical key; in this case, pressing 'A' will generate a different virtual keycode.

I wrote a bit about this on the Stack Overflow question here:

https://stackoverflow.com/questions/3202629/where-can-i-find-a-list-of-mac-virtual-key-codes/16125341#16125341

Some strategies for layout-agnostic conversion of keycodes to output are here:

https://stackoverflow.com/questions/1918841/how-to-convert-ascii-character-to-cgkeycode

rgbworld commented 6 years ago

I am developing a macOS desktop app that is localized in several languages. Is this issue going to affect all non-US users if I were to use HotKey?

soffes commented 6 years ago

@pkamb good call. I had no idea. I'll try to implement this when I have time.

@rgbworld I'd wager non-US keyboards would have trouble with this.

rampatra commented 4 years ago

Curious to know whether any work was done on this?

I used HotKey and a user using Swiss-French keyboard complained about shortcut keys not working. Upon some investigation(by changing my keyboard layout in System Preferences, etc.), I figured that this is the issue.

soffes commented 4 years ago

Realistically, I'm not going to have time to work on adding this feature any time soon :/

If you want to PR something, I'd be happy to take a look though!