#include #include #include #include #include #include #include int main(int argc, char *argv[]) { int fd = -1,yalv=0,version=0,i=0; char name[256]= "Unknown", uniq[256]=""; char atiname[]="X10 Wireless Technology Inc USB Receiver"; /* how many bytes were read */ size_t rb; /* the events (up to 64 at once) */ struct input_event ev[64]; char eventpathname[]="/dev/input/event00"; while(i!=32) { sprintf(eventpathname,"/dev/input/event%i",i); if ((fd = open(eventpathname, O_RDONLY)) < 0) { perror("evdev open"); ++i; continue; } if(ioctl(fd, EVIOCGNAME(sizeof(name)), name) < 0) { perror("evdev ioctl"); } printf("The device on %s says its name is %s\n",eventpathname, name); if(!strcmp(name,atiname)) break; else close(fd); ++i; } if(i==32) { fprintf(stderr,"No ATI Remote found\n"); exit(-1); } /* ioctl() accesses the underlying driver */ if (ioctl(fd, EVIOCGVERSION, &version)) { perror("evdev ioctl"); } /* the EVIOCGVERSION ioctl() returns an int */ /* so we unpack it and display it */ printf("evdev driver version is %d.%d.%d\n", version >> 16, (version >> 8) & 0xff, version & 0xff); #if 0 if(ioctl(fd, EVIOCGUNIQ(sizeof(uniq)), uniq) < 0) { perror("event ioctl"); } printf("The device on %s says its identity is %s\n", argv[1], uniq); #endif while(1) { rb=read(fd,ev,sizeof(struct input_event)*64); if (rb < (int) sizeof(struct input_event)) { perror("evtest: short read"); exit (1); } for (yalv = 0; yalv < (int) (rb / sizeof(struct input_event)); yalv++) { if (EV_KEY == ev[yalv].type) printf("%ld.%06ld ", ev[yalv].time.tv_sec, ev[yalv].time.tv_usec); printf("type %d code %d value %d\n", ev[yalv].type, ev[yalv].code, ev[yalv].value); } } close(fd); }