Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Swap Command and Alt keys on USB keyboard Other Hardware
Today I ruined my silver Apple keyboard by spilling coffee on it and had to switch back to an old PC keyboard with a German layout. Which is a fine keyboard with one very annoying attribute: the Control (Windows) and Alt keys are swapped, the bottom keys are from left to right: Ctrl - Windows(Command) - Alt - Space. It can drive you crazy. So I searched for a solution but it was not as obvious as I had expected.

With Snow Leopard the mapping can be changed via System Preferences » Keyboard, there choose 'Modifier keys...' and in the Dialog remap Alt (Option) and Command. However, some applications, like Eclipse, do not get these changes.

So, I would like to swap the modifiers further down at the input driver level. There are descriptions how to modify AppleUSBKeyboard.kext. That seems to be outdated since I can not find AppleUSBKeyboard.kext on Snow Leopard (10.6.7) anymore. But looking at the source code for the the keyboard handler shows that there is a property Swap command and alt evaluated which belongs to the IO Service Provider. At least for Snow Leopard. Unfortunately, the property seems to be poorly documented and I could not find any example.

Using the IORegistryExplorer to check the internal and USB keyboard settings I found another property of the provider, alt_handler_id, set for the internal keyboard. In the same way I added the property Swap command and alt for the IOHIDEventDriver as follows:

First, open the property list for editing (as system) using a text editor capable of authenticating. I just used vi:
sudo vi /System/Library/Extensions//IOHIDFamily.kext/Contents/PlugIns/IOHIDEventDriver.kext/Contents/Info.plist
Note that the above path can be used with BBEdit or TextWrangler as well. Then make the following addition to the plist file:
<plist version="1.0">
<dict>
  ...
        <key>IOKitPersonalities</key>
 
                        <key>Swap command and alt</key>
                        <integer>1</integer>
....
                </dict>
        </dict>
 ....
</dict>
After running

touch /System/Library/Extensions

in Terminal followed by a reboot, the USB keyboard's Alt and Command keys were changed.

Furthermore, with this kind of keyboard you may want to change the input method. For example, a keyboard layout can be created with Ukelele. For me, the layout offered here works perfectly. Just download it and copy to /Library/Keyboard Layouts.

[crarko adds: I haven't tested this one.]
    •    
  • Currently 3.83 / 5
  You rated: 5 / 5 (6 votes cast)
 
[21,408 views]  

Swap Command and Alt keys on USB keyboard | 6 comments | Create New Account
Click here to return to the 'Swap Command and Alt keys on USB keyboard' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Swap Command and Alt keys on USB keyboard
Authored by: nschum on Jun 01, '11 08:41:06AM

I use KeyRemap4MacBook to switch (only the right-side) Command and Option keys on my MacBook. It works for Eclipse.

It probably works on USB keyboards, as well.



[ Reply to This | # ]
Swap Command and Alt keys on USB keyboard
Authored by: Balthamos on Jun 02, '11 08:57:07PM

I second KeyRemap4MacBook. It works great and works for just about everything. Haven't had it fail on anything yet.



[ Reply to This | # ]
Swap Command and Alt keys on USB keyboard
Authored by: asmeurer on Sep 05, '11 01:29:18PM

Yes, please use this instead of manually editing a kernel extension.



[ Reply to This | # ]
Swap Command and Alt keys on USB keyboard
Authored by: mdwittenberg on Jun 01, '11 09:14:01AM
Excellent hint... It's a shame the settings in Keyboard Preferences don't change it everywhere

[ Reply to This | # ]
Swap Command and Alt keys on USB keyboard
Authored by: dvo on Aug 17, '11 10:34:55PM

On my MacBook Air (running Mac OS X 10.6.8 and now 10.7.1), following the above hint
to change IOHIDEventDriver.kext/Contents/Info.plist caused a kernel trap on reboot :-(

There is an official and also much simpler solution: System Preferences -> Keyboad -> Modifier Keys
Select the internal, and optionally also the external USB keyboard, then swap Option and Command keys

I also use KeyRemap4MacBook, but not for this purpose, because swapping the modifier keys (Command_L
and Option_L as well as Command_R and Option_R) with this tool would only affect the internal keyboard.



[ Reply to This | # ]
Swap Command and Alt keys on USB keyboard
Authored by: iandennismiller on Jan 06, '12 08:26:26PM

"There is an official and also much simpler solution: System Preferences -> Keyboad -> Modifier Keys
Select the internal, and optionally also the external USB keyboard, then swap Option and Command keys"

dvo is exactly right - the best way to swap command and option is through System Preferences. This works on Lion; I can't comment on anything earlier. In my case, I wanted to keep the internal keyboard as is, but swap the keys on my windows USB keyboard. This works like a charm!



[ Reply to This | # ]