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

  1. Ralesk using Konqueror 3.5 on Kubuntu | March 6, 2007 at 11:28 am | Permalink

    Interesting choice!

    I’m not a fan of wasting time with unlearning and then re-learning so many reflexes, which you have to revert the very moment you have to sit at a computer that’s not yours — hence why I still use a QWERTY layout (although yes, under AltGr I can reach anything I need, including Hungarian characters); but as I don’t use Caps Lock either, and I got severely annoyed by its presence a couple times before, I too changed it to something more fun: it’s become my Compose key. Works like a charm :)

  2. Rick using Firefox 2.0.0.2 on Ubuntu | March 6, 2007 at 11:44 am | Permalink

    I love this tip. Using caps lock for control has been so nice on the hands and I try to get as many shortcuts to a control combo as I can. Ctrl-q for yakuake, ctrl-space for gnome-launch-box. Good stuff. One tip, in gnome in ubuntu you can make this change by going to System->keyboard->Layout Options->Ctrl Key Position. It gives you several options on just what you want to do with it.

  3. Chris Humphries using Firefox 2.0.0.2 on Ubuntu | March 6, 2007 at 1:40 pm | Permalink

    But my control key is there! ;)

  4. Miles using Firefox 2.0.0.2 on Windows XP | March 6, 2007 at 4:02 pm | Permalink

    But, I need Caps Lock on Linux. Not on Windows, but I need it on Linux. Without it, I wouldn't even be able to type caracters such as Ç or É.

  5. Can Bican using Firefox 2.0.0.2 on Mac OS | March 6, 2007 at 5:32 pm | Permalink

    The keyboard is full of stuff nobody ever used, layout is inconvenient for any language on earth, so if caps lock is the last problem yet to be solved, let's solve it but not lose it. How about giving the function of caps lock to scroll lock? ;)

  6. Garren using Swiftfox on GNU/Linux | March 6, 2007 at 11:03 pm | Permalink

    I was wondering how I get it to stay like this at startup

  7. Garren using Swiftfox on GNU/Linux | March 6, 2007 at 11:03 pm | Permalink

    I was wondering how to have it stay like this at startup

  8. Dan using Firefox 2.0 on Windows XP | March 7, 2007 at 12:33 am | Permalink

    I tried to do this, but realized that I am uneducated and stubborn.

  9. Brian using Firefox 2.0.0.1 on Ubuntu | March 7, 2007 at 1:27 am | Permalink

    Does anybody know the code for the escape key? Would be a lot quicker when using Vi..

  10. Aaron using Firefox 2.0.0.2 on Ubuntu | March 7, 2007 at 6:42 am | Permalink

    Ralesk- The point, as you pointed out, is to move the caps lock away from the user, and put in it's place a much more used key, in my case, the backspace.

    Miles- I'm not removing it, but moving it. The caps lock still exists on my system.

    Can Bican- Good idea! Placing the caps lock as a meta key under/above the scroll lock is a perfect idea.

    Garren- If you have put the switch in your ~/.xmodmap file, it will take effect at startup. Setting the repeat is the only thing that you need to do manually. However, you can have a script launch that at startup as well.

    Brian- The code for the escape key is 0x09. Now that I think about it, putting the escape key is where the Windows key is is a great idea, just because of vim.

  11. Bill using Firefox 2.0.0.1 on Unknown O.S. | March 7, 2007 at 9:43 am | Permalink

    But it makes the little light go on and off.

    Look at the pretty light.

  12. phoenyx using Firefox 2.0.0.2 on Ubuntu | March 7, 2007 at 11:35 am | Permalink

    Here's how I changed mine:

    xmodmap -pke > ~/.xmodmaprc

    Edit the .xmodmaprc file to taste. (It automatically uses it when you start up.)

  13. Philip Hofstetter using Firefox 2.0.0.2 on Mac OS | March 8, 2007 at 5:45 am | Permalink

    Hi,

    about Caps Lock being usless: With the swiss german keyboard layout, capslock doesn't at all work like it would if you pressed and hold shift:

    Caps Lock only affects normal letters that actually have a uppercased form.

    So if Caps Lock is enabled and you press the a-Key, it'll convert it to A. But if you press the 5-key, it'll do nothing. This is different from any other keyboard layout I know where it would be converted to Shift-5 (% here).

    This is interesting, because we have some accented characters available on shifted keys.

    Let's take the ö-Key:

    unshifted, no caps lock: ö
    shifted, no caps lock: é
    unshifted, caps lock: Ö
    shifted, caps lock: É

    Pressing shift when caps lock is enabled will revert the uppercasing again.

    So caps lock is - with the swiss layout - actually doing what its name implies: It locks your keyboard so it only creates capitalized letters.

    Actually, to write Ö, we only have two options:

    1) Caps lock on and the ö-key
    2) Hit the dead-key ¨ and then Shift-O

    I prefer the Caps lock way as it means one fewer key press.

    Granted. Not that many nouns (remember, in german you capitalize nouns) begin with a ö, so it doesn't happen all that often, but still, I prefer Caps Lock to be where it is.

    Still, you provide us with a nice trick. I just wanted to add some trivia :-)

    Philip

  14. Aaron using Firefox 2.0.0.2 on Ubuntu | March 8, 2007 at 6:41 am | Permalink

    Phillip- You're not paying attention. I am aware of the accented characters in different languages. Pressing the double-shift would have the EXACT behavior that the caps lock does now. Nothing would change.

  15. Philip Hofstetter using WebKit 418.9.1 on Mac OS | March 8, 2007 at 7:10 am | Permalink

    Hi Aaron,

    I WAS paying attention and I was fully aware how nice your hack works. I just wanted to give some trivia of how my particular keyboard layout works.

    Philip

  16. Nick Stolwijk using Firefox 2.0.0.11 on Ubuntu | January 2, 2008 at 1:14 am | Permalink

    To auto enable/disable the repeat have a look at http://gentoo-wiki.com/HOWTO_Use_Multimedia_Keys#Disabling_auto-repeat

Post a Comment

Your email is never published nor shared.

Switch to our mobile site