The Problem

Since I don't find the "caps lock" key to be useful, I would rather use it as another "control" key instead.

I thought this would be easy to do in Linux, but it turned out to be tricky. I'm going to write down what I did here, in case it's useful to anyone else.

I am running OpenSUSE 12.3 using Xfce 4.10. This release uses X.org 1.13.2, which was released on January 23, 2013.

Attempts

The first thing I investigated was creating an .Xmodmap file in my home directory. Xmodmap is a utility for changing the key mapping in X11, and it can be used with configuration files. I found that this approach did not work-- when starting up X, the .Xmodmap file appears to be ignored.

My next attempt was to add an xmodmap invocation to an .xinitrc file, also in my home directory. Back in The Old Days, .xinitrc was where you put shell commands you wanted X11 to execute when you started the X server. However, this also doesn't seem to be read any more.

I was determined to have my keyboard remapped, so I added an xmodmap invocation to my .bashrc file. That way, whenever I started a new shell, xmodmap would be run. This is obviously somewhat of a hack, since not all bash shells that I run exist in a context where the X server is accessible. I also found that running xmodmap a second time produced errors. Those two problems were fixable. However, there was another problem which was not: when the keyboard was unplugged and plugged back in, the xmodmap configuration that I had set was cleared, and caps lock went back to its old behavior.

At this point, I started looking at an alternate configuration system called xkb. It seems that xmodmap is now deprecated in favor of this new system.

Most of the xkb material I found online was related to setting up European or Asian keyboard settings. It seems like most windowing environments have graphical tools to do this. In Xfce, you can go into "Control Panel" and select "Keyboard" to use a French or Spanish keyboard. However, this didn't help me, since in France and Spain, apparently the Caps Lock key is still the same.

My breakthrough came when I looked in /var/log/Xorg.0.log and noticed the line that included "xkb_options". Apparently, xkb has the concept of a layout (xkb_layout), but also the concept of options that apply to that layout. I found that the setxkbmap command-line program would allow me to set the "ctrl:nocaps" option, which replaced Caps Lock with a Control key, just like I wanted.

The Solution

I needed a way to get this behavior on startup, and even after the keyboard was unplugged and plugged back in again. It turned out that the best way to do this is by editing the X11 configuration file. However, since this is 2013, there is no longer one X11 configuration file. Instead, there's a whole directory of them. I found the right one was /etc/X11/xorg.conf.d/90-keytable.conf. Previously, it contained this:


Section "InputClass"
	Identifier "LocalKeyboard"
	MatchIsKeyboard "on"
	Option	"XkbLayout"	"us"
EndSection
I added the following line to this section:

	Option "XkbOptions" "ctrl:nocaps,ctrl:menu_rctrl"
After a reboot, I found that my keyboard was remapped! The change persisted when I unplugged and re-plugged in my keyboard.

Conclusion

Finally, I have conquered the Caps Lock key. It will always be Control from now on. Along the way, I learned just how many X11 mechanisms have been deprecated in Linux. All of the configuration files I used to use seem to be completely or partially non-functional now.

I also learned just how unhelpful forums can be. All of the older approaches people discussed online simply didn't work. Linux has moved on since then. Maybe Google needs a way to filter results based on when they were published. Hopefully, new systems like Wayland or Mir will clear up some of this confusion and introduce a consistent way to configure things.

Anyway, I hope this helps somebody. Take it for what it's worth and always remember that your results may depend on how closely my environment matches yours.