views:

19

answers:

2

I've been playing around with capturing the input from my keyboard device:

/dev/input/by-path/platform-i8042-serio-0-event-kbd 

for me, and I was wondering if there was any specification for what it returns, using

od -tx1 /dev/input/by-path/platform-i8042-serio-0-event-kbd 

to listen. I'm curious mostly due to the behavior of certain keys; the meta, arrow keys, numpad forward slash.

0520300 ac 9d 86 4c 6b 0f 04 00 04 00  04  00 (db) 00 00 00
0520320 ac 9d 86 4c 8c 0f 04 00 01 00 (7d) 00  00 00 00 00
0520340 ac 9d 86 4c 95 0f 04 00 00 00  00  00  00 00 00 00

Every other key I've looked at so far has the two bytes in parentheses as matching values, is there any reason these are special?

+1  A: 

Some keys have unusual scan codes...

From: http://www.beyondlogic.org/keyboard/keybrd.htm :

Now there's 101 keys and 8 bits make 256 different combinations, thus you only need to send one byte per key, right?

Nop. Unfortunately a handful of the keys found on your keyboard are extended keys, and thus require two scan code. These keys are preceded by a E0 (hex). But it doesn't stop at two scan codes either. How about E1,14,77,E1,F0,14,F0,77! Now that can't be a valid scan code? Wrong again. It's happens to be sent when you press the Pause/break key. Don't ask me why they have to make it so long! Maybe they were having a bad day or something?

phreakocious
+1  A: 

/dev/input/by-path/platform-i8042-serio-0-event-kbd is just a symlink to /dev/input/eventX event device file. Data can be read from event device files as

struct input_event {
    struct timeval time;
    __u16 type;
    __u16 code;
    __s32 value;
};

defined in /usr/include/linux/input.h.

Possible values of type are prefixed with EV_. Possible values of code depend on type. They are prefixed with KEY_ or BTN_ or REL_ or so on. Possible values of value depend on both type and code. For example for key-press events value equals 1 and for key-release events 0.

You can examine event data with:

evtest /dev/input/eventX

where X is the event device number of your keyboard (or any other event device). One key press or release normally emits three events (EV_MSC, EV_KEY and EV_SYN).

tuos