Created
April 25, 2017 09:35
-
-
Save kelunik/d9a9d70fbaeeab1d7d94d16da6303ce4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <errno.h> | |
#include <linux/input.h> | |
#include <string.h> | |
#include <stdio.h> | |
static const char *evval[3] = { | |
"RELEASED", | |
"PRESSED", | |
"REPEATED" | |
}; | |
int main(void) { | |
const char *dev = "/dev/input/by-id/usb-Fujitsu_Technology_Solutions_GmbH_Fujitsu_Keyboard-event-kbd"; | |
struct input_event ev; | |
ssize_t n; | |
int fd; | |
fd = open(dev, O_RDONLY); | |
if (fd == -1) { | |
fprintf(stderr, "Cannot open %s: %s.\n", dev, strerror(errno)); | |
return EXIT_FAILURE; | |
} | |
while (1) { | |
n = read(fd, &ev, sizeof ev); | |
if (n == (ssize_t) -1) { | |
if (errno == EINTR) { | |
continue; | |
} else { | |
break; | |
} | |
} else { | |
if (n != sizeof ev) { | |
errno = EIO; | |
break; | |
} | |
} | |
if (ev.type == EV_KEY && ev.value == 0) { | |
if (ev.code >= 2 && ev.code <= 10) { | |
printf("%d", ev.code - 1); | |
} else if (ev.code == 11) { | |
printf("%d", 0); | |
} else if (ev.code == 28) { | |
printf("\n"); | |
} | |
} | |
fflush(stdout); | |
} | |
fflush(stdout); | |
fprintf(stderr, "%s.\n", strerror(errno)); | |
return EXIT_FAILURE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment