~clarkema >_

Reconfiguring CapsLock on Debian

05 December 2022

As part of setting up my new FrameWork laptop, I want to get capslock reconfigured to my preference.

My normal configuration is to have capslock act as control when held, and escape when tapped in isolation. On my desktop this is done in the firmware (QMK) on my keyboard.

While the firmware approach is by far the best solution whenever possible, it’s not an option for the internal keyboard of a laptop1. To achieve the same effect in software on Debian requires two separate steps.

First, use X’s keyboard configuration file (see man 5 keyboard) to make capslock act as an additional control key:

Edit /etc/default/keyboard. Change the XKBOPTIONS line to read:

XKBOPTIONS="ctrl:nocaps"

Run the following to have the changes taking effect without rebooting:

$ sudo udevadm trigger --subsystem-match=input --action=change

Secondly, use xcape (apt-get install xcape) to add the escape functionality. To do this, make a simple shell script:

#! /bin/sh

# make control behave like escape when tapped
/usr/bin/xcape -e "Control_L=Escape"

Then arrange for this script to run when you log into your graphical session. In my case I’m using KDE on the FrameWork, so it’s just a case of opening the ‘Autostart’ system settings, clicking Add > Add Login Script, and selecting the script you just made.

Behind the scenes this just creates a symlink to the script in $HOME/.config/autostart-scripts

That’s it! Capslock is now useful again.

1

In the unusual case of the FrameWork laptop it is possible to reconfigure the keyboard using the laptop’s Embedded Controller (EC). While this is something I might investigate in the future, for now I’m taking the easy way out and sticking to software only. If you’re interested, see here and here.