#include #include #include int tty_cbreak (int fd, struct termios *orig) { struct termios buf; if (tcgetattr (fd, &buf) < 0) return -1; /* Save the original state, for resetting later */ *orig = buf; buf.c_lflag &= ~(ECHO | ICANON); buf.c_iflag &= ~(ICRNL | INLCR); buf.c_cc[VMIN] = 1; buf.c_cc[VTIME] = 0; #if defined (VLNEXT) && defined (_POSIX_VDISABLE) buf.c_cc[VLNEXT] = _POSIX_VDISABLE; #endif #if defined (VDSUSP) && defined (_POSIX_VDISABLE) buf.c_cc[VDSUSP] = _POSIX_VDISABLE; #endif if (tcsetattr (fd, TCSAFLUSH, &buf) < 0) return -1; return 0; } int tty_set_attributes (int fd, struct termios *buf) { if (tcsetattr (fd, TCSAFLUSH, buf) < 0) return -1; return 0; } int main (int argc, char **argv) { struct termios term_attributes; tty_cbreak (0, &term_attributes); while (1) { int c; read (0, &c, 1); fprintf (stderr, "%d\n", c); if (c=='q') break; } tty_set_attributes (0, &term_attributes); return 0; }