Linux C编程连载(2)-鼠标控制

来源:互联网 发布:在线ftp源码 编辑:程序博客网 时间:2024/05/17 06:10
【代码清单】 
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/types.h>#include <fcntl.h>#include <time.h>#include <errno.h>int main(void){int fd,retval;char buf[6];fd_set readfds,tmp_readfds;struct timeval tv;if((fd=open("/dev/input/mice",O_RDONLY|O_NONBLOCK))<0){printf("Fail to open /dev/input/mice!\n");return -1;}printf("Open /dev/input/mice success!\n");tv.tv_sec=5;tv.tv_usec=0;FD_ZERO(&readfds);FD_SET(fd,&readfds);FD_SET(0,&readfds);while(FD_ISSET(fd,&readfds)){tmp_readfds=readfds;retval=select(fd+1,&readfds,NULL,NULL,&tv);printf("retval is %d.\n",&retval);switch(retval){case -1:{printf("Select error\n");return -1;}break;case 0:{printf("Time out\n");return -1;}break;default:{printf("Select OK!\n");if(read(fd,buf,sizeof(buf))<=0){printf("Fail to read!\n");continue;}printf("Button type is %d, x=%d ,y=%d\n",buf[0]&0x07,buf[1],buf[2]);}break;}//end of switch}//end of whileclose(fd);return 0;}


 

转载请标明出处,仅供学习交流,勿用于商业目的

Copyright @ http://blog.csdn.net/tandesir

 

 

原创粉丝点击