Running a program in infinite loop until any key is pressed

I want to make a part of my program to cotinue in infinite loop unti I press any key. And when I release that key the programm should again go into the infinite loop.
Last edited on
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646293%28v=vs.85%29.aspx

The function returns 0 when the specific key is not pressed, and 1 when it is. Just stick it in your loop conditional, or make it an if-statement break check in the middle. You can use the same logic for going back in.
I ment that my program must run automatically until i press any key and when I press key it holds down. When I leave that key it again continues. Can u please write a small code explaining it.
Last edited on
1
2
3
4
5
6
7
while (true) //runs forever
{
    while (keyIsPressed) //will stay in this loop while the key is pressed
    {
        
    } //when you stop pressing the key it will resume the initial while loop
}


This is basically my pause function for my game
Last edited on
how to define (keyIsPressed). Is keyIsPressed already defined in c++.
Is keyIsPressed already defined in c++.
No, it's system specific

For windows either use what Ispil showed, or _kbhit():

https://msdn.microsoft.com/de-de/library/58w7c94c.aspx
Last edited on
OK..thanks a lot..
Topic archived. No new replies allowed.