Map scancodes to keycodes

From ArchWiki
Revision as of 09:43, 26 August 2013 by Lekensteyn (talk | contribs) (Using udev: Out-of-date since systemd 206)
Jump to: navigation, search

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Map scancodes to keycodes#)

scancodes are the lowest identification numbers for a key, they are from the kernel and are not used by applications that's why we have to map them to keycodes which correspond to functions.

See Extra Keyboard Keys for more information.

There are three ways of mapping scancodes to keycodes:

  • Using udev
  • Using the kernel tool setkeycodes

The preferred one is to use udev because it uses hardware information (which is a quite reliable source) to choose the keyboard model in a database. It means that if your keyboard model as been defined in the database, your keys are recognized "out of the box" and can be seen by Xorg. That's why by expanding the database you are helping the linux community and maybe someday we won't have to care about scancodes.

Using udev

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: Since systemd 206, the tools described here have been replaced by hwdb and the "keyboard" udev builtin (Discuss in Talk:Map scancodes to keycodes#)

First, you need to create a keymap file that udev will recognise. Some examples can be found in /usr/lib/udev/keymaps/, and you should use one of these if it works for your keyboard model. Otherwise, you need to create one yourself. The format of each line in a keymap is '<scancode> <keycode>'. You can work out <scancode> (looks like 0xXX) using:

# /usr/lib/udev/keymap -i input/eventX

and pressing the relevant keys. Replace input/eventX with your keyboard device, which can most of the times be found by running:

$ /usr/lib/udev/findkeyboards

If it is not correct, you have to try with other eventX devices. The choices for <keycode> are listed as KEY_<KEYCODE> in /usr/include/linux/input.h, but you need to change these to lower case and remove the KEY_ prefix (for example, KEY_PROG3 corresponds to prog3). A sorted list is available here.

Once you have a keymap, you need to tell udev to use it. This can be done with a udev rule. Here is a simple example:

SUBSYSTEM=="input", ATTRS{name}=="AT Translated Set 2 keyboard", RUN+="/usr/lib/udev/keymap input/$name /path/to/keymap"

If you place the keymap file in /usr/lib/udev/keymaps/, you can omit the full path. Now the keymap will be active the next time you restart. You can run the following command to activate it immediately:

# /usr/lib/udev/keymap input/eventX /path/to/keymap

For more information about keymaps and how to send them upstream, see /usr/share/doc/systemd/README.keymap.txt.

Using the kernel tool setkeycodes

See the detailed article: setkeycodes.