Swap Command and Alt keys on USB keyboard

Swap Command and Alt keys on USB keyboard 
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:


  ...
        IOKitPersonalities
 
                        Swap command and alt
                        1
....
                
        
.... 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.

이 블로그의 인기 게시물

둘 중 누군가 그녀를 죽였다, 범인 해설

[MAC OS X] mds_stores 100% CPU usage

tips more on unity ...