Keyboard Remapping in Mac OS X (10.4)

The Problem

I have an IBM full size desk keyboard plugged into my iBook when I’m at work. This works find except the ‘option’ (aka alt) and ‘command’ (aka Apple, like Windows) keys are in the opposite places on the PC keyboard instead of a Mac. Given I also used the keyboard on the laptop, this was confusing to my fingers, so I need to be able to reverse the layout of these two keys. On Mac OS X 10.3 (Jaguar) I used to use the excellent uControl, which was totally fab and did more than this hack, but is no longer maintained for Tiger.

The Solution

So, here’s the hack. It works only because (a) you can remap some modifier keys in System Preferences in Tiger and (b) unbelievably, my iBook thinks it’s internal keyboard is ADB (remember them!) not USB. If you don’t know what ADB is (was?) don’t worry, it’s a Ye Olde Propriatary Macintosh thing.

Preparation

You do make backups, right?

ADB Keyboard?

Before trying this, make sure your Mac thinks it has an ADB keyboard internally:-

kextstat | grep ADBKeyboard

If you get some output, then you have a ADB Keyboard Driver loaded; and thus most likely an internal ADB Keyboard.

Remap Option and Command

Next up, remap your Mac’s Option (aka Alt) to Command (aka Apple) key using System Preferences:

System Preferences > Show All > Keyboard & Mouse > Keyboard > Modifier Keys

This will affect all keyboards, internal and external.

Reverse the Polarity of the remapping on the built in keyboard only

Now, to remap the internal keyboard back again. Fist backup the Info.plist of the AppleADBKeyboard.kext:-

cd /System/Library/Extensions/AppleADBKeyboard.kext/Contents/
sudo cp Info.plist{,.backup}

Now edit the Info.plist file and swap the 0×37 entry with 0x3A and vice versa. Real geeks use a god awful editor called vi for this purpose, however, unless your the masocistic kind, Apple’s perfectly serviceable Text Editor can be used. Or perhaps a Sonic Screwdriver if you have one handy.

Reload the kernel extensions

Rebuild kernel caches:-

sudo kextcache -c

Reload the kernel extension:-

sudo kextunload /System/Library/Extensions/AppleADBKeyboard.kext
sudo kextload /System/Library/Extensions/AppleADBKeyboard.kext

Test the keyboard externally – it should have the keys remapped as you want. Test the internal keyboard – things should work as normal (although they are actually being remapped twice).

Reboot and test again.

Share and Enjoy

 
technical/unix/mac_os_x/keyboard_remapping.txt · Last modified: 2006/01/03 22:42 by garylaw