linux鼠标测试程序,Linux USB鼠标驱动注解及测试

五、应用层测试代码编写

在应用层编写测试鼠标的测试程序,在我的系统中,鼠标设备为/dev/input/event3. 测试代码如下:

/*

* usb_mouse_test.c

*by lht

*/

#include

#include

#include

#include

#include

int main (void)

{

int fd,i,count;

struct input_event ev_mouse[2];

fd = open ("/dev/input/event3",O_RDWR);

if (fd < 0) {

printf ("fd open failed\n");

exit(0);

}

printf ("\nmouse opened, fd=%d\n",fd);

while(1)

{

printf("...............................................\n");

count=read(fd, ev_mouse, sizeof(struct input_event));

for(i=0;i

{

printf("type=%d\n",ev_mouse[i].type);

if(EV_REL==ev_mouse[i].type)

{

printf("time:%ld.%d",ev_mouse[i].time.tv_sec,ev_mouse[i].time.tv_usec);

printf(" type:%d code:%d value:%d\n",ev_mouse[i].type,ev_mouse[i].code,ev_mouse[i].value);

}

if(EV_KEY==ev_mouse[i].type)

{

printf("time:%ld.%d",ev_mouse[i].time.tv_sec,ev_mouse[i].time.tv_usec);

printf(" type:%d code:%d value:%d\n",ev_mouse[i].type,ev_mouse[i].code,ev_mouse[i].value);

}

}

}

close (fd);

return 0;

}

运行结果如下:

562083de97a07521c242dbd8c5cb3ad6.png

根据type、code、value的值,可以判断出鼠标的状态,具体值参考include/linux/input.h0b1331709591d260c1c78e86d0c51c18.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值