/******************************************************************** linux 读取input输入设备demo* 说明:* 本文主要是解读以前同事写的input设备的一个demo程序。** 2016-3-24 深圳 南山平山村 曾剑锋******************************************************************/#include
#include
#include
#include
#include
{int fd; struct input_event ev;// 判断参数if (argc <2) {printf("Usage: %s \n", argv[0]);return 0;}// 打开设备fd &#61; open(argv[1], O_RDWR);if (fd <0) {printf("open %s", argv[1]);fflush(stdout);perror(" ");return 0;}// 循环读取while(1) {// 读取数据read(fd, &ev, sizeof(struct input_event));// 打印当前触发类型printf("ev &#61;&#61; %x \n",ev.type );
switch(ev.type) {case EV_SYN:printf("-------------------------\n"); break;// 按键case EV_KEY:printf("key down / up: %d \n",ev.code ); break;// 鼠标case EV_REL:printf("mouse: "); if (ev.code &#61;&#61; REL_X) {printf(" x -- %d\n", ev.value);} else if (ev.code &#61;&#61; REL_Y) {printf(" y -- %d\n", ev.value);}break;// 触摸屏case EV_ABS:printf("ts: "); if(ev.code &#61;&#61; ABS_X) {printf(" x -- %d\n", ev.value);} else if (ev.code &#61;&#61; ABS_Y) {printf(" y -- %d\n", ev.value);} else if (ev.code &#61;&#61; ABS_PRESSURE) {printf(" pressure: %d\n", ev.value);}break;} }close(fd);return 0;
}