Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Awaiting for some key to be pressed without looping

$
0
0
Hi !
I need some way to wait in a easy console app for some key for example left arrow to be pressed.
I have tried things like this:
if( GetAsyncKeyState( VK_LEFT ) & 0x8000 )


but this code if( GetAsyncKeyState( VK_LEFT ) checks for pressed key only when its called, and to check all the time i need to loop it.It works, however when i loop it, its lagging my pc (100% usage, do you know a way that will just wait for the input and if there is a other button pressed then just go back to a function ?
Like:
void waiting()
{
    waitForKey( VK_LEFT )
    //If other key pressed then do waiting(); again
    //some code that will be done after VK_LEFT pressed.
}


thats how i imagine it xD
BTW im not some pro C++ programmer and it would be the best if someone would also show it on a example of a simple program.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>