How to make it so that when you press the ESC key, without pressing then the Enter key, in getchar (e) for example, did the program end?
|
1 answer
#include <conio.h> if (_getch() == 27) { exit(0); } By the way, if you want to intercept pressing ESC not only in the console, you can use the GetAsyncKeyState () function from Windows.h
for (int i = 0; i < 255; i++) { int state = GetAsyncKeyState(i); if (state == 1 || state == -32767 && i == 27) exit(0); } |
_getch()fromconio.h- Harry