# Keyboard configuration in console

Related articles

- Keyboard configuration in Xorg
- Extra keyboard keys
- Fonts#Console fonts

Note: This article covers only basic configuration without modifying layouts, mapping extra keys etc. See Extra keyboard keys for these advanced topics.

Keyboard mappings (keymaps) for virtual console, console fonts and console maps are provided by the kbd package (a dependency of systemd), which also provides many low-level tools for managing virtual console. In addition, systemd also provides the localectl tool, which can control both the system locale and keyboard layout settings for both the virtual console and Xorg.

## Viewing keyboard settings

Use `localectl status` to view the current keyboard configurations.

## Setting keyboard layout

### Keymap codes

Usually one keymap file corresponds to one keyboard layout (the `include` statement can be used to share common parts and a keymap file can contain multiple layouts with some key combination used for switching). The keymap files are stored in the `/usr/share/kbd/keymaps/` directory tree.

The naming conventions of console keymaps are somewhat arbitrary, but usually they are based on:

- Language codes: where the language code is the same as its country code (e.g. `de` for German, or `fr` for French).
- Country codes: where variations of the same language are used in different countries (e.g.`uk` for United Kingdom English, or `us` for United States English); a list of country codes can also be found in wikipedia:ISO 3166-1#Officially assigned code elements.
- Keyboard layouts: where the layout is not related to a particular country or language (e.g. `dvorak` for the Dvorak keyboard layout).

For a list of all the available keymaps, use the command:

    $ localectl list-keymaps

To search for a keymap, use the following command, replacing `search_term` with the code for your language, country, or layout:

    $ localectl list-keymaps | grep -i search_term

Alternatively, using find:

    $ find /usr/share/kbd/keymaps/ -type f

### Persistent configuration

A persistent keymap can be set in `/etc/vconsole.conf`, which is read by systemd on start-up. The `KEYMAP` variable is used for specifying the keymap. If the variable is empty or not set, the `us` keymap is used as default value. See `man 5 vconsole.conf` for all options. For example:

    /etc/vconsole.conf

    KEYMAP=uk
    ...

For convenience, localectl may be used to set console keymap. It will change the `KEYMAP` variable in `/etc/vconsole.conf` and also set the keymap for current session:

    $ localectl set-keymap --no-convert keymap

The `--no-convert` option can be used to prevent `localectl` from automatically changing the Xorg keymap to the nearest match. See `man localectl` for more information.

### Temporary configuration

It is possible to set a keymap just for current session. This is useful for testing different keymaps, solving problems etc.

The loadkeys tool is used for this purpose, it is used internally by systemd when loading the keymap configured in `/etc/vconsole.conf`. It can be used very simply for this purpose:

    # loadkeys keymap

See `man 1 loadkeys` details.

## Adjusting typematic delay and rate

The typematic delay indicates the amount of time (typically in miliseconds) a key needs to be pressed in order for the repeating process to begin. After the repeating process has been triggered, the character will be repeated with a certain frequency (usually given in Hz) specified by the typematic rate. These values can be changed using the kbdrate command. Note that the typematic delay in the virtual console is different from the typematic delay in Xorg.

    # kbdrate [-d delay] [-r rate]

For example to set a typematic delay to 200ms and a typematic rate to 30Hz, use the following command:

    # kbdrate -d 200 -r 30

Issuing the command without specifying the delay and rate will reset the typematic values to their respective defaults; a delay of 250ms and a rate of 11Hz:

    # kbdrate

### Systemd service

A systemd service can be used to set the keyboard rate. For example

    /etc/systemd/system/kbdrate.service

    [Unit]
    Description=Keyboard repeat rate in tty.

    [Service]
    Type=simple
    RemainAfterExit=yes
    StandardInput=tty
    StandardOutput=tty
    ExecStart=/usr/bin/kbdrate -s -d 450 -r 60

    [Install]
    WantedBy=multi-user.target

Then start/enable the `kbdrate.service` systemd service.

Category:

- Keyboards