Running program for a period of time

Hello!
How can I make my code to run for a fixed period of time?
Something Like

runfor10seconds{
ch=_getch();
}

For 10 seconds the program will wait me to press a character on keyboard, and if I don't, "ch=_getch()" won't happen. Also how can i make it to stop when I press a character and don't wait for the rest amout of seconds?

I hope you understand my question and I hope you can help me :)
Thank you !
If you want to do this type of thing, you probably should move away from the console and use a real GUI/graphics library like Qt or SFML. The console isn't designed for this type of interaction and you will waste time fighting it when you could instead use a real graphical window.
closed account (48T7M4Gy)
http://stackoverflow.com/questions/9240109/how-to-run-a-program-for-a-specified-amount-of-time
Topic archived. No new replies allowed.