hidutil
is a powerful tool that can remap keys on your MacOS. It can remap keys for internal keyboard as well
as for external keyboard. In the example below, I am remapping section sign key(§) to grave accent key(`),
because I want to have my recently bought K380 keyboard with UK layout to act almost like US layout.
Note: there are GUI tools like Karabiner, but it messed by FN keys on external keyboard, when I just wanted simple one key remap, so I found this might be useful if you want simple solution.
--set
- this one sets your mapping. What is important is HIDKeyboardModifierMappingSrc
and HIDKeyboardModifierMappingDst
.
As their name tells it is mapping from source to destination. You can use this table https://www.freebsddiary.org/APC/usb_hid_usages.php
to find the key you need.
Note: first you need to put page number(1st column in the table that is in the link) and then key itself (2nd column) with padded extra zeros.
Example - map A -> B. Both are on page 7
, A is 0x04
and B is 0x05
, so your mapping would be:
{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000004,"HIDKeyboardModifierMappingDst":0x700000005}]}
Note that it will only map A -> B, not B -> A. If you want B -> A, just add another entry in UserKeyMapping
array.
--matching
- property targets my specific device. I guess you don't need that if you want to map internal keyboard.
ProductID can be found in Apple icon -> System Report -> Bluetooth (or USB depending on how your device is connected) -> Your device
and ProductID will be there.
I followed instructions here: https://www.nanoant.com/mac/macos-function-key-remapping-with-hidutil, however for some reason it does not work on restarts, but it works when I log out of my user and Log in.
Just put the com.example.KeyRemapping.plist
below in your /Library/LaunchAgents
or ~/Library/LaunchAgents
folder with
changed keys. Here is what to change:
-
<string>
after<key>Label</key>
: it should be unique name for your agent. Convention is to name the file the same as Label(+ extension for filename of course). Another convention is to use reverse domain notation. -
in
<array>
after<key>ProgramArguments</key>
, you just put the command as you do it for remapping.
Well, that's it. If you find solution how to make it work on reboots, leave a comment and help other people.
Thanks :)