系统 CentOS 内核 2.6 鼠标:usb 2.0
鼠标对应的设备文件是 /dev/input/event1
在linux 下,执行如下的操作,然后移动鼠标会得到哪下的数据:
[root@bogon input]# cat /dev/input/event1
(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�(�
读取鼠标,显示:
程序如下:
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <linux/input.h>
- #define MOUSEFILE "/dev/input/event1"
- int main()
- {
- int fd;
- struct input_event ie;
- if((fd = open(MOUSEFILE, O_RDONLY)) == -1)
- {
- perror("opening device");
- exit(EXIT_FAILURE);
- }
- while(read(fd, &ie, sizeof(struct input_event)))
- {
- printf("time %ld.%06ld\ttype %d\tcode %d\tvalue %d\n",
- ie.time.tv_sec, ie.time.tv_usec, ie.type, ie.code, ie.value);
- }
- return 0;
- }