Keyboard devices

When writing keyboard device modules, keep in mind that the protocol/filter layers will expect make-and-break scan codes indicating when a key is pressed down and released. The easiest thing to do is to map the scan codes your device sends to the standard PC scan codes. This way you won't have to make any filter-layer changes — it will all just work like a normal PC keyboard. Standard PC scan codes are available in any PC hardware book.

When passing up a struct packet_kbd to the filter layer, all you need to do is:

  1. Fill in the key_scan field of the struct _keyboard_data with the scan code.
  2. Fill in the flags field with KEY_SCAN_VALID.

The keyboard filter layer will read in a keyboard definition file and interpret the scan codes it receives based on the contents of this file.

You shouldn't have to play around with these mapping files very much if you map your scan codes appropriately. The only place where you might need to modify these files is if your keyboard has special keys. In this case, you would start with a standard definition file (e.g. en_US_101.kdef), and add your unique scan codes.

When the driver starts up and initializes the keyboard filter module, the module will try to load in a mapping definition file. It uses the following algorithm to look for the file:

  1. The module tries to open the keyboard configuration file /etc/system/trap/.KEYBOARD. If this file exists, the module just reads the keyboard filename from it.
  2. If the keyboard mapping filename is empty, the module tries to take it from the KBD environment variable.
  3. If the keyboard mapping filename is still empty, the module assigns the standard US keyboard definition file (en_US_101.kbd) to it.