A Request / Suggestion for Supporting Different Keyboard Layouts

I use the Dvorak layout. Attached to my desktop, I have a keyboard that internally outputs Dvorak, and macOS is set to Qwerty. On my laptop, macOS is set to Dvorak, since I'm using the internal keyboard.

This issue also applies to moving macros between other keyboard layouts, such as German, BÉPO, Italian, etc. So a German person's Cmd-Y becomes Cmd-Z to an American person, Cmd-W to a French person, and Cmd-; to a Dvorak user, Colemak, etc. Keystrokes generated by macros change in a similar fashion.

KM macro definitions are tied to the KeyCode of the physical keys on the keyboard, rather than the symbols they represent.

I propose that KM save it's macro definitions to its .plist file using definitions such as those in Carbon/Carbon.h, such as kVK_ANSI_Semicolon rather than 41, with the translation happening when loading and saving the .plist, and when the keyboard layout is changed in macOS.

E.g. rather than the current:

<key>KeyCode</key>
<integer>41</integer>

it might be:

<key>KeyCode</key>
<string>kVK_ANSI_Semicolon</string>

When the .plist file is read on my iMac Pro, any macro triggered by, or that generates kVK_ANSI_Semicolon becomes 41, and when read on my MacBook Pro, it becomes 6.

What would this do?

Well, it would allow me to define a macro triggered by Cmd-; and have it work on both my iMac Pro using a Dvorak layout with macOS set to Qwerty, as well as my MacBook Pro with macOS set to Dvorak layout. On both machines, the macro would be triggered by the ; key. It would also allow me to send a macro to a user with any other keyboard layout (that has a semicolon), and allow them to use it by pressing Cmd + their semicolon key, rather than mine (which as mentioned before would currently be Y for German, W for French, etc.).

I haven't written code for macOS, but the attached might be helpful.

ASCII to CGKeyCode

There have been several posts about this over the years, and I'm sure it would be helpful to others besides me.

When I complained to my government's official language Commissioner about the fact that government issued PKI certificate fields were in English only, the answer I got was (something like) "Just change your Windows GUI interface to French."

They didn't understand the issue at all! It was frustrating. I can see parallels between my situation and yours, here.

I wish you luck. I'm not sure how much work it will take to implement your change. Probably more than your post suggests.

@peternlewis?

The system Hot Key API is tied to keycodes.

kVK_ANSI_Semicolon is 41. It's a constant. It does not change with different keyboard layouts.

That is what the ANSI part means - it is the keycode for semicolon on an ANSI standard keyboard.

That code is “Much cleaner” (as the poster notes) in the way that code that has not actually bumped up against the real world tends to be.

The code for mapping between keycodes and keys in Keyboard Maestro is over 500 lines long, handling a myriad of cases and issues.

Remapping Key codes as Key layouts change and trying to keep the same meaning would be so fragile and fraught with problems that there is not much chance of me implementing it.

1 Like

:sunglasses:

Of course. That was intended to be a conceptual example of replacing the magic number with a symbol.

I'll see what I can do with Python and plistlib.