Thursday, April 12, 2007

Remap Macbook Pro Enter key to Exposé

Apple's laptop keyboards have an "Enter" key to the right of the space bar and command key (it's different from the "Return" key which is in the usual place). I have no idea what it's supposed to be useful for, but since it's so easy to reach from the touchpad, I like to assign it to the Exposé function. You can reassign the Exposé hotkeys in System Preferences, but it limits you to the F-keys. This tip explains how to assign Exposé to other keys, but it doesn't work for the Enter key on a Macbook Pro because the keycode has apparently changed. I used Full Key Codes to determine that the correct keycode for the Enter key on a Macbook Pro is 76 (it was 52 on the G4 Powerbooks).

I assign "Expose all windows" to Enter, and "Expose desktop" to Command-Enter (I don't use "Expose application windows", so I left it on the default, F10). If you want to use this setup, you can save my configuration file to ~/Library/Preferences.

If you try to edit this file yourself, be aware that there's some incorrect information in the tip linked to above (it's corrected in a later comment). Here's my summary of the process:
  • Go to the Dashboard/Exposé System Preferences pane and touch every hotkey setting to ensure that the file is created.
  • Open ~/Library/Preferences/ You can either use Property List Editor (included with Xcode, I think) or any text editor (it's xml).
  • The sections within this file are numbered, and they're in a strange order:
    • 32: Expose all windows (default F9)
    • 33: Expose application windows (default F10)
    • 34: Slow motion expose all windows (default Shift-F9)
    • 35: Slow motion expose application windows (default Shift-F10)
    • 36: Expose desktop (default F11)
    • 37: Slow motion expose desktop (default Shift-F11)
  • There are three parameters in each section.
    • The first is always -1 as far as I can tell; I don't know what it does.
    • The second is the keycode (F9=101, F10=109, F11=103, Enter=52 for Powerbooks and 76 for Macbook Pros. Use Full Key Codes to find codes for other keys).
    • The third is the modifier key: None=0, Shift=131072, Control=262144, Option=524288, Command=1048576. You can add these numbers together for multiple modifiers (for example, 1179648 is Shift+Command)
  • After you've edited this file, save it and log out. Once you've done this, don't touch anything in the Dashboard/Exposé preferences, or you might lose your customizations.