LinuxCommandLibrary

loadkeys

Load keyboard translation tables

TLDR

Load a specific keyboard layout for the current console

$ sudo loadkeys [en|de|fi|dvorak|defkeymap|...]
copy

Load a default keymap
$ sudo loadkeys [[-d|--default]]
copy

Create a kernel source table
$ loadkeys [[-m|--mktable]]
copy

Create a binary keymap
$ loadkeys [[-b|--bkeymap]]
copy

Search and parse keymap without action
$ loadkeys [[-p|--parse]]
copy

Load the keymap suppressing all output
$ loadkeys [[-q|--quiet]]
copy

Set a keymap for a specific console
$ sudo loadkeys [[-C|--console]] [/dev/ttyN] [uk]
copy

Load a keymap from the specified file for the console
$ loadkeys [[-C|--console]] [/dev/ttyN] /[path/to/file]
copy

SYNOPSIS

loadkeys [OPTIONS] [KEYMAP-FILE]

PARAMETERS

KEYMAP-FILE
    Specifies the path to the keymap file to be loaded. If not provided, loadkeys will attempt to load a default keymap or search for a standard one.

-b, --bkeymap
    Dumps the current keymap in binary format to standard output. This format is not human-readable but can be reloaded faster by loadkeys.

-c, --clear
    Clears the current keymap, effectively disabling all custom key mappings and reverting to a basic default.

-d, --default
    Loads the default keyboard map (usually us.map.gz or similar) from the standard keymap directory.

-h, --help
    Displays a help message and exits.

-m, --mkeymap
    Dumps the current keymap in loadkeys format to standard output. This output can be used as a source for a new keymap file.

-q, --quiet
    Suppresses warnings and other verbose output, displaying only error messages.

-s, --script
    Dumps the current keymap in a script format, which can be useful for debugging or programmatic manipulation.

-u, --unicode
    Enables loading of Unicode keymaps. This is important for supporting a wide range of characters beyond traditional ASCII.

-v, --verbose
    Enables verbose output, showing more details about the keymap loading process.

-V, --version
    Displays version information and exits.

-w, --console=DEVICE
    Specifies the console device to operate on (e.g., /dev/console). By default, loadkeys attempts to determine the active console.

DESCRIPTION

The loadkeys command is used to change the kernel's keyboard translation table, often referred to as the 'keymap'. This keymap defines how physical key presses on the keyboard are interpreted and translated into characters or actions on the Linux console (TTYs). It's essential for configuring keyboard layouts specific to different languages (e.g., German, French, Spanish) or specialized layouts (e.g., Dvorak).

When executed, loadkeys reads a specified keymap file, which contains rules for mapping scancodes (raw input from the keyboard) to keycodes, and then keycodes to character outputs, function keys, or other special behaviors. This command is typically run during the system's boot process to set the desired keyboard layout for the console, but it can also be used interactively to temporarily switch layouts.

CAVEATS

loadkeys primarily affects the Linux console (TTYs) and generally does not affect graphical environments (like Xorg or Wayland). Graphical environments manage their own keyboard layouts, typically using utilities like setxkbmap.

Modifying system-wide keymaps usually requires root privileges. Loading an incorrect or corrupted keymap can make your console keyboard unusable, potentially requiring a reboot or access via SSH to fix.

KEYMAP FILES

Keymap files are plain text files that define the mapping between keyboard scancodes, keycodes, and the actions produced (characters, function keys, modifier states, etc.). They are typically found in directories like /usr/share/kbd/keymaps/. These files follow a specific syntax, allowing for complex mappings including dead keys for accents, compose sequences, and different shift states.

PERSISTENT CONFIGURATION

To ensure a specific keymap is loaded every time the system boots, loadkeys is usually invoked by system initialization scripts or services. On systems using `systemd`, the keymap is often configured via `systemd-vconsole-setup.service`, which reads settings from files like /etc/vconsole.conf. Other distributions might use `init.d` scripts or configuration files such as /etc/default/keyboard to specify the desired keymap.

HISTORY

loadkeys is part of the `kbd` package, which provides essential tools for managing the Linux console keyboard and fonts. Its core functionality of loading keyboard maps has been a fundamental part of the Linux console setup since its early days, ensuring multilingual and diverse keyboard support on command-line interfaces. While graphical environments have evolved separate keyboard configuration systems, loadkeys remains the authoritative tool for the text-based console.

SEE ALSO

dumpkeys(1), showkey(1), setxkbmap(1), kbd_mode(1), keymaps(5), console_codes(4)

Copied to clipboard