CSS Style Choice Dark Text on Light Background
CSS Style Choice Light Text on Dark Background 
Avatar: Old Photo of Gary's Face
[M] Gary
Vollink.com

07 Apr 2007

Getting "Control" on the "Caps Lock"

Introduction

At work, I've been using a Sun Workstation quite a bit.  A Sun Workstation has the positions of the left Control and Caps Lock swapped.  While this is completely backwards from what most are used to, it's amazing how convenient it is to have the control key right next to my left pinky.

Suddenly, I found myself hitting the Caps Lock key while attempting a cut and paste operation in Windows.  So, I found a way to remap the Caps Lock key to a Control key in Windows.  That soon transitioned onto my Windows laptop.

Recently, I decided to change over fully.  Below is what I did.

Tested On These Distributions:

This has only been tested with US 104 keyboard layouts.  The idea is the same on other ones, but I haven't done it.

I initially set this up on Debian Lenny/Sid (Unstable), then on Ubuntu 7.04.  There were very few differences between these, so the steps should be the similar on any Debian variant.

If you find out this works on a any distribution not listed below, E-mail me*, and I'll note it here. 

x86 - Debian Lenny/Sid (Unstable:2.6.18-4): Works
AMD64 - Debian Etch (Testing:2.6.18-4): Only Console Tested
x86 - Ubuntu (Feisty Fawn:2.6.20-14): Works
x86 - Windows XP (Service Pack 2) through Windows 10: Works

Procedure

Console

Console terminals (the virtual terminals that don't have an X display) use a different keyboard mapping than the X window system.  It is not necessary to do this to change the behavior in the X environment, but it's here because I find myself using the console on my server.

The console keymaps are stored in slightly different places, and look very different.  However, for both, the idea is the same.

Debian:
/etc/console/boottime.kmap.gz
Ubuntu 7:
/etc/console-setup/boottime.kmap.gz

Once you've found the console keymap, make a backup first.

sudo shell:
mv boottime.kmap.gz boottime.kmap.orig.gz
cp boottime.kmap.orig.gz boottime.kmap.gz
cp boottime.kmap.orig.gz test.kmap.gz
gzip -d test.kmap.gz

Use your favorite text editor to edit the file.  Find the Caps_Lock Entry.  If you want to move the Caps_Lock to another key, you'll want to make sure you keep track of everything right of the equal sign.

The Caps Lock and Control entries were very different, yet similar, and originally looked like this:

Debian:
keycode  29 = Control
...
keycode  58 = Caps_Lock
Ubuntu 7:
keycode 29 = Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control
...
keycode 58 = Caps_Lock Caps_Lock Caps_Lock Caps_Lock VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol Caps_Lock Caps_Lock Caps_Lock Caps_Lock VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol Caps_Lock Caps_Lock Caps_Lock Caps_Lock VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol Caps_Lock Caps_Lock Caps_Lock Caps_Lock VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol VoidSymbol

Once you find the lines above (again, in non-US, or even future kernels it's possible that these numbers will no longer match), either swap the right side, or replace the Caps_Lock key altogether.

If you share your computer with someone who isn't going to expect the Ctrl key to act like a Caps Lock, then you are better off removing the Caps Lock altogether.  Honestly, the Caps Lock isn't really very useful.

Debian:
keycode  29 = Control
...
keycode  58 = Control
Ubuntu 7:
keycode 29 = Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control
...
keycode 58 = Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control Control

gzip the file you just edited, and test it.  Remember, do not attempt this under X, it won't work.

Shell:
gzip test.kmap.gz loadkeys test.kmap.gz

Make sure everything is doing what you expect it to do.  If it isn't, and you find you are unable to get the original keymap loaded, you should be able to reboot, and everything should be back to normal (you did not do this directly to boottime.kmap.gz, right)?

Assuming everything is working as you expect it to, NOW is the time to replace the boottime.kmap.gz with the test.kmap.gz file.

XOrg Server

Changing the Caps_Lock key within the X environment, is done by modifying the options of the 'kbd' driver.  There was little difference between, Debian and Ubuntu 7 on this, except that Ubutnu 7 already had one XkbOptions entry set, and I needed to add an additional one.

/etc/X11/xorg.conf:
Ubuntu 7 (Original Entry)
Section "InputDevice"
	Identifier	"Generic Keyboard"
	Driver		"kbd"
	Option		"CoreKeyboard"
	Option		"XkbRules"	"xorg"
	Option		"XkbModel"	"pc105"
	Option		"XkbLayout"	"us"
	Option		"XkbOptions"	"lv3:ralt_switch"
EndSection

These are the two entries for use in the XkbOptions line:

ctrl:nocaps
ctrl:swapcaps

My kbd configuration section now looks like this:

/etc/X11/xorg.conf:
Ubuntu 7 (New Entry)
Section "InputDevice"
	Identifier	"Generic Keyboard"
	Driver		"kbd"
	Option		"CoreKeyboard"
	Option		"XkbRules"	"xorg"
	Option		"XkbModel"	"pc105"
	Option		"XkbLayout"	"us"
	Option		"XkbOptions"	"lv3:ralt_switch, ctrl:nocaps"
EndSection

Multiple Option "XkbOptions" are not possible, so multiple options must be comma separated.

The only place that I found XkbOptions listed, were in "*.lst" files in /etc/X11/xkb/rules.

Restart the X Windows system.

Windows XP

This section is really here for completeness. It has been used on several Windows XP systems, but has never been tried off of a "US" keyboard layout.

I've reduced this to two registry entry files. These files (if saved in Windows with a '.reg' extension) can be double-clicked and enabled.

Caps Lock and Ctrl are Control Keys:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
Caps Lock and Ctrl are Swapped:
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,1d,00,3a,00,3a,00,1d,e0,\
  00,00,00,00

NOTES:

MacOS 10

This section is only here for completeness.

The MAC has a built-in editor to deal with Ctrl key layout.

Screen capture of MacOS Keyboard and Mouse utility