Linux – Multi-Function CapsLock Without X

consolekeyboardkeyboard-layoutlinux

I would like to remap CapsLock to Esc when pressed by itself and Ctrl when pressed with another key without using X.

This is similar to a previous question ( Remap CapsLock to Escape and Control System Wide ) but I am specifically looking for a solution without X.

Best Answer

This keymod program reads keyboard events from a /dev/input/eventX device and injects most directly back into the kernel using the /dev/uinput device. The caps lock behavior is special: if the key is pressed and released without touching another key, an Esc key is sent into the kernel. If another key is pressed while holding the caps lock, holding the (left) control key is emulated instead.

Since the program takes control over the specified event device, being able to access the computer using e.g. SSH can be very handy when testing this. For example, pausing this program (using ctrl-z for example) will make sure you can't use your keyboard anymore (it has taken control over it exclusively and is now no longer active).