I found this piece of code online:
CHAR getch() {
DWORD mode, cc;
HANDLE h = GetStdHandle( STD_INPUT_HANDLE );
if (h == NULL) {
return 0; // console not found
}
GetConsoleMode( h, &mode );
SetConsoleMode( h, mode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT) );
TCHAR c = 0;
ReadConsole( h, &c, 1, &cc, NULL );
SetConsoleMode( h, mode );
return c;
}
Using it like:
while(1) {
TCHAR key = getch();
}
I am able to get numeric, alphabetic even return key presses. But am not able to get escape or other functional keys like control, alt. Is it possible to modify it to detect also these keys?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…