I was looking for a solution to mapping the CapsLock
key on my laptop into Ctrl
and Esc
. I was happy with using the setxkbmap and xcape solution for a while now, but I also had a problem with it: whenever I did a system update in Arch and the initramfs got regenerated, I would suddenly lose my bindings.
As I searched for an alternative solution, I came across Interception Tools. This solution also has an additional benefit. I can use the same configuration in X, Wayland and TTY as well!
Interception tools is like middleware which helps in changing the behaviour of key events.
it contains four main CLI commands:
intercept
- captures the device eventsmux
- combines multiple input event streams as oneudevmon
- the monitor for eventsuinput
- redirect input events to the virtual device
In short, we use the above tools to capture input from a device, modify it somehow (using plugins or our own executables which can handle input events) and finally sending the input to the same device again. All in the matter of a few microseconds 😄
Plugins are also available for easy configuration and remapping for common scenarios.
Here’s how I did it:
- Remove any previous configurations that modified key events I had to remove my previous settings from
.xinitrc
# setxkbmap -option 'ctrl:nocaps'
# xcape -e 'Control_L=Escape'
- Kill the xcape process and reset the setxkbmap options
pkill xcape
setxkbmap -option
- Install the tools first! I use Arch so yay does it seamlessly for me.
yay -S interception-caps2esc #installs the interception-tools (the main package) as well
- Configure a job for udevmon to listen in
/etc/interception/udevmon.yaml
- JOB: "intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE"
DEVICE:
EVENTS:
EV_KEY: [KEY_CAPSLOCK, KEY_ESC]
- Enable the provided systemd service
udevmon.service
sudo systemctl enable --now udevmon.service
- Enjoy your RSI free experience!