Remapping a keyboard

April 1, 2011

One month ago I've accidentally damaged my Macbook Pro keyboard so it completely stopped working. I've decided to replace it with a new one by myself, so I ordered the new keyboard from Ebay. While I was waiting for the parcel to arrive, I used an old-school Apple wireless keyboard, like this one:


What a torture it was! It weighs as much as kilo, so my notebook with mouse, keyboard and supply unit had more than 4 kilograms in weight. It was terribly heavy to carry.

Finally, the new keyboard module for my macbook arrived. I successfully replaced it, thanks to iFixit guide. But then I faced another problem: “ ] ” button worked as Caps Lock. Even Caps Lock button LED state was changing. A Many Tricks’ Key Codes app helped me to find out that it sends exactly same events to system as Caps Lock.

I decided that I can live without Caps Lock but cannot live without ] button as Objective-C syntax uses square brackets widely. So I planned to remap both Caps Lock and ] keys from Caps Lock functionality to ].

The solution was:

  1. Go to Keyboard → Keyboard Pane in System Preferences and remap Caps Lock to “No Action” (see screenshot),
  2. Download PCKeyboardHack and KeyRemap4MacBook apps,
  3. Install both of them,
  4. Search through both apps and find a suitable option (for me, it was an option Change Caps Lock in PCKeyboardHack),
  5. Change keycode of the key that you want to remap.
  6. ...
  7. PROFIT!

You'll also have to know the keycode of the key that you want to turn to. I spent a fair amount of time to find the keycodes table (as it is NOT connected with ASCII codes which are easy to find). I finally found it here: Virtual key-codes. Mirror link to pdf: here.

Hope this guide will save time for others.