Jun 08, 2019 If you need to remap keyboard keys on Windows 10, AutoHotKey is a simple way to do it. For macOS, there’s no equivalent of AutoHotKey if you’re looking for script-based solution. That said, if you need to remap keyboard keys on macOS, you can do it with a free, open source app called Karabiner-Elements. If all you want to do is remap a single key Example: How to Remap Escape Key on Mac. Go to the Apple menu and choose “System Preferences” and then go to the “Keyboard” preference panel and choose the “Keyboard” tab. Click on the “Modifier Keys” button in the lower right corner. Karabiner is a Mac-based tool that allows to remap the keys for almost all kinds of input devices. This basically means that whenever a key is pressed on an input device, Karabiner intercepts the signal sent by the device, checks if it has a remapping rule for this key, and if yes, changes the signal, and passes it on to the application which. If you need to remap keyboard keys on Windows 10, AutoHotKey is a simple way to do it. For macOS, there’s no equivalent of AutoHotKey if you’re looking for script-based solution. That said, if you need to remap keyboard keys on macOS, you can do it with a free, open source app called Karabiner-Elements.
How to remap one Mac OS X keyboard key to the other without using any external tools?Is it even possible to do without being a mac developer?It turns out to be pretty simple in the new macOS X 10.12 Sierra using a little util named hidutil
.
Problem
You don't like your Mac keyboard layout, or worse you have to work with a different layout at work than you have at home.In either case you can install some external tool which will do the remapping for you but maybe you don't like to have additional application just for remapping a single key?My problem was connected with having British keyboard at home and American at work.While it is IMO not a problem to get used to any of those switching between them on a daily basis is annoying.There was one key in particular which makes things a bit hard from a developer perspective.It was a tilde key`.Tilde key is placed next to the 1/! on the American keyboard and replaced by a section sign§ key on the British one.
Solution
As it turns out for macOS X 10.12 Sierra you don't have to do anything more than running a short piece of code to do the required remapping.
Here is an simple example for the problem which I was facing which was remapping §/£ to `/~ key.
Remap Key For Mac Windows 10
As you can see you have to place appropriate values (usage ID) for HIDKeyboardModifierMappingSrc
and HIDKeyboardModifierMappingDst
which you will have to find in a table in the official docs.What is more for each 'Usage ID (hex)' you will have to calculate bitwise 'OR' with 0x700000000
which is very easy in most cases, but if you are facing any difficulties with that you can also use the following Bash command:
Where 0x64
should be replaced with a value from 'Usage ID (hex)' column.
In order to check current/effective mappings you can run:
And last but not least. In order to reset everything you have setup so far just execute:
NOTE
All changes made with hidutil
are immediate, so you don't have to restart anything.
Automatically set custom key mapping after each reboot
Create plist file e.g. /Library/LaunchDaemons/org.custom.keyboard-remap.plist:
Then load it with sudo launchctl load -w /Library/LaunchDaemons/org.custom.keyboard-remap.plist
so it will be loaded on each system reboot.
If you want to check if your plist file was loaded successfully you can use sudo launchctl list | grep org.custom.keyboard-remap.plist
.
NOTEIn order to unload plist file from system autostart usesudo launchctl unload /Library/LaunchDaemons/org.custom.keyboard-remap.plist
Issues
I have only one issue with this problem which was finding an appropriate 'Usage ID (hex)' for the section sign § key.As it turns out it was named in the Apple docs as Keyboard Non-US and |.In order to find that out I've used trial and error approach, so nothing fancy.If you will come across any better way of finding 'Usage ID (hex)' codes please share.
In case of are receiving Invalid property list
error message after loading plist file you are most probably trying to usethe old syntax for plist file with <key>Program</key>
instead of mentioned <key>ProgramArguments</key>
.
Sources
Key Remap For Macbook
- https://developer.apple.com/library/archive/technotes/tn2450/_index.html - Apple Technical Note regarding key remapping in macOS X Sierra
- https://apple.stackexchange.com/questions/283252/how-do-i-remap-a-key-in-macos-sierra-e-g-right-alt-to-right-control - Stack Overflow topic about that
- https://en.wikipedia.org/wiki/British_and_American_keyboards - possible keyboard layouts
- https://apple.stackexchange.com/questions/329085/tilde-and-plus-minus-%C2%B1-in-wrong-place-on-keyboard - exact same topic found after writing that post