| Erik's linux page: Linux information for beginners and advanced users | ||
|---|---|---|
| Prev | Chapter 3. Some other Linux information, perhaps not for the new user | Next |
Changing your caps lock into Ctrl in X
Have you ever been irritated that there's a big key between tab and skift that you never use? If not, sometime in the future your left little finger might start complaining about having to reach all the way down to the Ctrl key every time you're moving around in an emacs buffer. This small tip will let you redefine your Caps Lock into a Ctrl key in X.
Of course there is a solution for this. The X window system wasn't designed by a gang of morons so the key mapping system is quite flexibel, though a little bit hard to understand. I won't say I understand it :)
So, let's say you wan't to change your Caps Lock into a Ctrl key. The first thing to do is to glance through the manual page of xmodmap. When you're done with that you'll understand a little bit more of what's happening. The next thing would be to execute the xev from an xterm or similar. Try putting the cursor in the window popping up, and press some keys up and down. A lot of information will pass by in the xterm you started the xev from. It will most probably look something like this:
KeyPress event, serial 21, synthetic NO, window 0x4800001,
root 0x36, subw 0x0, time 921569335, (87,93), root:(796,823),
state 0x0, keycode 66 (keysym 0xffe3, Control_L), same_screen YES,
XLookupString gives 0 characters: ""
KeyRelease event, serial 21, synthetic NO, window 0x4800001,
root 0x36, subw 0x0, time 921569438, (87,93), root:(796,823),
state 0x4, keycode 66 (keysym 0xffe3, Control_L), same_screen YES,
XLookupString gives 0 characters: "" |
Now lets do some real action! You might want to start with executing xmodmap -pke and redirect the output to some file. That way you might be able to restore your keymap without restarting your X. After that, do this:
xmodmap -e 'keycode 66 = Control_L' xmodmap -e 'clear Lock' xmodmap -e 'add Control = Control_L' |
xmodmap -e 'keycode 117 = Caps_Lock' xmodmap -e 'add Lock = Caps_Lock' |
I assume you don't want to do those commands every time you restart your X. (Personally I don't restart X more often than once a week or so). The solution to this is to put something like this:
keycode 66 = Control_L clear Lock add Control = Control_L keycode 117 = Caps_Lock add Lock = Caps_Lock |
That's all folks! Now get used to your new key, or use the old one. Some variation is always good to prevent repetetive stress injuries caused by keyboards.