📄 keytest.c
字号:
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
typedef struct {
unsigned short b;
unsigned short x;
unsigned short y;
unsigned short pad;
} POS;
main()
{
fd_set rfds;
struct timeval tv;
int retval;
POS pos;
int fileno;
int ts, maxfd;
int ret= 0,i ;
char number[10];
memset( number , 0, 10);
/*
ts = open("/dev/h3600_ts", O_RDONLY);
if (ts == -1) {
printf("open ts error\n");
return 0;
}
*/
fileno = open("./keynode",O_RDONLY);
if (fileno == -1) {
printf("open device key error!\n");
return 0;
}
for(i =0 ; i< 100;i++)
{
FD_ZERO(&rfds);
FD_SET(fileno, &rfds);
/* Wait up to five seconds. */
tv.tv_sec = 5;
tv.tv_usec = 0;
// FD_SET(ts, &rfds);
// maxfd =( (ts > fileno) ? ts : fileno);
maxfd = fileno;
retval = select(maxfd+1, &rfds, NULL, NULL, &tv);
/* Don't rely on the value of tv now! */
if (retval)
{
printf("Data is available now.\n");
if (FD_ISSET(fileno, &rfds))
{
if (read(fileno, &number, 1) == 0)
{
printf("key %d stroke\n", number[0]);
}
else
{
printf("read error\n");
}
}
/* if (FD_ISSET(ts, &rfds))
{
read(ts, &pos, sizeof(POS));
printf("touch panel\n");
}*/
}
else
printf("No data within five seconds.\n");
}
close(fileno);
close(ts);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -