Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <linux/input.h>
- // read events in a loop
- int main(int argc, char** argv)
- {
- // check if we got a device parameter
- if( argc < 2 )
- {
- printf ("please provide a device to listen on!\n" );
- return 1;
- }
- // open the device for reading
- int fd = open( argv[1], O_RDONLY );
- if( fd < 0 )
- {
- printf( "Error opening device \'%s\'\n", argv[1] );
- return 2;
- }
- // read events
- struct input_event ev;
- while( read( fd, &ev, sizeof( struct input_event ) ) )
- {
- printf( "Input event @ %d.%d code=%u type=%u value=%d\n",
- (int) ev.time.tv_sec,
- (int) ev.time.tv_usec,
- (unsigned) ev.code,
- (unsigned) ev.type,
- (int) ev.value
- );
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment