How to change CapsLock key to produce "a"?

Specifically, I don't know how to change CapsLock to a, because I don't remember the keycode. I'll find it a little later. But generally speaking, you can use xmodmap (and .Xmodmap) to change your keymappings. The first time GNOME detects your .Xmodmap file, it'll ask if you want to always load it, and then you're set.

I also think caps lock is silly. However, the key position is useful. I like mapping it to the Control key. I use control a lot, and it's tiring for my pinky to be constantly reaching down in that awkward position. And as I later found, historically Control is where Caps Lock is currently. Anyway. Create a file in your home directory called .Xmodmap with the following lines:

remove Lock = Caps_Lock
keysym Caps_Lock = Control_L

To make these changes take effect right this instant, run xmodmap ~/.Xmodmap.

You can find keycodes on your own using xev. Turns out the keycode for a is 38, or hex 0x61. So instead your .Xmodmap could be:

remove Lock = Caps_Lock
keysym Caps_Lock = 0x61

I highly recommend reading through the man page, lots of interesting stuff.


After looking at man xmodmap, it turns out there is an idempotent way to define this:

clear Lock
keysym Caps_Lock = Caps_Lock Control_L

After restarting X, you should be able to run xmodmap ~/.Xmodmap repeatedly without getting any "bad keysym" errors.

Update: Unfortunately this doesn't seem to be portable and idempotent.