modified: nfig1.py
[GalaxyCodeBases.git] / c_cpp / readscorr / getch.h
blob070909f3e1df80c113c4b6f54b68d5cdbcb7ed6e
1 // From http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1042856625&id=1043284385
2 // Edited by Hu Xuesong @ Thu Apr 28 CST 2011
4 #ifndef _GA_GETCH_H
5 #define _GA_GETCH_H
7 #include <stdio.h>
8 #include <termios.h>
9 #include <unistd.h>
11 inline int mygetch ( void ) {
12 int ch;
13 struct termios oldt, newt;
15 tcgetattr( STDIN_FILENO, &oldt );
16 newt = oldt;
17 newt.c_lflag &= ~( ICANON | ECHO );
18 tcsetattr( STDIN_FILENO, TCSANOW, &newt );
19 ch = getchar();
20 tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
22 return ch;
25 int pressAnyKey (void) {
26 if ( !isatty(STDIN_FILENO) )
27 return -2; // # define EOF (-1) in <stdio.h>
28 // other errno in /usr/include/asm-generic/errno-base.h
29 fputs("\nPress any key to continue ... ", stderr);
30 //return mygetch();
31 int ch = mygetch();
32 fputs("\n", stderr);
33 return ch;
36 #endif /* getch.h */