Remapping logo keys and menu key as CTRL


 
Quick messy update to this page

Since my last update I've changed how I remap the keys. Soon I may need to refer to it while away from my computer, so I'm quickly sticking it here.

If you need to know the hows and whys, look at the rest of this page.

Here's my current Linux .xmodmap file:

! Change capslock to act as ctrl, left logo as capslock,
! right logo as ctrl, menu as ctrl
keycode 66 = Control_L
add Control = Control_L
keycode 115 = Caps_Lock
add Lock = Caps_Lock
keycode 116 = Control_R
keycode 117 = Control_R
add Control = Control_R

!!! On my kubuntu install I needed the below, but not on ubuntu
!!! Make right alt work as meta
!!keycode 113 = Meta_R
And here is an image of the registry value when done in Windows XP:

The rest of this page still refers to how I used to do it.


 
Why I remapped my keyboard

In early 2006 I started using Emacs as my primary editor and
development environment. It was great to use such a powerful tool,
but constantly bending my wrists sideways to reach the CTRL keys was a
bother. Also, repeating such an awkward motion was a risk factor for
carpal tunnel syndrome, a potential career-killer for a programmer.

So after reading how Steve Yegge had remapped his keyboard to make
Emacs easier to use, I decided to remap my own keyboard to suit my
needs.

The best candidates for easy-to-reach CTRLs were the Windows logo
keys, and the "menu" (aka "application") key. They can be easily
reached by bending the pinky down, with very little sideways wrist
motion. And by having multiple CTRL keys to choose from on both sides
of the keyboard, I could use whichever one was most convenient at the
moment, depending on which of my keyboards ("split" or "normal") I had
plugged in, and where my hands were.

Also, those keys were mostly useless to me. Once in a while I would
press a logo key the get the Start menu, but it's easy enough to do
that with CTRL-ESC. And the "menu" key (aka "application" key) is
even more useless.

So, I figured out how keyboard scancodes work in Windows, found out
what scancodes I needed
, and modified my Windows registry as described
below.

Some time later I figured out how to do it in Linux, after reading the
xmodmap manpage and figuring out the key codes with xev.


 
Windows XP - Remapping logo keys and menu key as CTRL

Here's how I did it on my Windows XP systems. Don't do this unless
you're comfortable editing the Windows registry.

  1. Enter the registry editor:
    Do Start->Run, then type "regedit" and hit Enter (or click OK).
     
  2. Go to "HKEY_CURRENT_USER\Keyboard Layout".
    Make sure "Keyboard Layout" is selected.
     
  3. Do Edit->New->Binary Value.
     
  4. Name the new binary value "Scancode Map".
     
  5. Make sure "Scancode Map" is selected, and do Edit->Modify Binary Data.
     
  6. Enter the following value:
    00 00 00 00 00 00 00 00
    04 00 00 00 1D E0 5D E0
    1D E0 5C E0 1D 00 5B E0
    00 00 00 00
    
    Click OK when you're done.
     
  7. Log off and log back on (or reboot) for the change to take effect.
     

Technical meaning of each "word" in the binary value

Note that the values are entered as little endian.

"Header: Version"
00 00 00 00

"Header: Flags"
00 00 00 00

Number of entries in the map (including null)
04 00 00 00

Menu key (E0 5D) to RCTRL (E0 1D)
1D E0 5D E0

Right windows (E0 5C) to RCTRL (E0 1D)
1D E0 5C E0

Left windows (E0 5B) to LCTRL (00 1D)
1D 00 5B E0

Null terminator
00 00 00 00

 
Linux - Remapping logo keys and menu key as CTRL

In Linux you can remap your keys with the xmodmap utility.

First, run the xev utility to determine the keycodes for the keys.
On my system they turned out to be:

Left logo = 115
Right logo = 116
Menu = 117

I don't know how standard those codes are; you should run xev to
verify them yourself.

Then using that information, create the file ~/.xmodmap and put these
lines in it (your exact keycodes may vary, as I mentioned above):

! Change logo keys and menu key to CTRL
keycode 115 = Control_L
add Control = Control_L
keycode 116 = Control_R
keycode 117 = Control_R
add Control = Control_R
Finally, put this line in your .bash_profile:
xmodmap ~/.xmodmap
If your .bash_profile automatically executes when your session starts,
you should be all set. However if that doesn't happen, you can
manually execute it.

(For my Debian GNU/Linux version 3.1r2 system, I have to run it
manually, although there probably is a setting I could change somewhere
to fix that.)


Related links

A Microsoft article on how it works in windows:
http://www.microsoft.com/whdc/device/input/w2kscan-map.mspx

Article by Steve Yegge primarily on customizing Emacs, but also with a
brief section on how he remapped his keyboard:
http://opal.cabochon.com/~stevey/blog-rants/effective-emacs.html

More on scancodes (with a Linux slant):
http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html


Back ...

... to David Rantanen's home page.


Last modified (UTC):
$Date: 2007-11-01 12:56:24 $