The user space interface
Every registered input device is represented by a /dev/input/event<X>
char device, from which we can read the event from the user space. An application reading this file will receive event packets in the struct input_event
format:
struct input_event { struct timeval time; __u16 type; __u16 code; __s32 value; }
Let's look at the meaning of each element in the structure:
time
is the timestamp. It returns the time at which the event happened.type
is the event type; for example,EV_KEY
for a key press or release,EV_REL
for a relative moment, orEV_ABS
for an absolute one. More types are defined ininclude/linux/input-event-codes.h
.code
is the event code; for example,REL_X
orKEY_BACKSPACE
. Again, a complete list is ininclude/linux/input-event-codes.h
.value
is the value that the event carries. For theEV_REL
event type, it carries the relative change. For anEV_ABS
(joysticks, and so on) event type, it contains the absolute new value. For theEV_KEY...