问题
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!
回答1:
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):
timeis the timestamp, it returns the time at which the event happened.typeis for exampleEV_RELfor relative moment,EV_KEYfor a keypress or release. More types are defined in include/linux/input-event-codes.h.codeis event code, for exampleREL_XorKEY_BACKSPACE, again a complete list is in include/linux/input-event-codes.h.valueis the value the event carries. Either a relative change forEV_REL, absolute new value forEV_ABS(joysticks ...), or0forEV_KEYfor release,1for keypress and2for autorepeat.
For guides and example code, do a web search for "linux kernel" "input subsystem".
来源:https://stackoverflow.com/questions/16695432/input-event-structure-description-from-linux-input-h