Key Mapping in GNU/Linux (Debian Lenny)
After getting frustrated with OS X for a long time, I recently moved back to Debian(Lenny). Since my laptop(Dell D630 Latitude) has two Ctrl keys(one on either side of the spacebar), i decided to use Caps Lock key as Ctrl and make the right side Ctrl key Caps Lock. I didn’t want to disturb Left Ctrl key as sometimes i use it for certain special key combinations. I started out with Gnome’s KeyBoard Preferences[gnome-keyboard-properties](Layout Options -> Ctrl key position -> Swap Ctrl and CapsLock) to change my Caps Lock to Ctrl, but that made the Left Ctrl key Caps(which was rather inconvenient for me), and on top of it didn’t fix CapsLock-On/Off indicator that my keyboard has, which used to turn a little green light on and off every time i pressed Ctrl. Unnecessary blinking didn’t hurt as-such, but then i didn’t quite like that because it was constantly dragging my attention away from the display.
In addition, i sometimes use the text terminals(Ctrl + Alt + Fn)(0 < n < 7) for various things, which still were unaffected by this mapping at Desktop Manager level.
This is what i did to fix the non-X (text terminals).
$ sudo sufound the following lines
# cd /etc/console
# cp boottime.kmap.gz boottime.kmap.orig.gz
# gzip -d boottime.kmap.gz
# emacs -nw boottime.kmap
keycode 58 = Caps_Lock (around line number 130)
keycode 97 = Control (around line number 222)
and changed them to….
keycode 58 = Control
keycode 97 = Caps_Lock
respectively, and then gziped it back to boottime.kmap.gz…
# gzip boottime.kmap
# loadkeys /etc/console/boottime.kmap.gz
Post loadkeys, the Right Ctrl key should become Caps Lock and the Caps-On/Off indicator should starts responding to Right Ctrl keypress while on non-X terminals.
However, this fix doesn’t affect(fix) X-based displays, since we have only changed console keymap.
This is what did the trick for X-displays…
$ cd ~
$ emacs -nw .xmodmap
add following text in the opened file…
! Swap Caps_Lock and Control_R
remove Lock = Caps_Lock
remove Control = Control_R
keysym Control_R = Caps_Lock
keysym Caps_Lock = Control_R
add Lock = Caps_Lock
add Control = Control_R
Save the file, logout and login again.
Post login, a prompt will solicit confirmation to accept .xmodmap as an xmodmap file, add the file to confirmed xmodmap file list.
The changes will enable Right Ctrl as Caps Lock, Caps-On/Off indicator will start working as expected and physical Caps Lock/Left Ctrl key will both behave as Ctrl.
As an Emacs user, i find this key-mapping really good. Even on other distros(flavours of GNU/Linux), this way of mapping keys should work(the correct files may need to be located though….).
About this entry
You’re currently reading “Key Mapping in GNU/Linux (Debian Lenny),” an entry on codehunk
- April 17, 2009 / 5:28 am