Use the Windows key as Ctrl Key on Linux

Tue 11 May 2010 by Thejaswi Puthraya

The Ctrl key on the Samsung R517 laptop is placed awkwardly for comfortable use with Emacs. Off late due to the strain of hitting the Ctrl key often, I started to feel a mild tingling on my pinky. I was anxious if this was the first stage of the infamous Emacs pinky. So I started looking for ways of reducing the pain and I came across a beautiful article by Steve Yegge on Effective Emacs. If you wish to become a power Emacs user, then you ought to read it. This article came as a real blessing in disguise and I hope my post might be useful to some other soul.

The article actually recommends swapping the Caps Lock and the Ctrl key. But as a fairly frequent user of the Caps Lock key, I did not like the idea and hence decided to swap it with the 'vestigial' Windows key. This is fairly simple process on Linux. Here's how I went about it...

  1. Figure out the key code of the windows key. Linux comes with an X utility called 'xev'. After firing that utility, I pressed the windows key several times and noted down the key symbol and key code. In my case, they were "Super_L" and "133".
Keycode identification using xev
  1. Map the key using 'xmodmap'.
keysym Control_L = Super_L
keycode 37 = Control_L
remove mod4 = Super_L
add Control = Control_L Control_R Super_L

What the code above does is that it first assigns the left control to the windows key and deassigns the left control. But we want an additional control key instead of deassigning it. So we take the key code of the left control as mentioned in Step 1 and reassign it to the Control_L key symbol. We then, remove the Windows key from the modifier group called 'mod4'. The 8 modifier groups are Shift, Lock, Control, Mod1, Mod2, Mod3, Mod4 and Mod5. These modifier groups hold a collection of keys for a specific action. For example, by default the Caps Lock is part of the Lock modifier. Suppose, you add another key to this group, you can make it function like a Caps Lock. This is the basis for the last line, where I wish to use the Left Control, Right Control and Windows key as control keys.

  1. Add the above xmodmap file to your bashrc (or bashrc_profile depending on your distro)
source path/to/the/above/xmodmap/file

May the power of Emacs be with you!