#include #include #include static struct termios stored; void set_keypress(void) { struct termios newone; tcgetattr(0,&stored); memcpy(&newone,&stored,sizeof(struct termios)); /* Disable canonical mode, and set buffer size to 1 byte */ newone.c_lflag &= (~ICANON); newone.c_cc[VTIME] = 0; newone.c_cc[VMIN] = 1; tcsetattr(0,TCSANOW,&newone); return; } int isready(int fd) { int rc; fd_set fds; struct timeval tv; FD_ZERO(&fds); FD_SET(fd,&fds); tv.tv_sec = tv.tv_usec = 0; rc = select(fd+1, &fds, NULL, NULL, &tv); if (rc < 0) return -1; return FD_ISSET(fd,&fds) ? 1 : 0; } void echo_off(void) { struct termios newone; tcgetattr(0,&stored); memcpy(&newone, &stored, sizeof(struct termios)); newone.c_lflag &= (~ECHO); tcsetattr(0,TCSANOW,&newone); return; } void echo_on(void) { struct termios newone; tcgetattr(0,&stored); memcpy(&newone, &stored, sizeof(struct termios)); newone.c_lflag +=8; tcsetattr(0,TCSANOW,&newone); } int main() { cout<<"Type\n"; set_keypress(); echo_off(); char a=' '; while (a!='z'){ if (isready(1)) { cin.get(a); cout << a << flush; } } }