March 17, 2005
There are two two sets of keys which one might want to re-map on an OS X machine: the alphanumeric and symbolic (comma, asterisk etc.) keys and the modifier keys (Command, Option, Control, Esc etc.). A third type of modification is to customise keyboard shortcuts (beyond what is possible using Apple’s Preferences system). This article discusses all three in turn.
Remapping the alphanumeric and symbolic keys is possible, and reasonably straightforward, and a method to do this is explained below. OS X allows certain modifier keys to be re-mapped (see System Preferences→Keyboard and Mouse→Keyboard→Modifier Keys). As of OS X 10.4.8, only Caps Lock, Control, Option, and Command can be re-mapped (to one another); however it is possible to re-map some of the other modifier keys, and a simple way to do this is explained below. There used to be a kernel extension (which tend to be rather risky things) called uControl, which I understand allowed arbitrary re-mapping, but this is no longer maintained. There is what seems to be an immature program called fKeys, which the uControl developers point to as a possible successor, but it does not appear to be very simple or stable.
Finally, it is also possible to change the keyboard shortcuts (outside what OS X’s System Preferences allows).
You can re-map (redefine) the keyboard for OS X. Apple provide instructions on how to do it here. However, the XML format is pretty complex (if you just want to make changes quickly), but there is an excellent piece of software called Ukelele, which can be downloaded for free. The software comes with an excellent manual (the most well-written of any freeware I’ve seen for quite some time!).
The following is based on the information at macosxhints, but presents the information in what I hope is a clearer manner, and uses a less complex method of making the required changes.
OS X modifier keys have numeric codes. A re-mapping is achieved by specifying a source code (i.e. the key you want to change the meaning of) and a destination code (i.e. what the key should do instead). The key names and their codes are given below:
Note that kernel panic is not a key! Apparently if you set this code as a destination, you will cause your Mac to crash.
To edit or create a new mapping, follow the instructions below:
There is a very useful article at the TextMate blog which a method of mapping OS X key combinations to events which OS X can handle (Cocoa events), should you want to (re)define your own keyboard shortcuts outside of what is allowed by System Preferences. A complete-looking list of default text-editing keyboard shortcuts for OS X may also be useful for reference.
I have produced a Keyboard layout for OS X which I have called “Lambda” (after the lambda calculus, which I know almost nothing about), because the layout is “optimised” for programming and writing in English. I use the quotes because the layout is based on the QWERTY layout (I guess I’d use something based on the Dvorak layout if I really wanted an optimal keyboard layout). The layout does the following (based upon the Apple iBook keyboard shipped in the UK and probably the US):
I have also produced an OK-ish (for a first attempt) icon for the input mode for the OS X menu bar. By placing the icon file in the same directory as the .keylayout XML file, the icon is used to represent the layout. You can download each file below: