Setxkbmap keeps resetting

Hey, so I like to remap my CapsLock to Control, which I do by running setxkbmap -option ctrl:nocaps.

I have this in my ~/.Xkbmap to set it at boot time.

-option ctrl:nocaps

The problem is that this setting keeps resetting at seemingly random times, so I’ll be typing away and suddenly CapsLock becomes CapsLock again.

It’s doing my head in! Any ideas what could be resetting thing and how I can make this permanent?

Welcome to the forum! :enos_flag:

For me, setxkbmap resets whenever I connect/disconnect a device. (speaker, keyboard)

I don’t know a way to make it permanent; what I did was to add a keyboard shortcut in my i3wm config to run the command again in background.

Welcome to the forum @plork :enos_flag: :partying_face: :tada: :balloon:

Which DE? Am at work, but you can use xmodmap to do this or tweaks on Gnome.

Well that is very interesting! I was just about to say that this isn’t a result of connecting/disconnecting a device since it happens too regularly.

However, just to check I ran udevadm monitor, and indeed it does seem that just wiggling the usb cable is actually disconnecting and reconnecting the USB device! Plugging into a different USB port doesn’t do this.

So at least this will save my sanity for a lot of the time!

It would still be nice, but not totally essential now, to work out how to make this setting more permanent though.

1 Like

XFCE.

If it can wait, I will share my .Xmodmap when I get home (19:00 UK time).

Yeah that would be awesome, thanks. I did try using .Xmodmap before to fix this, but couldn’t get it working. Would be very interested to see what you did!

clear lock
clear control
add control = Caps_Lock Control_L Control_R
keycode 66 = Control_L Caps_Lock NoSymbol NoSymbol

I currently use interception tools, and this article helped me:

It seems to be more resilient to bombing out. This is my config:

TIMING:
  TAP_MILLISEC: 250
  DOUBLE_TAP_MILLISEC: 150

MAPPINGS:
# Hold enter for left control
#  - KEY: KEY_ENTER
#    TAP: KEY_ENTER
#    HOLD: KEY_LEFTCTRL

# Tap = super+w
  - KEY: KEY_LEFTALT
    TAP: [KEY_LEFTMETA,KEY_W,]
    HOLD: KEY_LEFTALT

# Tap = super+t
  - KEY: KEY_LEFTCTRL
    TAP: [KEY_LEFTMETA,KEY_T,]
    HOLD: KEY_LEFTCTRL

# Tap = Escape
  - KEY: KEY_RIGHTCTRL
    TAP: [ KEY_LEFTMETA, KEY_E, ]
    HOLD: KEY_RIGHTCTRL

# Tap = Escape
  - KEY: KEY_CAPSLOCK
    TAP: KEY_ESC
    HOLD: KEY_LEFTCTRL

#  Tap is left/right bracket
#  - KEY: KEY_LEFTSHIFT
#    TAP: [ KEY_LEFTCTRL, KEY_SPACE, ]
#    HOLD: KEY_LEFTSHIFT

  - KEY: KEY_RIGHTSHIFT
    TAP: [ KEY_LEFTALT, KEY_LEFT, ]
    HOLD: KEY_RIGHTSHIFT

# Tap super for rofi:
#  - KEY: KEY_LEFTMETA
#    TAP: [ KEY_LEFTMETA, KEY_D, ]
#    HOLD: KEY_LEFTMETA

  - KEY: KEY_MENU
    TAP: KEY_HOME 
    HOLD: KEY_HOME 

The relevant bit is:

# Tap = Escape
  - KEY: KEY_CAPSLOCK
    TAP: KEY_ESC
    HOLD: KEY_LEFTCTRL
1 Like

Awesome thanks. I’ll have a look at interception, I didn’t know about those before, but they look really powerful!