November 2012

0

Using Caps Lock as a new modifier key in OS X

Posted on Tuesday, 27 November 2012

I've started using Slate for window management in OS X. It's lovely being able to drive specific operations with the keyboard, but what's not lovely is trying to find a spare keyboard shortcut that doesn't need lots of fingers and doesn't clash with another app.

Taking inspiration from this article and the article it took inspiration from, I've taken to mapping Caps Lock to Shift+Ctrl+Option+Command, which is such a crazy set of modifiers that no app would ever have a default keyboard shortcut based on it. That means I get a single key which acts like all four normal modifier keys combined, so I get a whole blank keyboard of shortcuts all to myself!

The specifics of how I did this:

  1. Open System Preferences, then Keyboard, then Modifier Keys
  2. For each keyboard listed, set Caps Lock to No Action
  3. Install KeyRemap4MacBook and PCKeyboardHack, then restart your Mac
  4. Open System Preferences, then PCKeyboardHack
  5. Tick Change Caps Lock and set the keycode it sends, to 80 (which is really F19. If you have a keyboard which has a real F19 key, you need to change this to a different key you don't have)
  6. Go back to the main System Preferences page (click Show All, or re-open System Preferences) and open KeyRemap4MacBook
  7. Choose the Misc & Uninstall tab and click Open private.xml. This will give you a Finder window with a private.xml visible
  8. Right click private.xml and choose Open With then TextEdit.app
  9. Paste the following between the <root> and </root> tags:
    <item>
        <name>Remap F19 to Hyper</name>
        <appendix>OS X doesn't have a Hyper. This maps F19 to Control + Shift + Option + Command.</appendix>

        <identifier>usercustom.f19_to_hyper</identifier>

        <autogen>
            --KeyToKey--
            KeyCode::F19,

            KeyCode::COMMAND_L,
            ModifierFlag::OPTION_L | ModifierFlag::SHIFT_L | ModifierFlag::CONTROL_L
        </autogen>
    </item>
  10. Save and Quit the private.xml window, close the Finder window
  11. Back in the KeyRemap4MacBook preferences, switch to the Change Key tab and click ReloadXML
  12. You should now see Remap F19 to Hyper at the top of the list. Tick it.
  13. At this point you should be done, but we can easily test to make sure...
  14. Switch to the Misc & Uninstall tab in the KeyRemap4MacBook preferences and Launch EventViewer
  15. Press your Caps Lock key and you should see a series of events appear, each of which adds/removes one of the Shift/Ctrl/Option/Command keys. The middle row should have Shift Ctrl Opt Cmd in the flags column. If you see that, you are done!
  16. Configure lots of shiny new Hyper shortcuts in Slate or whatever other app you like!