LinuxCommandLibrary

setkeycodes

Remap scancodes to keycodes

SYNOPSIS

setkeycodes scancode1 keycode1 [scancode2 keycode2 ...]

PARAMETERS

scancode
    The hexadecimal scancode to remap. This is the hardware signal sent by the keyboard.

keycode
    The keycode to assign to the given scancode. This is the software identifier the OS uses for the key.

DESCRIPTION

The `setkeycodes` command in Linux is used to modify the mapping between keyboard scancodes (hardware-level signals) and keycodes (software-level identifiers). This allows you to customize keyboard behavior, especially useful when dealing with non-standard keyboards or fixing incorrect mappings. You provide `setkeycodes` with pairs of hexadecimal scancodes and corresponding keycodes. The changes made by `setkeycodes` are typically not persistent across reboots unless you configure the system to load the custom keymap. This command is particularly useful for addressing issues where keys are not recognized or produce incorrect characters. It provides a low-level method for keyboard remapping, influencing how the operating system interprets key presses.

CAVEATS

Changes made using `setkeycodes` are volatile and will be lost upon reboot. You need to configure a mechanism (e.g., using udev rules, rc.local or systemd startup scripts) to apply the changes persistently.
Using the wrong keycodes can make your keyboard unusable.

FINDING SCANCODES

You can use the `showkey -s` command to determine the scancode generated by a particular key. Note that you need to be running the command in a virtual console (not an X terminal).

PERSISTENCE

To make the remapping permanent, consider creating a udev rule. This allows you to associate the scancode/keycode mapping with a specific keyboard and load it during system startup.

EXAMPLE

Example
`setkeycodes 70 108`
Assigns keycode 108 (KEY_COMPOSE) to the scancode 0x70.

HISTORY

The `setkeycodes` command has been present in Linux systems for a long time, serving as a low-level tool for keyboard customization. It was more commonly used in earlier systems before the widespread adoption of more user-friendly keyboard configuration tools.

SEE ALSO

Copied to clipboard