Image of the glider from the Game of Life by John Conway
Skip to content

Switching Caps Lock and Backspace

The Caps Lock is a completely redundant key. Think about it for a second. It does what holding down the shift key does on your keyboard. And, given todays technology, there is absolutely no reason why you can't have the shift key perform the function of the caps lock key. For example, pressing the shift key twice would invoke an ALL CAPS BEHAVIOR then pressing the key again would take you out of that behavior.

Think of it. We would have an empty key location on the keyboard that could be used for a much more functional key, such as a second enter or a meta-key. In other words, a key that would get much more use, than just uppercasing your characters. Simple. And yet, due to the stubborn nature of the uneducated, we continue to have the caps lock on our keyboards. Not only do we have it on the keyboard, it is not in an optimized location. Well, I went out to change that.

The caps lock key, by default is only one key distance a way from the left little finger. Looking at the keyboard, there is a key that I use far more heavily, although I shouldn't be, that is a much further distance (3 key distances): the backspace. To me, and I'm sure others, it makes much more sense, as August Dvorak discovered with the keyboard, to put the more commonly used keys close together, and the least commonly used keys further away. So, switching the backspace and caps lock key make sense. So, I set out to do just that, and it was easy.

Thankfully, there is this great little utility in X called 'xmodmap'. xmodmap gives you the ability to modify your keyboard layout to your leisure. So, I put in a config file the keys that I wanted to swap. By default, the keycode for the backspace key is 0x16 and the code for the caps lock key is 0x42. So, we just need to make the switch. Easy as pie:

remove Lock    = Caps_Lock
keycode 0x16 =  Caps_Lock
keycode 0x42 =  BackSpace
add    Lock    = Caps_Lock

This should be saved as '.xmodmap' in your home directory. To execute it, just 'xmodmap ~/.xmodmap' at the terminal prompt.

Now, you may have noticed that the repeating didn't follow the switch. Pressing and holding what used to be the backspace key, but is now the caps lock, flickers the caps light, as repeat is set on that key. Pressing and holding the new backspace key does nothing as you would expect it to. So, we need to get the repeat off of our new caps lock and on the new backspace, where it belongs. Fortunately, this is just as easy:

First, I need the keycodes for caps and backspace:

aaron@poseidon:~$ xmodmap -pk | grep -i caps
     22         0xffe5 (Caps_Lock)
aaron@poseidon:~$ xmodmap -pk | grep -i backspace
     66         0xff08 (BackSpace)

Perfect. 22 for caps and 66 for backspace. Let's fix the repeat now:

aaron@poseidon:~$ xset -r 22
aaron@poseidon:~$ xset r 66

Done. The only caveat to this, is if X is restarted, you will need to reset the repeats. The keys should already be modified.

Now that I have my keys swapped, and the behavior of the repeat works as expected, I can optimize my typing by limiting my finger stretches across the keyboard. This fits perfect with the Dvorak layout that I am already using, and will be even nicer when I get my Das Keyboard II in the mail, as nothing is printed on the keys.

{ 16 } Comments