Guest User

Untitled

a guest
Jul 19th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. #include <linux/input.h>
  6.  
  7. // read events in a loop
  8. int main(int argc, char** argv)
  9. {
  10.     // check if we got a device parameter
  11.     if( argc < 2 )
  12.     {
  13.         printf ("please provide a device to listen on!\n" );
  14.         return 1;
  15.     }
  16.  
  17.     // open the device for reading
  18.     int fd = open( argv[1], O_RDONLY );
  19.     if( fd < 0 )
  20.     {
  21.         printf( "Error opening device \'%s\'\n", argv[1] );
  22.         return 2;
  23.     }
  24.  
  25.     // read events
  26.     struct input_event ev;
  27.     while( read( fd, &ev, sizeof( struct input_event ) ) )
  28.     {
  29.         printf( "Input event @ %d.%d code=%u type=%u value=%d\n",
  30.                     (int) ev.time.tv_sec,
  31.                     (int) ev.time.tv_usec,
  32.                     (unsigned) ev.code,
  33.                     (unsigned) ev.type,
  34.                     (int) ev.value
  35.               );
  36.     }
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment