input_event structure description (from linux/input.h)

SP5RFD picture SP5RFD · May 22, 2013 · Viewed 36k times · Source

Can someone please tell me what are the properties of the datatypes used by the input_event structure?

It is defined as follows in the input.h file:

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

but there are no other descriptions! Even googling gave me nothing interesting.

The only thing I know is that time gives seconds or miliseconds from epoch and value gives code of pressed button. But even value of value property isn't really clear for me. In my program every keystroke generates six events. Following events are response for pressing ENTER key:

type=4,code=4,value=458792
type=1,code=28,value=1
type=0,code=0,value=0
type=4,code=4,value=458792
type=1,code=28,value=0
type=0,code=0,value=0 

and those are for a letter:

type=4,code=4,value=458756
type=1,code=30,value=1
type=0,code=0,value=0
atype=4,code=4,value=458756
type=1,code=30,value=0
type=0,code=0,value=0

I would like to decode value to the real letter, but I don't understand the meaning of the properties.

Please help!

Answer

Nominal Animal picture Nominal Animal · May 22, 2013

The struct input_event is, among others, defined in include/linux/input.h.


From 5. Event interface in Linux kernel Documentation/input/input.txt (and modified to provide the correct header file names):

  • time is the timestamp, it returns the time at which the event happened.

  • type is for example EV_REL for relative moment, EV_KEY for a keypress or release. More types are defined in include/linux/input-event-codes.h.

  • code is event code, for example REL_X or KEY_BACKSPACE, again a complete list is in include/linux/input-event-codes.h.

  • value is the value the event carries. Either a relative change for EV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for keypress and 2 for autorepeat.

For guides and example code, do a web search for "linux kernel" "input subsystem".