Updated: This configuration no longer works in macOS Sierra or greater due to changes in Karabiner. I’ve written some new instructions.

I’ve had my Caps Lock key remapped to an escape key for some time now. I’ve become quite used to it — to the point where using other people’s keyboards is inconvenient. Given that I’ve already ruined my muscle memory, I figured I’d take it a step further. The end result is that hitting my Caps Lock key once still gives me “Escape,” but holding it triggers a “Hyper” modifier key (simultaneous Control, Shift, Option and Command). I can map the Hyper key using any of an assortment of utilities to do all kinds of fun things.

This is a slightly simplified version of what Steve Losh presented earlier this year, specifically the remapping that takes place in the Hyper section of that post. The idea is the same, but this doesn’t modify the behavior of the Control key; my muscle memory just wasn’t ready to accept that.

The first thing you’ll need to do is disable the Caps Lock key in OS X. Head to System Preferences’ Keyboard pane and click the “Modifier Keys…” button. Set Caps Lock to “No Action.”

The system starts with PCKeyboardHack. I’ve used this on all of my machines, including Mountain Lion systems and have never had issues because of it. It installs a kernel extension, but I swear it’s nothing to be afraid of.

Once you install PCKeyboardHack, all you need to do is set your Caps Lock key to key code 80 (F19):

PCKeyboardHack setting

Next, I used KeyRemap4MacBook, another kext utility for more intensive remapping. If you’re new to KeyRemap4MacBook, you’ll have fun (and likely be overwhelmed) sifting through the default options. Explore, but be warned that enabling too many at once will guarantee that you forget which keys do what and lead to unexpected behavior. I know this from experience.

I’m adding my own custom commands to KeyRemap using the private.xml file. This file is easily located by opening KeyRemap4MacBook, going to the Misc. tab and clicking the button to “Open private.xml.”

private.xml

Below is the code that I’m using for the primary remapping. It sets up the F19 key that the Caps Lock key is now remapped to so that pressing it once triggers escape (especially handy in vim) and holding it down simulates holding Control, Command, Option and Shift all at once. Rarely is this combination used as a hotkey combo, so it becomes a key that can be mapped to system-wide functions that are easily accessible without conflicting with anything else.

private.xmlraw
"
<?xml version="1.0"?>
<root>
	<item>
		<name>F19 to F19</name>
		<appendix>(F19 to Hyper (ctrl+shift+cmd+opt) + F19 Only, send escape)</appendix>
		<identifier>private.f192f19_escape</identifier>
		<autogen>
			--KeyOverlaidModifier--
			KeyCode::F19,
			KeyCode::COMMAND_L,
			ModifierFlag::OPTION_L | ModifierFlag::SHIFT_L | ModifierFlag::CONTROL_L,
			KeyCode::ESCAPE
		</autogen>
	</item>
</root>

Save the file and go back to KeyRemap4MacBook’s settings. Under the “Change Key” tab, hit the “ReloadXML” button on the right and your new options will show up at the top of the list (the screenshot shows some of my extra mappings, if your private.xml file is brand new you’ll only see the “F19 to F19” option). Enable “F19 to F19” and you’re good to go with a brand new Hyper key.

KeyRemap4MacBook settings

To make use of the Hyper key, you’ll want to start mapping it using your favorite keyboard utility. I’m doing most of my mapping in BetterTouchTool, but a tool like Keyboard Maestro offers even more options for sequential actions and other conditions.

Here are some basic settings I’m using to launch apps with the Hyper key. Hyper-M opens Mail, Hyper-B opens Chrome (browser), Hyper-T opens my iTerm2 visor, etc.

BetterTouchTool settings

You can also modify your DefaultKeyBindings file to add editing commands triggered by the Hyper key when in Cocoa text fields, or special mappings in an app like iTerm2 to perform command-line text navigation. Sky’s pretty much the limit.