Mac Missing key code for scripting key remapping on AZERTY keyboard

Yoms

macrumors regular
Original poster
Jun 1, 2016
102
46
Hi,

I've read the Technical Note TN2450
https://developer.apple.com/library/archive/technotes/tn2450/_index.html

I have a French AZERTY keyboard. My goal is to swap € (which is obtained by pressing "Option + $") with ` and £ key in order to make € directly accessible. I'd like to this using hidutil shell script (not an external app, hence programming section). But I can't seem to find the key codes for €, `and £ anywhere.

I tried --help on hidutil property, but not much came out.

Anyone knows how to get those codes? Or how to use the --get function with the rigth HID property to get the code from the character?

Thanks!
 

organicCPU

macrumors 6502a
Aug 8, 2016
666
182
I'm interested in the topic, but way far from knowing something about it...
I guess it's much easier to use a third-party tool, nonetheless, here are my findings...

The Apple Technical Note in your link offers Table 1 -> List of keyboard usages and their usage IDs
Right on top of the table is a broken link for a document that could refer to this one with even more information:
https://www.usb.org/document-library/hid-usage-tables-112

Refer to Table 1 on Apple Technote or Section 10 Keyboard/Keypad Page (starting at page 53 of the PDF).
Those codes (IDs) should be of interest, but your keyboard might even be more different.
Code:
USAGE ID  USAGE ID    Usage Name
(DEC)     (HEX)
180        B4          Currency Unit            <-- this one should be the $ key
33         21          Keyboard 4 and $         <-- or is it this one (?)
50         32          Keyboard Non-US # and ~  <-- this one should be the £` key
According to the Technote, something like this should then remap the Currency Unit key with the £` key for you (!Attention! this is not tested):
Code:
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x7000000B4,"HIDKeyboardModifierMappingDst":0x700000032},{"HIDKeyboardModifierMappingSrc":0x700000032,"HIDKeyboardModifierMappingDst":0x7000000B4}]}'
And this should check it:
Code:
hidutil property --get "UserKeyMapping"
After restart you'd need to set up the modification again or put it in a startup script.

The longer I'm thinking about it, the more I'm getting the feeling that it is a little more complicated. Maybe, you'll need to tinker around a bit, because everything is referring to keys and not to characters. Therefore there are chances that the key 4 could make some trouble after modification (especially if you decide for HEX 21, in case that B4 doesn't work like expected). It may be necessary to find out more about invoking a key combination in your mod, e.g. with left shift (HEX: E1) and/or right shift (HEX: E5) in the command. Maybe other MR members can tell us more...

Those commands gave me some more informative help on hidutil
Code:
man hidutil
hidutil dump --help
hidutil list --help
hidutil property --help
Hope this helps a bit! Would be great, if you'd report back, if you had success with remapping.
 

Yoms

macrumors regular
Original poster
Jun 1, 2016
102
46
I'm interested in the topic, but way far from knowing something about it...
I guess it's much easier to use a third-party tool, nonetheless, here are my findings...

The Apple Technical Note in your link offers Table 1 -> List of keyboard usages and their usage IDs
Right on top of the table is a broken link for a document that could refer to this one with even more information:
https://www.usb.org/document-library/hid-usage-tables-112

Refer to Table 1 on Apple Technote or Section 10 Keyboard/Keypad Page (starting at page 53 of the PDF).
Those codes (IDs) should be of interest, but your keyboard might even be more different.
Code:
USAGE ID  USAGE ID    Usage Name
(DEC)     (HEX)
180        B4          Currency Unit            <-- this one should be the $ key
33         21          Keyboard 4 and $         <-- or is it this one (?)
50         32          Keyboard Non-US # and ~  <-- this one should be the £` key
According to the Technote, something like this should then remap the Currency Unit key with the £` key for you (!Attention! this is not tested):
Code:
hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x7000000B4,"HIDKeyboardModifierMappingDst":0x700000032},{"HIDKeyboardModifierMappingSrc":0x700000032,"HIDKeyboardModifierMappingDst":0x7000000B4}]}'
And this should check it:
Code:
hidutil property --get "UserKeyMapping"
After restart you'd need to set up the modification again or put it in a startup script.

The longer I'm thinking about it, the more I'm getting the feeling that it is a little more complicated. Maybe, you'll need to tinker around a bit, because everything is referring to keys and not to characters. Therefore there are chances that the key 4 could make some trouble after modification (especially if you decide for HEX 21, in case that B4 doesn't work like expected). It may be necessary to find out more about invoking a key combination in your mod, e.g. with left shift (HEX: E1) and/or right shift (HEX: E5) in the command. Maybe other MR members can tell us more...

Those commands gave me some more informative help on hidutil
Code:
man hidutil
hidutil dump --help
hidutil list --help
hidutil property --help
Hope this helps a bit! Would be great, if you'd report back, if you had success with remapping.

Hi,

Thanks a lot for the thorough reply. I recently bought a new Mac with touchbar so decided to go for BetterTouchTool to make something useful out of that thing, i.e. in Terminal or dev apps the tb will display also these characters that are not easily accessible on an AZERTY keyboard.

Cheers and thanks again!
 
  • Like
Reactions: organicCPU
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.