key_test
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <linux/input.h>
#define INPUT_KEYBOARD "/dev/input/event1"
int main(int argc, char **argv)
{
int fd = -1, ret = -1;
struct input_event ev;
fd = open(argv[1] , O_RDONLY);
if(fd < 0) {
printf("open failed, error:%d\n", errno);
return -1;
}
while(1) {
memset(&ev, 0, sizeof(struct input_event));
ret = read(fd, &ev, sizeof(struct input_event));
if (ret != sizeof(struct input_event)) {
printf("read error, ret: %d\n", ret);
break;
}
if (ev.type == EV_KEY) {
printf("--------------------\n");
printf("type = %u.\n", ev.type);
printf("code = %u.\n", ev.code);
printf("value = %u.\n", ev.value);
}
}
close(fd);
return ret;
}