/*点击鼠标左右键和滑动,确定其输入值*//*环境:ubuntu 10.10*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/poll.h>
#include <linux/input.h>
#define USB_MOUSE ("/dev/input/mouse0")
struct pollfd mypoll;
int main(int argc, char *argv[])
{
int mouseFd;
struct input_event buff;
if ((mouseFd = open("/dev/input/mouse0", O_RDONLY)) == -1) {
printf("Failed to open /dev/input/mouse0/n");
return -1;
}
mypoll.fd = mouseFd;
mypoll.events = POLLIN;
while(1)
{
if(poll(&mypoll, 1, 10) > 0)
{
printf("one time*\n");
printf("****\n");
unsigned char data[4] ={0};
usleep(50000);
read(mouseFd, data, 4);
printf("mouse data=%02x\n%02x\n%02x\n%02x\n", data[0],data[1], data[2], data[3]);
printf("**************************\n");
}
}
close(mouseFd);
return 0;
}
说明:
/*data的数据格式:
data0:00xx 1xxx ----低三位是按键值---左中右分别为01 02 04, 第4/5位分别代表x、y移动方向,右上方x/y>0,左下方xy<0
data1:取值范围-127~127,代表x轴移动偏移量
data2:取值范围-127~127,代表y轴移动偏移量
*/