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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:58:37  来源:igfitidea点击:

input_event structure description (from linux/input.h)

c++clinuxinputstructure

提问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 timegives seconds or miliseconds from epoch and valuegives code of pressed button. But even value of valueproperty 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 aletter:

这些是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_eventis, 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.事件接口(并修改为提供正确的头文件名):

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

  • typeis for example EV_RELfor relative moment, EV_KEYfor a keypress or release. More types are defined in include/linux/input-event-codes.h.

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

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

  • time是时间戳,它返回事件发生的时间。

  • type是例如EV_REL相对时刻,EV_KEY按键或释放。更多类型在include/linux/input-event-codes.h 中定义

  • code是事件代码,例如REL_XKEY_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".