#include #include #include #include #include int main() { struct termios old, new; tcgetattr(STDIN_FILENO, &old); new = old; new.c_lflag &= ~(ECHO | ICANON); new.c_cc[VMIN] = 0; // bytes read to return new.c_cc[VTIME] = 0; // time before return tcsetattr(STDIN_FILENO, TCSANOW, &new); struct pollfd poller[1]; poller[0].fd = STDIN_FILENO; poller[0].events = POLLIN; printf("Pressed characters:\n"); uint8_t run = 1; while (run) { int events = poll(poller, 1, -1); if (events > 0 && poller[0].revents & POLLIN) { char buffer[10]; uint16_t length = read(STDIN_FILENO, buffer, sizeof(buffer)); if (length > 0) { uint8_t i; for (i = 0; i < length; i++) { printf(" %x", buffer[i]); if (buffer[i] == 'Q') run = 0; } printf("\n"); } } } tcsetattr(STDIN_FILENO, TCSANOW, &old); return 0; }