Saturday, 8 August 2009

Input Utils - Tools to debug the /dev/input devices

The input-utils package are a bunch of tools for examining and interacting with the /dev/input/event* input devices. Sometimes one needs to figure out why certain key events don't work, or why they are mapped incorrectly - in which case input-utils are the tools to turn to.

To install on a Ubuntu system use:

sudo apt-get install input-utils

The first command that's of interest is lsinput - it dumps out all the input devices and the associated details about the device. This command need to be run with sudo, here is an example:

sudo lsinput
bustype : BUS_HOST
vendor : 0x0
product : 0x5
version : 0
name : "event0"
phys : "PNP0C0D/button/input0"
bits ev : EV_SYN EV_SW

bustype : BUS_HOST
vendor : 0x0
product : 0x1
version : 0
name : "event1"
phys : "PNP0C0C/button/input0"
bits ev : EV_SYN EV_KEY


One can then dump out the keyboard mapping of a particular event device using input-kyb by specifing the Nth device number:

sudo input-kbd 3
bustype : BUS_ADB
vendor : 0x1
product : 0x1
version : 256
name : "event3"
bits ev : EV_SYN EV_KEY EV_REL

bits: BTN_LEFT

Finally, one can observe input events using the input-events command. The following example watches events on input device 4 which just so happens to be the keyboard on my Dell Inspirion 6400 laptop:

sudo input-events 4
bustype : BUS_I8042
vendor : 0x1
product : 0x1
version : 43841
name : "event4"
phys : "isa0060/serio0/input0"

waiting for events
17:38:02.671577: EV_MSC code=4 value=28
17:38:02.671601: EV_KEY KEY_ENTER (0x1c) released
17:38:02.671606: EV_SYN code=0 value=0
17:38:04.107847: EV_MSC code=4 value=42
17:38:04.107872: EV_KEY KEY_LEFTSHIFT (0x2a) pressed
17:38:04.107877: EV_SYN code=0 value=0
17:38:04.202190: EV_MSC code=4 value=42
17:38:04.202215: EV_KEY KEY_LEFTSHIFT (0x2a) released
17:38:04.202221: EV_SYN code=0 value=0
17:38:06.052641: EV_MSC code=4 value=58
17:38:06.052666: EV_KEY KEY_CAPSLOCK (0x3a) pressed
17:38:06.052672: EV_SYN code=0 value=0
17:38:06.053025: EV_LED code=1 value=1
17:38:06.154324: EV_MSC code=4 value=58
17:38:06.154348: EV_KEY KEY_CAPSLOCK (0x3a) released
17:38:06.154354: EV_SYN code=0 value=0
17:38:09.378158: EV_MSC code=4 value=157
17:38:09.378183: EV_KEY KEY_RIGHTCTRL (0x61) pressed
17:38:09.378190: EV_SYN code=0 value=0
17:38:09.430852: EV_MSC code=4 value=157
17:38:09.430876: EV_KEY KEY_RIGHTCTRL (0x61) released
17:38:09.430882: EV_SYN code=0 value=0
timeout, quitting

With these tools one can debug a system to see if inputs generate the expected event codes and hence help sort out issues such as why hotkeys don't work or are mapped incorrectly.

To remap events, use the input-kbd command as follows:

1. Dump the mapping out to a file using input-kbd on the appropriate input device
2. Edit the mappings on the file using your preferred text editor
3. Load up the new mappings using input-kbd -f mappingfile devicenumber

..hopefully this helps fix some of those weird button/keyboard mapping issues.

No comments:

Post a Comment