Read barcodes from input-event (linux, c)
I have a small program that read barcodes from /dev/input/event4. This is the code: #include <sys/file.h> #include <stdio.h> #include <string.h> #include <linux/input.h> int main (int argc, char *argv[]) { struct input_event ev; int fd, rd; //Open Device if ((fd = open ("/dev/input/event4", O_RDONLY|O_NONBLOCK)) == -1){ printf ("not a vaild device.\n"); return -1; } while (1){ memset((void*)&ev, 0, sizeof(ev)); rd = read (fd, (void*)&ev, sizeof(ev)); if (rd <= 0){ printf ("rd: %d\n", rd); sleep(1); } if(rd>0 && ev.value==0 && ev.type==1){ printf("type: %d, code: %d, value: %d, rd: %d\n", ev