测试代码:
#include <stdio.h>
#include <pthread.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define EV_KBD "/dev/input/event1"
void * func(void * argv)
{
static struct input_event ev_kbd;
int fd = open(EV_KBD,O_RDONLY);
while(1) {
read(fd, &ev_kbd, sizeof(ev_kbd));
printf("code:%d \n",ev_kbd.code);
}
return NULL;
}
int main()
{
pthread_t pid;
pthread_create(&pid, NULL, func, NULL);
pthread_join(pid, NULL);
return 0;
}