Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether key is pressed down in Windows console [duplicate]

Possible Duplicate:
C++ console keyboard events

I want a Windows console program to do something if a certain key is pressed down, something like

while(1)
{
    ....
    if(the key 'o' is pressed down)
      ....
}

but I don't know what to put in the if statement. How do I check if the key 'o' is pressed down?

I'm using Windows 7 64-bit and Visual Studio Professional 2008.

like image 725
Timothy Avatar asked Nov 14 '22 21:11

Timothy


1 Answers

You can use the std::cin.get() or you can use the windows.h GetAsyncKeyState, depending on what exactly you want to do.

If you want lower level stuff, look into hooks and events from the WinAPI.

like image 164
ultifinitus Avatar answered Dec 22 '22 07:12

ultifinitus