Skip to content

Instantly share code, notes, and snippets.

@errzey
Created July 4, 2010 04:55
Show Gist options
  • Save errzey/463142 to your computer and use it in GitHub Desktop.
Save errzey/463142 to your computer and use it in GitHub Desktop.
int
keyboard_watcher_init(const char **keyboards)
{
const char *keyboard = NULL;
while ((keyboard = *(keyboards++)) != NULL) {
int fd;
keyboard_t *kb;
fd = open(keyboard, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
fprintf(stderr, "[*] Unable to attach to %s: %s\n",
keyboard, strerror(errno));
continue;
}
kb = calloc(sizeof(keyboard_t), 1);
if (kb == NULL) {
return(-1);
}
event_set(&kb->event, fd, EV_READ | EV_PERSIST,
(void *)process_keystroke, (void *)kb);
event_add(&kb->event, 0);
}
return(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment