Download this file
38 lines (32 with data), 568 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 | #if defined ( WIN32 )
# include <conio.h>
#else
# include <stdio.h>
# include <termios.h>
#endif
namespace ctb {
char GetKey()
{
#if defined ( WIN32 )
if(_kbhit()) {
return _getch();
}
return '\0';
#else
int ch;
static struct termios t, save_t;
tcgetattr(0,&t);
save_t = t;
t.c_lflag &= ~(ICANON);
t.c_cc[VMIN] = 0;
t.c_cc[VTIME] = 0;
tcsetattr(0,TCSANOW,&t);
ch = fgetc(stdin);
tcsetattr(0,TCSANOW,&save_t);
if(ch != EOF) {
return ch;
}
return '\0';
#endif
}
} // namespace ctb
|
×
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.