Skip to content

Instantly share code, notes, and snippets.

@errzey
Created July 4, 2010 04:40
Show Gist options
  • Save errzey/463133 to your computer and use it in GitHub Desktop.
Save errzey/463133 to your computer and use it in GitHub Desktop.
unsigned char
is_keyboard(const char *file)
{
int fd;
uint8_t bitmask;
fd = open(file, O_RDONLY);
if (fd < 0) {
return(0);
}
if (ioctl(fd, EVIOCGBIT(0, EV_MAX), &bitmask) < 0) {
return(0);
}
/* make sure that the device supports EV_SYN and EV_KEY */
if (!(bitmask & (1 << EV_SYN))) {
return(0);
}
if (!(bitmask & (1 << EV_KEY))) {
return(0);
}
/* make sure the device does not support EV_REL */
if ((bitmask & (1 << EV_REL))) {
return(0);
}
/* make sure the device do not support EV_ABS */
if ((bitmask & (1 << EV_ABS))) {
return(0);
}
return(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment