The Mac OS X 10.4 Keyboard & Mouse preference pane provides a way to remap certain keys. However, the interface doesn’t expose the full functionality — a common problem with Apple software.
Note that this guide assumes you’re using the bash shell.
What keys can be remapped without the use of any third–party software?
Name Value
None –1
Caps Lock 0
Shift (Left) 1
Control (Left) 2
Option (Left) 3
Command (Left) 4
Keypad 0 5
Help 6
Shift (Right) 9
Control (Right) 10
Option (Right) 11
Command (Right) 12
Kernel Panic 16 (this used as a destination actually causes a kernel panic on keypress — as I’ve found out the hard way.)
How do I remap those keys?
1) Remap one of the keys available in the Keyboard & Mouse preference pane in order to make the following steps easier.
2) Locate the hidden property list file used to store the settings:
FILE=~/Library/Preferences/ByHost/.GlobalPreferences.000d*
(I assume there’ll be only one such file; you’ll need to verify that.)
3) Duplicate the file and convert it to the XML property list format:
cp $FILE ~/keys-binary.plist
plutil -convert xml1 -o ~/keys-xml.plist ~/keys-binary.plist
Open the resulting XML file and locate the com.apple.keyboard.modifiermapping key. Its value is an array containing several entries, each in turn containing HIDKeyboardModifierMappingSrc and HIDKeyboardModifierMappingDst keys. The values of those keys are described in the table above.
4) Convert the file back to the binary property list format, and put it back in the correct location:
plutil -convert binary1 -o ~/keys-binary.plist ~/keys-xml.plist
cp ~/keys-binary.plist $FILE
5) Log out and back in to apply changes.
How do I remap the Caps Lock key to the Escape key?
Unfortunately, this’ll require the use of a third–party program. I used a free trial version of Keyboard Maestro, by Stairways Software.
First, remap the Caps Lock key to the Help key, following the instructions above. Then, in Keyboard Maestro:
- Create a new macro.
- Add a Simulate Keypress action, with an User Keystroke — the Escape key.
- Add a Hot Key trigger, set to the Help key.
- In the Preferences section, enable the Launch Engine at Login option.
- While you’re at it, you might also want to disable all other unnecessary features.