#include #include #include #include #include #include #include #include #include #include #include #include volatile int done = 0; void sighandler(int sig) { done = 1; } int main(int argc, char **argv) { struct wscons_event ev; struct termios kbdtty, okbdtty; int fd, i, n, option = WSKBD_TRANSLATED; unsigned char buf[256]; signal(SIGINT, sighandler); signal(SIGTERM, sighandler); printf("Signals installed\n"); if ((fd = open(argv[1] != NULL ? argv[1]:"/dev/wskbd0", O_RDWR)) < 0) { perror("open"); return 1; } #if 0 tcgetattr(fd, &kbdtty); okbdtty = kbdtty; cfmakeraw(&kbdtty); kbdtty.c_cc[VTIME] = 0; kbdtty.c_cc[VMIN] = 1; tcsetattr(fd, TCSANOW, &kbdtty); #endif #if 1 if (argv[2] != NULL) { if (argv[2][0] == 'r') { option = WSKBD_RAW; } } else { option = WSKBD_TRANSLATED; } if (ioctl(fd, WSKBDIO_SETMODE, &option) < 0) { perror("SETMODE RAW"); return 1; } if (option == WSKBD_RAW) { printf("mode RAW\n"); } else { printf("mode TRANSLATED\n"); } #endif printf("entering loop\n"); done = 0; while (!done) { if (option == WSKBD_TRANSLATED) { n = read(fd, &ev, sizeof(ev)); printf("-> %d type: %d, value %d\n", n, ev.type, ev.value); } else { struct pollfd pfd[1]; pfd[0].fd = fd; pfd[0].events = POLLIN; n = poll(pfd, 1, INFTIM); if (n <= 0) { printf("nothing %d\n", n); continue; } n = read(fd, buf, sizeof(buf)); printf("-> %d\r\n", n); for (i = 0; i < n; i++) { printf(" 0x%02x\r\n", buf[i]); } } } tcsetattr(fd, TCSANOW, &okbdtty); option = WSKBD_TRANSLATED; ioctl(fd, WSKBDIO_SETMODE, &option); exit(0); }