#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
int fd = -1;
char buf[100];
int flag = -1;
int ret = -1;
fd = open("/dev/input/mouse0", O_RDONLY | O_NONBLOCK);
if(fd < 0)
{
perror("open");
return -1;
}
flag = fcntl(0, F_GETFL);
flag |= O_NONBLOCK;
fcntl(0, F_SETFL, flag);
while(1)
{
//读鼠标
memset(buf, 0, sizeof(buf));
ret = read(fd, buf, 5);
if(ret > 0)
{
printf("鼠标读出的内容是:[%s]\n", buf);
}
//读键盘
memset(buf, 0, sizeof(buf));
ret = read(0, buf, 5);
if(ret > 0)
{
printf("键盘读出的内容是:[%s]\n", buf);
}
}
return 0;
}