rendered paste body#include <stdio.h>#include <termios.h>#include <sys/ioctl.h>int getchar_imm() { struct termios ts; struct termios new_ts; int c; // read old termios ioctl(0, TCGETS, &ts); // copy old termios new_ts = ts; // modify it new_ts.c_lflag &= !(ICANON | ECHO); // delete line buffer and echo flag new_ts.c_lflag |= ISIG; // set "send signal on specific keys" flag: ctrl-c, ctrl-z, ctrl-alt-\ // set it ioctl(0, TCSETS, &new_ts); // read char c = getchar(); // set old one ioctl(0, TCSETS, &ts); return c;}int main() { int c; while (EOF != (c = getchar_imm())) { printf("Char '%c' (%i)\n", c, c); } return 0;}