ChumbyLurker wrote:The structure is defined in include/linux/input.h. It is, I believe, a 128-bit structure. You can ignore the first 32 bits, as it's just timestamp information. The next 16 bits is the type, which for the keyboard will likely be EV_KEY (0x01). The next 16 bits is the key, and will contain a VGA keycode. The last 32-bits should be a 1 or a 0.
What are the last 32 bits for? 32 + 16 + 16 + 32 = 96. According to the C structure that you linked to, sizeof(input_event) depends on sizeof(long) because of the timestamp. What is sizeof(long) on chumby? Assuming it is 4 bytes, that would make the timestamp 64 bits, and at least on my keyboard a 64+16+16+32=128 bit event size makes the most sense.
Here is a hexdump of me pressing one key:
chumby# hexdump /dev/input/by-id/*-kbd
hexdump 1.01
/dev/input/by-id/usb-Mitsumi_Electric_Apple_Extended_USB_Keyboard-event-kbd
00000000: 999a9a4c f52c0400 01002f00 01000000 ...L.,..../.....
00000010: 999a9a4c 132d0400 00000000 00000000 ...L.-..........
00000020: 999a9a4c 8c400600 01002f00 00000000 ...L.@..../.....
00000030: 999a9a4c 8c400600 00000000 00000000 ...L.@..........
512 bits are being recorded with each press. I think that each group of 128 bits is a separate keypress because they look so similar.
I wrote a ruby script to help figure out what is going on:
f = File.open '/dev/input/event1', 'r'
loop do
s = f.read(16).unpack('a8SSl')
p [s[1], s[2].to_s(16), s[3]]
end
Every time a 16 bytes is read from /dev/input/event1, this script prints out all fields but the timestamp. Here is the output from me pressing the "D" key once:
[1, "20", 1]
[0, "0", 0]
[1, "20", 0]
[0, "0", 0]
I don't know what the all-0 lines are for, but it seems that every time I press a key, two relevant events are read, one with a 1 for the last field and one with a 0. This probably means "key down" and "key up", respectively.
Am I correct? What is type 0x00? Also, it would make chumby development much easier if /dev/tty0 didn't buffer lines.