• Forum
  • Lounge
  • Quit getch() Input if X seconds reached?

 
Quit getch() Input if X seconds reached?

Hey Guys!


I just wanted to create some kind of pseudo framerates with my game tryout in DOS.
Therefore I want to let the screen being redrawn in a for(;;) loop and always get a input getch() demand. BUT if this demand isn't solved fast enough the getch() should be skipped.

I want to kinda let the user being able to press W / A / S / D - and move the 'X' through the continued drawn array. Since that all has to happen in "pseudo" realtime I want to let the getch() being skipped so if the user presses one of the above buttons it will be catched because of the processing speed of the machine.

I'm sure this is very dirty coding but i want to try it out anyway!

OK? What's your question? Like you said, it's definitely not an ideal solution.
Well my question is...how can I let getch() quit after a few seconds?
You can use std::async and query the future object for a certain time using wait_until().

http://en.cppreference.com/w/cpp/thread/async
http://en.cppreference.com/w/cpp/thread/future
Wow...this reference doesn't seems to be that understandable for me right away ^^ I think I need to recheck some basics again I think ^^
As you are (I presume) using windows, you can use some native WinAPI functions to do this. How about GetAsynKeyState()? See http://msdn.microsoft.com/en-us/library/windows/desktop/ms646293(v=vs.85).aspx
Topic archived. No new replies allowed.