1

I'm using Caps Lock as a Control key, configured with the following command (I'm running Gnome):

gsettings set org.gnome.desktop.input-sources xkb-options \
  "['caps:ctrl_modifier']"

Sometimes when I press a Control-modified key, the key autorepeats. For example, I'll type Ctrl-w and all of a sudden the w key starts repeating as if I were holding it down. I suspect a keyup event is being lost. The repeat goes on indefinitely until I hit another key.

Also maybe related, sometimes when I press a Control-modified key, it simply does nothing, as if I "pressed it wrong". I just try again and it works, but I suspect this is another symptom of the same underlying problem.

How can I debug/fix this? I'd like to see which keyboard events are being sent, and when.


Update

I still haven't found a fix for this (not sure what to do about the answer below, because it's helpful information, but did not solve my issue), but I used xinput to monitor the keyboard events involved.

It appears to be related to "rollover", because I can only reproduce the key-repeat bug with key-sequences like press Caps, press W, release Caps, release W (as opposed to releasing W before releasing Caps).

I also can only reproduce the bug in X, not in a virtual console.

I emptied out the xkb-options I had set via gsettings, and am now relying on /etc/X11/xorg.conf.d/00-keyboard.conf instead:

Section "InputClass"
  Identifier "Keyboard catchall"
  MatchIsKeyboard "on"
  Option "XkbModel" "pc104"
  Option "XkbLayout" "us"
  Option "XkbOptions" "ctrl:nocaps"
  Option "XkbVariant" ""
EndSection

I switched caps:ctrl_modifier to ctrl:nocaps because it works in the virtual console as well as X.

So I'm still hunting for a solution, but I feel I've at least learned a few things in the process.

ivan
  • 1,878
  • It might be easier to make caps a control key in X rather than gnome. Especially if gnome is giving you some strange behavior. – 111--- Feb 16 '18 at 14:05
  • @datUser how might I do that? – ivan Feb 16 '18 at 14:35
  • 1
    try using the XKB option ctrl:nocaps instead of caps:ctrl_modifier. they are subtly different options. compare the definitions in /usr/share/X11/xkb/symbols/ctrl and ../symbols/capslock for details. – quixotic Feb 20 '18 at 02:37
  • @quixotic Thanks for the suggestion. While digging into this, I actually ended up switching to ctrl:nocaps because that works in virtual console as well. It didn't solve my problem, but it was a good find, and got me thinking more clearly about keysyms. – ivan Feb 20 '18 at 04:05

1 Answers1

2

Setting the control key behavior in XServer rather than Gnome (assuming you aren't using wayland instead of X):

Using setkbmap

  1. Get your keyboard layout:

    setxkbmap -query
    

    Look for the stanza labeled layout. Something like gb for an English layout. Yours may be different.

  2. Modify the keyboard layout's options using the same layout your are alreay using in #2 above:

    setxkbmap -layout gb -option ctrl:nocaps
    

    Here the ctrl:nocaps option makes your caps lock an additional control key. To make this change permanent you can add it to your .xinitrc file if you are starting X with startx or xinit from a terminal. If you aren't doing that see this answer for how to run a command at login for Gnome.

Using xmodmap

Create the following .Xmodmap file in your home dir:

!
! Make Caps_Lock another Control_L
!
remove Lock = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock

You can then run the following at start up to make this change active for your X session:

xmodmap ~/.Xmodmap

Once you have something you like you can either add this command to your .xinitrc or use the same method as linked above to make this permanent.

Going Deeper

You can also change caps to control at the kernel level using loadkeys.

The basics here are to use dumpkeys to dump your existing key map to a file. Change the mapping for caps lock and then use loadkeys to load your new keymap.

Note that since you are making changes to how the kernel reads the keyboard input, these changes will need root privileges. Here's a github gist with the relevant modifications and some instructions.

111---
  • 4,516
  • 3
  • 30
  • 52