📄 test.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <errno.h>
int main(void)
{
int key;
int kpfd;
kpfd = open("/dev/Keypad", 0);
if(kpfd < 0)
{
perror("keypad");
exit(-1);
}
while(1)
{
fd_set kk;
int ret;
FD_ZERO(&kk);//将指定文件描述符集清空
FD_SET(kpfd, &kk);// 在文件描述符集合中增加一个新的文件描述符
ret = select(kpfd +1, &kk, NULL, NULL, NULL);//等待文件描述符
if(ret < 0)
{
perror("select");
exit (-1);
}
else if(ret == 0)
{
perror("timeout");
}
else if(FD_ISSET(kpfd, &kk))//判定某个描述符是否属于某个描述符集
{
ret = read(kpfd, &key, sizeof key);
if(ret <= 0)
{
perror("read");
continue;
}
else
printf("The key 0x%x is press\n", key);
}
}
close(kpfd);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -