Linux 下鼠标对应的文件

来源:互联网 发布:java自行车是高端的吗 编辑:程序博客网 时间:2024/05/19 22:50

系统 CentOS  内核 2.6  鼠标:usb 2.0

鼠标对应的设备文件是  /dev/input/event1


在linux 下,执行如下的操作,然后移动鼠标会得到哪下的数据:

[root@bogon input]# cat /dev/input/event1
(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�

读取鼠标,显示:

程序如下:

[cpp] view plaincopy在CODE上查看代码片派生到我的代码片
  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3. #include <fcntl.h>  
  4. #include <unistd.h>  
  5. #include <linux/input.h>  
  6.   
  7. #define MOUSEFILE "/dev/input/event1"  
  8.   
  9.   
  10. int main()  
  11. {  
  12.    int fd;  
  13.    struct input_event ie;  
  14.   
  15.    if((fd = open(MOUSEFILE, O_RDONLY)) == -1)  
  16.    {  
  17.        perror("opening device");  
  18.        exit(EXIT_FAILURE);  
  19.    }  
  20.   
  21.   
  22.    while(read(fd, &ie, sizeof(struct input_event)))  
  23.    {  
  24.         printf("time %ld.%06ld\ttype %d\tcode %d\tvalue %d\n",  
  25.         ie.time.tv_sec, ie.time.tv_usec, ie.type, ie.code, ie.value);  
  26.     }  
  27.   
  28.    return 0;  
  29. }  
0 0
原创粉丝点击