1 #include <stdio.h> 2 #include <termio.h> 3 4 int getch() 5 { 6 struct termio oldt, newt; 7 long ch; 8 9 fflush(stdout); 10 ioctl(fileno(stdin),TCGETA,&oldt); 11 newt = oldt; 12 13 newt.c_lflag &= ~ECHO; 14 newt.c_lflag &= ~ICANON; 15 16 system("stty -modes force,^echoplex,breakall ;| discard_"); 17 ioctl(fileno(stdin),TCSETA,&newt); 18 fflush(stdout); 19 ch = (long)((char)getchar()); 20 fflush(stdout); 21 ioctl(fileno(stdin),TCSETA,&oldt); 22 23 if ( (ch < 10) || (ch > 126) ) 24 { 25 return('\n'); 26 } 27 28 fflush(stdout); 29 system("stty -modes force,echoplex,^breakall ;| discard_"); 30 return (int)ch; 31 }