#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <linux/input.h>
#include <string.h>
int main(int argc, char **argv)
{
int fd;
int err;
int len;
struct input_event event;
if(argc < 2)
{
printf("Usage: %s <dev>\n",argv[0]);
return -1;
}
if(argc == 3 && !strcmp(argv[2],"noblock"))
fd = open(argv[1],O_RDWR | O_NONBLOCK);//O_NONBLOCK 表示非阻塞方式,即查询方式
else
fd = open(argv[1],O_RDWR);//默认是阻塞方式,即休眠方式
if (fd < 0)
{
printf("open %s err\n", argv[1]);
return -1;
}
while(1)
{
len = read(fd, &event, sizeof(event));
if(len == sizeof(event))
printf("get event: type = 0x%x, code = 0x%x, value = 0x%x \n",event.type,event.code,event.value);
else
printf("read err %d\n", len);
}
cl
07-查询和休眠方式获取输入设备状态
最新推荐文章于 2024-08-09 15:43:06 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)