Linux (X11) Keyboard Configuration

Introduction

Note
This was initially intended to be a longer article including some hardware recommendations and experiences. However, having not completed this for a long time, it was decided to put online the existing work on the “software side” which can be found in this article. The release of a follow-up post on the hardware issues is TBD.

Normally, it is not needed to deviate from the default keyboard configuration under X11. However, with specific hardware some issues might occur and it is then useful to know about the keyboard configuration.

Especially, since the documentation is not really easy to understand. Two important utilities when tuning X11 keyboard settings are xkbset and xset.

This blog post will cover key repeating. There is more to the keyboard configuration: One can set the layout (e. g. setxkbmap de for a German keyboard layout). There is things like dead keys and compose keys which will not be covered here.

For an extensive treatise on X11 and hot-plugged keyboards and multiple layouts, referring to Nicolas George’s debian-user post is recommended.

Delay and Rate

After pressing a key in e. g. a text editor, one character usually appears on the screen. If the key is held for some time, the same character will occur repeatedly. This of course also happens with arrow keys and such: They repeat after being pressed for some time. Two times are relevant here: The delay and rate.

Delay
The time between the first character appearing and the second character appearing if a key is held. This is also called ardelay for auto repeat delay (cf. https://unix.stackexchange.com/questions/40846)
Rate
The number of characters which appear per second if a key is still being held down after the second character has appeared. The delay between these consecutive characters is also called arinterval (for auto repeat interval).

These can be configured by means of the xset utility as follows:

xset r rate <delay> <rate>

Examples for rate and delay settings

# Repeated Characters appear quickly.
# This might be sensible base values to experiment with.
# (the first repeated after 250ms, the next after 1000/30 ~ 33ms)
xset r rate 250 30

# Repeated Characters appear slowly
# (the first repeated after 250ms, the next after 1sec)
xset r rate 250 1

# Repeated Characters appear very quickly but the delay for the second
# one to appear is long. This might be a solution if your keyboard
# "hangs" on a character longer than supposed to be.
# (the first repeated after 1s, the next after 10ms)
xset r rate 1000 100

# Repeated characters appear quickly and the repetition starts
# even more quickly (only try this if you know how to revert)
xset r rate 10 30

Disable/Enable Autorepeat

The automatic repetition of keys can be disabled completely by calling the following:

xset r off

(Re-)enable repeated keys as follows:

xset r on

If there is just some keys for which the autorepeat should be turned off, you will need to find out the keycode of the key at hand. This is easily done with the xev utility. Run xev | grep keycode and press the key to identify inside the appearing window. An output might look like this:

state 0x0, keycode 36 (keysym 0xff0d, Return), same_screen YES,
state 0x0, keycode 65 (keysym 0x20, space), same_screen YES,
state 0x0, keycode 65 (keysym 0x20, space), same_screen YES,
state 0x0, keycode 133 (keysym 0xffeb, Super_L), same_screen YES,

Here, the Enter, Space and Super (aka. Windows) keys were detected in that order. One can see that the keycode for space is e.g. 65.

With this, one can disable autorepeat for just the space key using the following:

xset -r 65

(Re)enabling works as follows:

xset r 65

Note the -r for disable and r for enable and how it differs from the “global” variant which uses r on and r off respectively.

Bouncekeysdelay

There is another time called the BounceKeysDelay. Bouncekeysdelay is an interval between consecutive key presses for which the concecutive key press will be ignored. I. e. if it is two seconds, after you press a key, all other presses of the same key are ignored for two seconds.

One might wonder what use this should have. The answer is bouncing keys (thus the name of the respective setting, cf. https://bbs.archlinux.org/viewtopic.php?id=213835).

The bouncekeysdelay will often be a small number of milliseconds. E. g. 50ms might fix a lot of keyboard issues but also ignore some key presses which come quickly after each other (e. g. when pressing the space key multiple times to indent a piece of code or such).

It can be configured by xkbset bo <bouncekysdelay> for instance the following seems not to miss too many intended key presses:

xkbset bo 25

The xkbset utility also has some other useful options e. g. it can define the autorepeat for all keys at once by means of a hexadecimal mask (although I do not have an usage example for that, so in case that feature is needed it is probably best to set the configuration as wanted and then print the hexadecimal values with xkbset q…).


Ma_Sys.ma Website 5 (1.0.0) – no Flash, no JavaScript, no Webfont, no Copy Protection, no Mobile First. No bullshit. No GUI needed. Works with any browser.

Created: 2019/03/16 23:19:43 | Revised: 2020/02/19 20:58:13 | Tags: kb, blog, keyboard, linux, x11 | Version: 1.1.1 | SRC (Pandoc MD) | GPL

Copyright (c) 2019, 2020 Ma_Sys.ma. For furhter info send an e-mail to Ma_Sys.ma@web.de.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.