The Hunting of the Snark


category: encategory: maccategory: tech created: 19. May 2005
modified: 18. Jun. 2005
canonical: http://treehouse.de/index.cgi/0007

ADB Keyboard hacks in Mac OSX Tiger (10.4)

In Adapting Mac OSX Tiger i said, simple remappings of modifier keys are possible without actually patching Apples Drivers. This is at least true for ADB Keyboards like those built into current iBooks and PowerBooks. Now that uControl seems not to be developed any further, i have had a couple of request (OK: 2 requests) and thought, i'd write down the details...

Apples own new Keyboard preference allows you to swap alt, option, command and capslock around and for many people, the "capslock-ctrl" feature was the main reason to use uControl at all. Check out Apples own comments in the ADBKeyboard driver about this feature:

//To better support the BSD (hacker) community
...
// FYI:  The LED will still continue to be controlled by the PMU 
// and change regardless of the state in SW.  While this may not
// be desired, it has been the position of the BSD management and
 // WWDR that the developement community is not concerned.

Other features of uControl like touchpad scrolling are now implemented elsewhere in a different way so Shane Celis is not interested in actively maintaining it.

enterkey.gif This leaves those of us stranded, that just hate the mysterious enter key on Power- and iBooks (the red one on the image to the right). No one could ever tell me, what it is actually good for.

Addition on May 23rd 2005: Just now, this hint on MacOSXHints.com popped up that detailed, what this enter key might originally be meant for... I still need an option key on the right more !

Luckily, Apple provided a hackish but still not too hard way to remap keys on the ADB Keyboard:

/System/Library/Extensions/AppleADBKeyboard.kext/Contents/Info.plist

In this file, there is a section ADBVirtualKeys that looks like this:

0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,
0x30,0x31,0x32,0x33,0x34,0x35,0x3B,0x37,0x38,0x39,0x3A,0x7B,0x7C,0x7D,0x7E,0x3F,
0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,
0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,
0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,
0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x3C,0x3D,0x3E,0x36,0x7F

and here, you can actually remap keys permanently (or until an apple update shoots it back again...) by just using the text editor of your choice...

find the 0x34 which is the code for the enter key and replace it with

correction on May 27th 2005: I had previously written 0x36 for control while in fact 0x3b is correct - that was just my poor hadwriting: scribble a small b on a piece of paper - read a 6 later when i type it here... sorry.

Don't add any linefeeds or formatting. leave those hex codes just as they are or the System might not be able to read them properly. Also: be warned: this is a modifiaction of a core system file that may render your machine unusable! While the keyboard driver code tries to have sane fallback rules in case the Info.plist file does not make sense, you might still turn it into that kind of gibberish that is barely acceptable but leaves you with a non-working keyboard. Best keep a spare USB keyboard around in case you mess up (those use another driver that is not affected by these modifications).

Once (after you made a backup of the original of course) you changed this as root and rebooted, your enter key should have turned into another modifier key... Instead of rebooting, you can simply unload and reload your keyboard driver - but be sure to do this in just one command line because once you unloaded it, you won't be able to type the command for loading it again...

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /System/Library/Extensions/AppleADBKeyboard.kext.org/Contents/Info.plist
sudo kextunload /System/Library/Extensions/AppleADBKeyboard.kext && sudo kextload /System/Library/Extensions/AppleADBKeyboard.kext
This simple hack does not work for remapping from or to the fn key and there is no way to deal differently with left or right modifier keys (ie. remap just the right command key instead) in this setup because both features are handled deep within the keyboard controller. It works the same way in OSX Panther (10.3) by the way.

Addition on June 3rd 2005: I have had a few reports of problems:

sudo rm /System/Library/Extensions.mkext
sudo rm /System/Library/Extensions.kextcache
sudo touch /System/Library/Extensions
sudo touch /System/Library/Extensions/AppleADBKeyboard.kext

I have also had one very weird scenario, where i had changed the enter mpping like described above, rebooted, happily saw that the modification worked, closed the lid of the powerbook so it slept and then - after wakeup - found that the enter mapping had reverted to the previous setting. No traces of this older mapping should have been left on the system so i can not really explain what has happened here (and again: i have not been able to reproduce this ever since). I would be glad, if someone could shed some light on this...

Addition on June 8th 2005: Thanks to a Hint by William Mortensen: If for some reason, your Modifications don't stick, you may also try deleting yet another kernel cache:

sudo rm /System/Library/Caches/com.apple.kernelcaches/*
and/or rebuild it with:
sudo kextcache -c


(c) Heiko Hellweg 2005 - 2009 top