SETKEYCODES(8)

๐Ÿ“ฆ
version 2.10.0 ยท 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

โœจ SETKEYCODES(8) โœจ

System Manager's Manual ๐ŸŒธ

๐Ÿ’– NAME ๐Ÿ’–

setkeycodes, okay so this one loads kernel scancode-to-keycode mapping table entries ๐ŸŽ€

๐Ÿ“ SYNOPSIS ๐Ÿ“

setkeycodes [options] scancode keycode ...

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

Okay bestie, so the setkeycodes command reads its arguments two at a time ๐Ÿ‘‘. Each pair is a scancode (written in hexadecimal) followed by a keycode (written in decimal). For every pair, it tells the kernel keyboard driver to map that scancode to that keycode โœจ. It's giving precision.

This command is only really useful for people with slightly unusual keyboards ๐Ÿ™ˆ. Like, if you have a few keys that send scancodes the kernel doesn't recognize, this is your moment ๐Ÿ’….

๐Ÿง  THEORY ๐Ÿง 

Okay so, every key press and key release on a usual PC keyboard sends a little series of scancodes ๐Ÿ”ฅ. (You can peek at those with showkey -s, see showkey(1) ๐Ÿ‘€.) The kernel reads that stream and turns it into a stream of keycodes, which are the key press and release events ๐Ÿ’œ. (You can see keycodes with showkey.)

Here's the tea. Apart from a few scancodes with special meaning, the Pause key's sequence, the shiftstate-related scancodes, and the key up/down bit, the stream is made of two flavors: unescaped scancodes xx (7 bits), and escaped scancodes e0 xx (8+7 bits) ๐ŸŒˆ. Each of these scancodes or scancode pairs can be given a matching keycode, anywhere in the range 1-127 ๐Ÿ“.

Let's say you've got a Macro key that sends e0 6f according to showkey(1). Then this command:

setkeycodes e06f 112

will assign keycode 112 to it ๐Ÿงš. After that, loadkeys(1) can be used to decide what the key actually does โœจ.

Heads up: some older kernels hardwire a low scancode range to the equivalent keycodes. If you try to remap those, setkeycodes will fail ๐Ÿ’€.

๐Ÿซง 2.6 KERNELS ๐Ÿซง

In 2.6 kernels, keycodes live in the range 1-255 instead of 1-127 ๐ŸŒธ. (Honestly, it might be safest to stick to 1-239 ๐Ÿซถ.)

Warning, bestie ๐Ÿ˜ญ: in 2.6 kernels, raw mode (aka scancode mode) is not very raw at all. The code that showkey -s returns will change after you use setkeycodes. That's a kernel bug, not you ๐Ÿ’…. See also showkey(1).

๐ŸŽ€ OPTIONS ๐ŸŽ€

  • -C, --console=DEV โ€” pick the console device you want to use ๐Ÿ–ฅ๏ธ
  • -V, --version โ€” shows you the version number ๐Ÿ”ข
  • -h, --help โ€” shows you the usage message ๐Ÿ“–

๐Ÿ› BUGS ๐Ÿ›

The keycodes of X have nothing to do with the ones in Linux, so no cap, they're not the same ๐Ÿ™ƒ. Some unusual keys can be made visible under Linux, but not under X ๐Ÿ˜ญ.

๐Ÿ”— SEE ALSO ๐Ÿ”—

dumpkeys(1), loadkeys(1), showkey(1), getkeycodes(8) ๐Ÿ’œ


Source: kbd, 24 October 2024. Stay iconic, bestie ๐ŸŒˆ๐Ÿ’–โœจ