input_event结构体
输入设备每次数据格式都是特定的,上报数据格式都是按照如下结构体进行上报的:
struct input_event {
struct timeval time; //时间戳,大小是2个long
__u16 type; //输入事件类型,2个字节
__u16 code; //键码,意义随type的不同而不同
__s32 value; //键值,意义随type和code的不同而不同
};
如: hexdump命令查看上报的数据,每一笔都是规范的
hexdump
序号 | time | type | code | value |
---|---|---|---|---|
0000000 | 823a 50f9 0000 0000 | d2f9 | 0006 | 0000 0000 |
type的常见值
#define EV_SYN 0x00 //同步事件,所有设备都必须要支持,表示一组数据上报完毕。
#define EV_KEY 0x01 //键盘或者按键,表示按键事件
#define EV_REL 0x02 //鼠标设备,表示一个相对的光标位置结果
#define EV_ABS 0x03 //绝对坐标事件,如手写板,触摸屏
#define EV_LED 0x11 //LED灯设备事件,标准键盘上的LED灯
#define EV_SND 0x12 //蜂鸣器,输入声音 ,标准键盘上的有时候触发蜂鸣器事件
#define EV_REP 0x14 //支持自动重复上报事件,如按下不放,会周期性上报一次按键事件。
code常见值
根据type的不同而含义不同。
如:type是EV_KEY表示本次数据是按键事件的数据,则code 是表示具体哪一个键,按键键值,
如:type是EV_ABS表示本次数据是绝对事件的数据,则code 是表示具体哪一个轴(x,y,z….)
常见值:
对于EV_KEY 事件:
#define KEY_RESERVED 0
#define KEY_ESC 1
#define KEY_1 2
#define KEY_2 3
……
#define KEY_0 11
…
#define KEY_TAB 15
#define KEY_Q 16
#define KEY_W 17
#define KEY_E 18
…
#define KEY_LEFTSHIFT 42
……
#define KEY_LEFTALT 56
#define KEY_SPACE 57
#define KEY_CAPSLOCK 58
#define KEY_F1 59
#define KEY_F2 60
#define KEY_F3 61
#define KEY_F4 62
……
对于非标准的按键值:
#define BTN_0 0x100
#define BTN_1 0x101
#define BTN_2 0x102
#define BTN_3 0x103
#define BTN_4 0x104
#define BTN_5 0x105
#define BTN_6 0x106
#define BTN_7 0x107
#define BTN_8 0x108
#define BTN_9 0x109
对于相对事件(EV_REL),内核支持的code值(子事件):
#define REL_X 0x00 //相对事件X轴子事件
#define REL_Y 0x01 //相对事件Y轴子事件
……
#define REL_WHEEL 0x08 //相对事件滚轮子事件
……
对于鼠标:
#define BTN_MOUSE 0x110
#define BTN_LEFT 0x110 //左键
#define BTN_RIGHT 0x111 //右键
#define BTN_MIDDLE 0x112 //中键
#define BTN_SIDE 0x113
#define BTN_EXTRA 0x114
#define BTN_FORWARD 0x115 //前进
#define BTN_BACK 0x116 //后退
#define BTN_TASK 0x117
对于绝对事件(EV_ABS事件)内核支持的code值(子事件):
以触摸屏为例子,对于单点触摸屏有以下事件(不带MT ):
#define ABS_X 0x00 //绝对事件X轴子事件
#define ABS_Y 0x01 //绝对事件Y轴子事件
……
#define ABS_PRESSURE 0x18 //绝对事件压力事件
#define ABS_DISTANCE 0x19 //绝对事件距离事件
以下带MT事件是多点触摸屏专用事件,单点触摸屏不能使用:
#define ABS_MT_SLOT 0x2f /* MT slot being modified */
#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */
#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */
#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */
#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */
#define ABS_MT_POSITION_X 0x35 /* Center X touch position */
#define ABS_MT_POSITION_Y 0x36 /* Center Y touch position */
#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */
#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */
#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */
#define ABS_MT_DISTANCE 0x3b /* Contact hover distance */
#define ABS_MT_TOOL_X 0x3c /* Center X tool position */
#define ABS_MT_TOOL_Y 0x3d /* Center Y tool position */
如:type是EV_ABS表示本次数据是绝对事件的数据,则code 是表示具体哪一个轴(x,y,z….),value表示code表示轴具体坐标数值.
value常见值
value:根据type, code的不同而含义不同,对type,code细化。
如:type是EV_KEY表示本次数据是按键事件的数据,则code 是表示具体哪一个键,比如是Q键,则value就是KEY_Q,也就是16;
按键键值,value表示按键的状态,1表示按键,0表示松开。