2013-05-22 52 views
16

有人能告诉我什么是由input_event结构中使用的数据类型的属性?input_event结构描述(从Linux/input.h)

它被定义为在input.h文件如下:

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

,但有没有其他的说明!即使使用谷歌搜索,也没有什么有趣的。

我知道的唯一的事情是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 

,而这些都是为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 

我想值进行解码,以真正的信,但我不明白的意思属性。

请帮忙!

回答

33

struct input_event是,除其他外,include/linux/input.h定义。


从Linux内核5.事件接口Documentation/input/input.txt(和修改,以提供正确的头文件名):

  • 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(游戏杆...),或0EV_KEY为 释放,1的按键和2用于自动重复绝对新的价值。

有关指南和示例代码,请执行网页搜索"linux kernel" "input subsystem"