Esc key

Hello everybody

I just want to know how to implement the Esc key from the keyboard in a console program
in which if the Esc key pressed at any time in the program, (by any time I mean at inputting, outputting, calculating, or just looping ) it makes a call for a specific function.
How to do That?

Note :
Operating system (windows 7 )
Compiler : QT creator 4.8

Please help
Thanks
Last edited on
While such thing could be hacked together, console is not created for that. Just start making proper windowed programs. It's not that hard. If you want to make a game, see SFML or SDL, if not, try Qt or GTK (in each pair, the first is more productive, but may be harder to set up).
The options you have are to unbuffer your input and handle all individual keypresses yourself, or to use a keyboard hook.

Google "msdn SetWindowsHook" for information on the second method.

Good luck!
@ Duoas

How to unbuffer the input?

*I can't use the second option you mentioned because I'm working in qt not visual studio.
@Baso

If your checking for key presses with GetKeyState, then try adding
1
2
3
4
if(GetKeyState('\x1B')<0)//Pressing 'ESC' key
{
  cout << "ESC key pressed.." << endl;// Put here what is to happen when this key pressed
}
Last edited on
Qt doesn't prevent you from using the Windows API directly, and setting a keyboard hook doesn't do anything that will modify your program's normal operation.

Though, I do believe Qt has slots for keyboard hooks... I has been a long time since I've messed with it and I'm not interested in browsing the documentation myself right now...
Topic archived. No new replies allowed.