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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With