热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

linux读取input输入设备demo

********************************************************************linux读取input输入设备demo*说

/******************************************************************** linux 读取input输入设备demo* 说明:* 本文主要是解读以前同事写的input设备的一个demo程序。** 2016-3-24 深圳 南山平山村 曾剑锋******************************************************************/#include
#include

#include

#include

#include
int main(int argc, char **argv)
{
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;
}

 

转:https://www.cnblogs.com/zengjfgit/p/5314984.html



推荐阅读
author-avatar
mobiledu2502885111
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有