This works perfectly in the terminal but gives very mixed results in my desktop environment. Specifically, sometimes hitting CapsLock triggers Esc, sometimes it turns on CapsLock, and sometimes it does both. What might be causing this, and how do I ensure that I get consistent behavior across my machine?
I’m on Xubuntu 25.04, xfdesktop version 4.20.1, running on Xfce 4.20 with X11.
Are you sure about the use of setxkbmap in this case ? I would have used xmodmap. And I faintly recall that you first have to remove the Lock function from caps lock before redefining that key, otherwise the behaviour of the key becomes erratic.
May I quote from the DESCRIPTION section of ‘man setxbmap’ and ‘man xmodmap’ ?
xmodmap: The xmodmap program is used to edit and display the keyboard modifier map and keymap table that are used by client applications to convert event keycodes into keysyms. It is usually run from the user's session startup script to configure the keyboard according to personal tastes.
setxkbmap: The setxkbmap command maps the keyboard to use the layout determined by the options specified on the command line.
Basically it comes down to what you’re used to. xmodmap is for making small changes to the mapping on the fly, setxkbmap can do very big and complex changes in one command. I personally find the syntax of xmodmap easier, but AFAIK both of them are on the way out with Wayland.
xmodmap -e 'remove Lock Caps_Lock'
Note: removing Caps Lock from the list of locks doesn’t change it’s function, but changing it’s function without removing it from the list of locks creates an unconsistent state of the keyboard description …
Thank you. I tried adding xmodmap -e "remove Lock = Caps_Lock" to my .bashrc file, but then every time I open a new terminal window (Ctrl + T), I’m greeted with the following:
xmodmap: please release the following keys within 2 seconds:
t (keysym 0x74, keycode 28)
Control_L (keysym 0xffe3, keycode 37)
And the problem continues regardless.
Also, I did some more research, and I keep finding sites suggesting my original implementation is the correct one:
If it helps, the problem specifically seems to occur when I have an external keyboard hooked up to my laptop. Using the laptop’s native keyboard doesn’t cause a problem.
Oh, and I was mistaken in my OP: the problem occurs in the terminal as well.
Okay, I’ve been able to narrow down the problem somewhat. When the problem occurs with my external keyboard, I can manually run the setxkbmap command in the terminal, and the problem goes away until I unplug and replug my keyboard, at which point the setting gets reset, and I have to run the command again.