Remapping Your Macbook’s Keyboard in Ubuntu 12.04
I just installed Ubuntu 12.04 (Pangolin) on the Macbook Pro that I got from work. The fact that Apple rearranges the has a different bottom row of keys drives me nuts, though. The placement of the Command keys are where the Alt keys should be, and there is no right ctrl key. My muscle memory is trained for a standard keyboard and fighting it, especially while coding, slows me down a lot.
Luckily, there’s a utility called xmodmap that will let you remap these keys however you want. Here’s what we’re going to do:
Drop the following code into a text editor and save it somewhere. I saved it as .xmodmappings in my home directory:
!
! clean most of the modifiers
clear control
clear mod4
clear mod1
! -----------------
! left side
! ----------------
! keycode 64 is the left alt key
keycode 64 = Super_L
! key code 133 is the left command key
keycode 133 = Alt_L Meta_L
! ------------------
! right side
! -------------------
! key code 134 is the right command key
keycode 134 = Alt_R Meta_R
! keycode 108 is the right alt key
keycode 108 = Control_R
add mod4 = Super_L
add mod1 = Alt_L Meta_L
add mod1 = Alt_R Meta_R
add control = Control_L
add control = Control_R
To test this, drop into a terminal and type:
$ xmodmap ~/.xmodmappings
It should make the following changes:
Left Alt -> Left Super
Left Command -> Left Alt
Right Command -> Right Alt
Right Alt -> Right Ctrl
Now test it out. If everything looks kosher, you can set this to run every time by pulling down the gear/power menu from the taskbar, choosing “Startup Applications”, and adding a new item containing the above command.
Note that this works on a 7th-gen Macbook, and the layouts may differ slightly on other models. If it doesn’t work for you, running xev from a terminal will let you discover the keycodes for your model, which you can substitute into the above script.
May 11th, 2012 • 2 Comments » • Tags: apple, howto, linux, tech, ubuntu •
