Map escape to caps lock on a Mac (and other tricks)

A few months ago, Steve Losh posted on his keyboard setup. His setup is very intimidating impressive, but unfortunately his post was mostly of the ‘what I do’ variety, with Steve commenting that:

I’m not going to give you a tutorial here — read the documentation if you want to learn how to use the things I’m going to show.

This post reflects my efforts to fill in those gaps… I use it for vim, but you could use this setup for any number of things. Screen Shot 2013-01-03 at 1.39.31 PM The first step is to open Apple/System Preferences – see above. Screen Shot 2013-01-03 at 12.00.21 PM Next, select the ‘Keyboard’ options. Screen Shot 2013-01-03 at 12.08.10 PM Now we want to open the ‘Modifier Keys’ tab — the modifier keys are command, option (alt), control and caps lock (because they modify what other keys do). Screen Shot 2013-01-03 at 12.00.58 PM Set the caps lock key to control (I know, you want it to map to escape, but trust me, this is even better). Now, install KeyRemap4MacBook. It is important you pay attention to step two in the installation instructions:

Control-click or right click the pkg file, then select “Open” from the top of contextual menu that appears. Important You must open the pkg file from contextual menu in order to pass through Gatekeeper

Once you are installed and have reset, you are ready for some mapping magic: you can map escape to caps lock, and much more! Screen Shot 2013-01-03 at 12.37.58 PM Go back to system preferences (under the apple logo top left), and now you’ll notice a new logo in the bottom left, under the ‘Other’ heading — click on that to open our (new) keyboard remapping tool.  If you do not see the new logo (i don’t on my desktop), you can still pull up both programmes via command+space (spotlight).

This next step is Steve’s great insight — we really only need to tap the escape key. So what we are going to do is to map it such that a short tap on the caps lock key sends the escape signal, and a longer hold down sends control. When we have done this, we will have two of the most useful keys on the keyboard in pretty much the best spot. Screen Shot 2013-01-03 at 12.39.52 PM To do this, we must change Control_L (Left Control) – so expand that tab. Screen Shot 2013-01-03 at 12.41.11 PM Scroll down, and find the option that is (confusingly) titled ‘Control_L to Control_L (+ When you type Control_L only, send Escape)’ — select that. Now the biggest problem with this is that one man’s tap is another man’s hold. The computer decides which based on how long you hold it down. To modify this behaviour, we must open the Key Repeat tab (see the above picture — it’s highlighted at the top). Screen Shot 2013-01-03 at 12.42.32 PM Once in the key repeat tab, tweak the ‘[Key Overlaid Modifier] Timeout’ option. I lowered mine to 300ms, and haven’t had any problems with getting an Escape when I expected a Control. I wanted my caps lock key back, so I mapped escape to caps lock. Back into System preferences / KeyRemap4MacBook, and this time select the ‘Change Escape Key Option’. Screen Shot 2013-01-03 at 12.56.24 PM The first option is to map the Escape key to CapsLock. Check that option and you’re in business. Screen Shot 2013-01-03 at 12.57.10 PM Ludicrous Key: This last part is a how-to for an advanced trick that Steve employs. With the caps lock key now sending a Control message when held down for more than 300ms, the existing left control key is redundant. So … Steve maps it so Command-Option-Control-Shift — a combination that he calls ‘Hyper’. Why bother? If you use Safari, you’ll find that using it in combination with the left and right arrow keys will change tabs, which I think it pretty useful. Another good reason to do it is that it gives you some exposure to creating custom mappings. First of all, you’ll need to download PCKeyboardHack. It’s from the same folks as KeyRemap4MacBook, and once again you must control-open it and restart after the install. Screen Shot 2013-01-03 at 1.09.25 PM With that done, you can open the programme. Screen Shot 2013-01-03 at 1.10.34 PM You may have to scroll in the menu below, to find the key code for — note the code is 80. We are going to remap the left control key to send key code 80 (so that your system thinks it’s getting the F19 code). Next, expand the ‘other keys’ tab: Screen Shot 2013-01-03 at 1.11.31 PM Select ‘Change Control_L’, and enter 80 into the keycode box. Now your system will get an F19 message — if you have a normal keyboard setup, it won’t do anything. So … back to KeyRemap4MacBook to intercept that F19 message, and substitute our ludicrous mapping. Screen Shot 2013-01-03 at 1.19.20 PM This time we go to the ‘Misc and Uninstall’ tab, and hit the ‘open private.xml’ button. There is a guide to editing these things, but you should get the idea from how we make the ‘ludicrous’ key.

<?xml version="1.0"?>
<root>
  <item>
    <name>Remap Left Control to Hyper</name>
    <appendix>Maps left control to control+shift+option+command</appendix>
    <identifier>space_cadet.left_control_to_hyper</identifier>
    <autogen>
            --KeyToKey--
            KeyCode::F19,

            KeyCode::COMMAND_L,
            ModifierFlag::OPTION_L | ModifierFlag::SHIFT_L | ModifierFlag::CONTROL_L
    </autogen>
  </item>
</root>

So open your private.xml, and add the above (just copy and paste). Screen Shot 2013-01-03 at 1.26.57 PM Now you have that added, go back to the ‘Change Key’ tab, hit the ‘ReloadXML’ button, and you should have a new mapping option. Select that, and you’ll have your new key. An immediate benefit of this is that you can change tabs easily in Safari, and as Steve notes, it gives you pretty much an entire ‘namespace’ to map your own shortcut keys to (a task for which he employs Keyboard Maestro).

About these ads
This entry was posted in tech, vim and tagged . Bookmark the permalink.

2 Responses to Map escape to caps lock on a Mac (and other tricks)

  1. Dr Page says:

    You’re a good man!

  2. abattre says:

    Note: For Mavericks, it is now installed into your Applications directory as an application, not in System Preferences.

    Thanks for this tut!!!

please comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s