input_event 结构描述(来自 linux/input.h)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16695432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
input_event structure description (from linux/input.h)
提问by SP5RFD
Can someone please tell me what are the properties of the datatypes used by the input_event structure?
有人能告诉我 input_event 结构使用的数据类型的属性是什么吗?
It is defined as follows in the input.h file:
在 input.h 文件中定义如下:
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:
我唯一知道的是time
从纪元给出秒或毫秒,并value
给出按下按钮的代码。但即使是value
财产的价值对我来说也不是很清楚。在我的程序中,每次击键都会产生六个事件。以下事件是按 ENTER 键的响应:
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:
这些是a
信件:
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.
我想将 value 解码为真正的字母,但我不明白这些属性的含义。
Please help!
请帮忙!
采纳答案by Nominal Animal
The struct input_event
is, among others, defined in include/linux/input.h.
的struct input_event
是,在其他中,定义在包括/ LINUX / input.h。
From 5. Event interfacein Linux kernel Documentation/input/input.txt(and modified to provide the correct header file names):
来自Linux内核Documentation/input/input.txt中的5.事件接口(并修改为提供正确的头文件名):
time
is the timestamp, it returns the time at which the event happened.type
is for exampleEV_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 exampleREL_X
orKEY_BACKSPACE
, again a complete list is in include/linux/input-event-codes.h.value
is the value the event carries. Either a relative change forEV_REL
, absolute new value forEV_ABS
(joysticks ...), or0
forEV_KEY
for release,1
for keypress and2
for autorepeat.
time
是时间戳,它返回事件发生的时间。type
是例如EV_REL
相对时刻,EV_KEY
按键或释放。更多类型在include/linux/input-event-codes.h 中定义。code
是事件代码,例如REL_X
或KEY_BACKSPACE
,完整列表在include/linux/input-event-codes.h 中。value
是事件携带的价值。无论是相对变化EV_REL
的,绝对的新价值EV_ABS
(操纵杆...),或0
用于EV_KEY
发布,1
对于按键和2
用于自动重复。
For guides and example code, do a web search for "linux kernel" "input subsystem"
.
有关指南和示例代码,请在网络上搜索"linux kernel" "input subsystem"
.