Home c++ How to exit the C++ program using the ESC key

How to exit the C++ program using the ESC key

Author

Date

Category

How to make it so that when you press the ESC key, without pressing, then the Enter key, in Getchar (e), for example, the program ended?


Answer 1, Authority 100%

# include & lt; conio.h & gt;
if (_Getch () == 27)
{
  EXIT (0);
}

By the way, if you want to intercept the Pressing ESC not only in the console, you can use the GetAsyncKeyState () from windows.h

for (int i = 0; i & lt; 255; i ++)
{
  int state = getAsyncKeyState (i);
  If (state == 1 || state == -32767 & amp; & amp; i == 27)
    EXIT (0);
}

keys keys

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions