Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <linux/input.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. int fd;
  11. struct input_event ev;
  12.  
  13. fd = open("/dev/input/event4", O_RDONLY);
  14. if (fd < 0)
  15. {
  16. perror("Cannot open file");
  17. return 1;
  18. }
  19.  
  20. while(1)
  21. {
  22. if (read(fd, &ev, sizeof(struct input_event)) < 0)
  23. {
  24. perror("Cannot read");
  25. return 1;
  26. }
  27. if(ev.type== EV_KEY) {
  28. printf("Eventtype: %d\n"
  29. "\tcode: %d\n"
  30. "\tValue: %d\n" , ev.type, ev.code, ev.value);
  31. fflush(stdout);
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement