Skip to content

Instantly share code, notes, and snippets.

@ngharo
Created January 3, 2012 17:46
Show Gist options
  • Save ngharo/1556026 to your computer and use it in GitHub Desktop.
Save ngharo/1556026 to your computer and use it in GitHub Desktop.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int fd;
if(argc < 2) {
printf("usage: %s <device>\n", argv[0]);
return 1;
}
fd = open(argv[1], O_RDONLY);
struct input_event ev;
while (1)
{
read(fd, &ev, sizeof(struct input_event));
if(ev.type == 1)
printf("key %i state %i\n", ev.code, ev.value);
}
}
struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};
/********************************************
* Dies with:
/tmp/cap.c: In function ‘main’:
/tmp/cap.c:16: error: storage size of ‘ev’ isn’t known
/tmp/cap.c:20: error: invalid application of ‘sizeof’ to incomplete type ‘struct input_event’
/tmp/cap.c: At top level:
/tmp/cap.c:30: error: expected specifier-qualifier-list before ‘__u16’
**********************************************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment