2008年11月6日 星期四

Linux Scancode set

摘錄自:
(1)http://gunnarwrobel.de/wiki/Linux-and-the-keyboard.html
(2)http://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html

The i8042 is usually set to translate key codes from scancode 2 to scancode 1.

Whatever the situation of your keyboard and its controller, the intention of the atkbd.c (in drivers/input/keyboard/atkdb.c) file is to map all weird scancodes to a standard key code that has a defined meaning for the kernel. So if you press the key in the upper left corner on your keyboard (usually labelled "Esc"), the kernel should always produce key code 1, whatever scancodes and translation are used by the keyboard.

The usual PC keyboards are capable of producing three sets of scancodes. Writing 0xf0 followed by 1, 2 or 3 to port 0x60 will put the keyboard in scancode mode 1, 2 or 3. Writing 0xf0 followed by 0 queries the mode, resulting in a scancode byte 43, 41 or 3f from the keyboard.

Set 1 contains the values that the XT keyboard (with only one set of scancodes) produced, with extensions for new keys. Someone decided that another numbering was more logical and invented scancode Set 2. However, it was realized that new scancodes would break old programs, so the keyboard output was fed to a 8042 microprocessor on the motherboard that could translate Set 2 back into Set 1. Indeed a smart construction. This is the default today. Finally there is the PS/2 version, Set 3, more regular, but used by almost nobody.

Sets 2 and 3 are designed to be translated by the 8042. Set 1 should not be translated.

Not all keyboards support all scancode sets. For example, my MyCom laptop only supports scancode Set 2, and its keyboard does not react at all when in mode 1 or 3.

沒有留言: