#include <stdint.h>
#include <linux/input.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#ifndef EV_SYN
#define EV_SYN 0
#endif
int main (int argc, char **argv)
{
int fd, rd, i, j, k;
struct input_event ev[64];
if (argc < 2) {
printf("Usage: evtest /dev/input/eventX\n");
printf("Where X = input device number\n");
printf("If X is 1, keypad, else if X is 2, touchpad\n");
return 1;
}
if ((fd = open(argv[argc - 1], O_RDONLY)) < 0) {
perror("evtest");
return 1;
}
printf("Testing ... (interrupt to exit)\n");
while (1) {
rd = read(fd, ev, sizeof(struct input_event) * 64);
if (rd < (int) sizeof(struct input_event)) {
printf("yyy\n");
perror("\nevtest: error reading");
return 1;
}
for (i = 0; i < rd / sizeof(struct input_event); i++)
{
if(ev[i].type==EV_KEY)
{
printf("Keypad Event: time %ld.%06ld, code %d , value %d(%s)\n",
ev[i].time.tv_sec, ev[i].time.tv_usec,
ev[i].code,
ev[i].value, ev[i].value ? "Down keypad" : "Up keypad");
}
else if(ev[i].type==EV_ABS)
{
switch(ev[i].value)
{
case 0:
printf("Touch Event: time %ld.%06ld, code %d , value %d(release)\n",
ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].code, ev[i].value);
break;
case 4095:
printf("Touch Event: time %ld.%06ld, code %d , value %d(press)\n",
ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].code, ev[i].value);
break;
default :
printf("Touch Event: time %ld.%06ld, code %d (%s), value %d\n",
ev[i].time.tv_sec, ev[i].time.tv_usec,
ev[i].code, ev[i].code ? "Y" : "X",
ev[i].value);
}
}
}
}
}