Trigger Caps Lock in Linux from the terminal

Revision history
Tags: linux x11

I have rebound my Caps Lock key using xmodmap so that it can be used as a modifier key to trigger Norwegian characters.

However, when I connect an external keyboard, the keymap changes back to default again and I have to re-run xmodmap ~/.xmodmap in order to reload the custom key bindings. If I have enabled Caps Lock before I reload, I can no longer use that button to disable it again. This is where xdotool come into the picture.

Send keystroke to X11

xdotool - command-line X11 automation tool

One of the available commands is key, which will send a key to the current window. I don’t really care what window I send Caps Lock to, so I can just send it directly.

$ xdotool key Caps_Lock

And now my Caps Lock is disabled again.

References

If you have any comments or feedback, please send me an e-mail. (stig at stigok dotcom).

Did you find any typos, incorrect information, or have something to add? Then please propose a change to this post.

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.