http://blog.csdn.net/liang12360640/article/details/50350648
来源:互联网 发布:旅游市场数据 编辑:程序博客网 时间:2024/06/06 01:02
linux c/c++监听鼠标或键盘事件
1、输入设备在文件/proc/bus/input/devices中,如:
其中Handlers=kbd event2,说明其值可以在/dev/input文件夹的event2文件中读到,文件夹内容:
2、可能是受虚拟机影响,鼠标事件并不能从mousex系列的文件中读到,而是event3,键盘是event2,完整程序如下:
- #include <stdio.h>
- #include <linux/input.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- int main(int argc,char** argv)
- {
- int keys_fd;
- char ret[2];
- struct input_event t;
- keys_fd=open(argv[1],O_RDONLY);
- if(keys_fd<=0)
- {
- printf("error\n");
- return -1;
- }
- while(1)
- {
- read(keys_fd,&t,sizeof(struct input_event));
- if(t.type==1)
- printf("key %i state %i \n",t.code,t.value);
- }
- close(keys_fd);
- return 0;
- }
3、键盘事件效果:
0 0
- http://blog.csdn.net/liang12360640/article/details/50350648
- http://blog.csdn.net/IBM_hoojo/article/details/5688947
- http://blog.csdn.net/chenlaic/article/details/6143235
- http://blog.csdn.net/eaglewood2005/article/details/4335052
- http://blog.csdn.net/mchp/article/details/3995970
- http://blog.csdn.net/v_july_v/article/details/6015165
- http://blog.csdn.net/masterz/article/details/6232585
- http://blog.csdn.net/perfectpdl/article/details/6442847
- http://blog.csdn.net/eroswang/article/details/1967243
- http://blog.csdn.net/zhvsby/article/details/5986645
- http://blog.csdn.net/dz45693/article/details/6183645
- http://blog.csdn.net/david_lv/article/details/5798003
- http://blog.csdn.net/zxingchao2009/article/details/6299313
- http://blog.csdn.net/zhanxinhang/article/details/6783766
- http://blog.csdn.net/ruanruoshi/article/details/935510
- http://blog.csdn.net/yming0221/article/details/6538527
- http://blog.csdn.net/yming0221/article/details/6528490
- http://blog.csdn.net/yming0221/article/details/6704079
- 基于事件的时序控制
- Android中ArrayAdapt&SimpleAdapt的使用
- 3.C语言常用运算符
- Codeforces Round #345 (Div. 2)(B)暴力
- 【BZOJ1066】【SCOI2007】蜥蜴(网络流isap)
- http://blog.csdn.net/liang12360640/article/details/50350648
- Introduction to The Design and Analysis of Algorithms (1)
- NBUT 1655 木块拼接【想不明白】
- 在Activity里显示列表(ListView的布局)
- 链接
- ShellSort
- PKU1038 Bugs Integrated, Inc. 状压DP
- 集体智慧编程——神经网络预测点击率-Python实现
- 对于已知二叉树的中序遍历和后序遍历如何求二叉树的的前序遍历