I have heard tales for a while of the joy of having your caps lock key remapped to a more useful modifier key. For me the most useful modifier key that I know of is ESC, for vim. Alas, this seems to be very dificult to do in OS X. Here are some of the false starts I made when trying to do this.
in vim you remap keys with the following command
this is great and a very useful feature, unfortunately I can’t directly map the caps lock key with mmap.
at least in 10.4, OS X lets you remap the caps lock key to Control, Command, Alt, or Nothing. This is great for most people, but it doesn’t help me make it ESC. It also doesn’t help me map it to ESC for one app (Vim) and nothing for other apps.
You can find this option in
System Preferences > Keyboard & Mouse > Modifier Keys
.inputRC / xmodmap
These are files that BASH (maybe all shells) and X11 read on startup to map keys. I didn’t examine them too much. From what I hear it is possible to remap the Caps Lock key with xmodmap, but I don’t run X11 regularly
Ukelele / .keylayout files
Ukelele is a program for creating key layout files, it comes highly recommended, I wasn’t impressed. I found it easier to hand edit the xml key layout files that OS X uses. You can read about their schema here. I found out that the caps lock key should generated a key code of 55 or 57 depending on whether it’s being turned on or off. On OS X they don’t generate that key code for a keylayout file to manipulate.
Writing A C program to modify keycodes
I ran across this code example OS X Internals and this code. Now I was on to something. I had one program that modifies key codes, and another one that traps the caps lock key (or any other modifier key being pressed. I was able to hack the code to generate a key code of “74″ (unused in the keylayouts I am using) every time the caps lock key is pressed. I was enormously satisfied with this.