https://wiki.archlinux.org/api.php?action=feedcontributions&user=Spat&feedformat=atomArchWiki - User contributions [en]2024-03-29T09:51:06ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Map_scancodes_to_keycodes&diff=184908Map scancodes to keycodes2012-02-15T23:41:11Z<p>Spat: </p>
<hr />
<div>{{i18n|Map scancodes to keycodes}}<br />
[[Category:Input devices (English)]]<br />
<br />
{{stub}}<br />
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.<br />
<br />
''See [[Extra Keyboard Keys]] for more information.''<br />
<br />
There are three ways of mapping scancodes to keycodes:<br />
*Using [[udev]]<br />
*Using the kernel tool <code>setkeycodes</code><br />
<br />
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 (as does HAL, but it is now deprecated). 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.<br />
<br />
=Using udev=<br />
First, you need to create a keymap file that udev will recognise. Some examples can be found in /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<br />
# /lib/udev/keymap -i input/eventX<br />
and pressing the relevant keys. Replace input/eventX with your keyboard device, which can be found by running<br />
$ /lib/udev/findkeyboards<br />
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 [http://hal.freedesktop.org/quirk/quirk-keymap-list.txt here].<br />
<br />
Once you have a keymap, you need to tell udev to use it. This can be done with a [[Udev#About udev rules|udev rule]]. Here is a simple example:<br />
SUBSYSTEM=="input", ATTRS{name}=="AT Translated Set 2 keyboard", RUN+="/lib/udev/keymap input/$name /path/to/keymap"<br />
If you place the keymap file in /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:<br />
# /lib/udev/keymap input/eventX /path/to/keymap<br />
<br />
=Using the kernel tool <code>setkeycodes</code>=<br />
''See the detailed article: [[setkeycodes]].''</div>Spat