Disable Capslock

Sunday, Jun 27, 2021
#unix #tips #X11

Capslock is a useless key so I figured I’d reassign it to something useful. There are three ways to change a keys function.

  1. Create a custom keyboard layout and set that as the default.
  2. Use xmodmap (not a good idea, not really standard).
  3. Use Xorg’s xkb settings.

If you’re using a non-Xorg machine the first option is probably what you’ll want to pick, but in the case of a Xorg machine option 3 is much simpler and better. I’m not actually sure the best way to do this on Wayland, but I guess I’ll have to figure that out eventually since Wayland is getting better and better.

Option 3

You can set xkb settings either with the command line tool setxkbmap which could be placed in your .Xinitrc for user settings or you can set them system wide in your Xorg config. Most modern distros split the Xorg config into various config files under /etc/X11/xorg.conf.d/.

Disable Capslock

To disable the use of the caps lock key you can simply create a file in /etc/X11/xorg.conf.d/ named 90-disable-caps.conf (or similar). Then place the below contents into that file. The files in that directory are loaded based on their sort order, so traditionally the names begin with two numbers that determine the load order.

Section "InputClass"
	Identifier "keyboard defaults"
	MatchIsKeyboard "on"
	Option "XKbOptions" "caps:none"

Basically this matches “keyboards” and sets the option caps:none. A full list of possible options is located inside /usr/share/X11/xkb/rules/base.lst. Most of the time you’ll want to swap caps for control or similar instead of outright disabling it. ctrl:nocaps Would switch it to control.

I added a link showing some of wayland’s improvements.