Re-Map Caps Lock key to Esc in OS X

DEPRECATED: This post may no longer be relevant or contain industry best-practices.

If you are a VIM user, you probably find yourself stretching your poor little pinkey to the upper-left corner of your keyboard all of the time. How annoying! You probably also find yourself never hitting the Caps Lock key, which is totally useless since one can hold the shift key for the same effect, and annoying as heck because it is right on the home row!

Luckily, there is help. Download the PC Keyboard Hack application, and install it. This is a pretty cool app that lets us change what signals the OS interprets from key presses. It adds an entry to your System Preferences for configuring it.

To get the Caps Lock sending the escape code, you'll want to set it to 53:

PC Keyboard Hack
PC Keyboard Hack

Now that that is done, pressing Caps Lock will now send the escape code. Go ahead, try it out! You'll notice that the light on the key no longer toggles either.

But, we can do a little better. If you were to tap each key on your keyboard very quickly, you would notice that each of them sends their code. Even pressing the normal escape key really quickly still sends the escape code. However, if you quickly tap the caps lock key, you'll notice that it doesn't send the escape code, you actually need to hold it down maybe 100ms for the keypress to be acknowledged.

To fix this, go back to System Preferences, and go to Keyboard, then click the Modifier Keys button. On the dialog that pops up, change the Caps Lock key to perform No Action and press OK. After doing this, your Caps Lock key will be as quick as the rest of them.

Keyboard Preferences Modifier Keys
Keyboard Preferences Modifier Keys

Thomas Hunter II Avatar

Thomas has contributed to dozens of enterprise Node.js services and has worked for a company dedicated to securing Node.js. He has spoken at several conferences on Node.js and JavaScript, is currently writing a book on Node.js services with O'Reilly, and is an organizer of NodeSchool SF.