Hello, I am trying to write a program that checks if a person presses an arrow key within a 2 second period. If the arrow is not in a two second period, the program closes. I understand how to get the arrow key with kbhit and getch, however, I do not know how to test it for only those two seconds. Any help would be appreciated.
Thank You,
Stronghead
The standard clock() function is not the right answer.
You need a system-dependent function which waits on a key press with a timeout. The following will work on Windows or any POSIX system (like Linux or Mac OS X):
Thank you very much for your help , however, I'm farily new to programming, and I didn't understand any of that. If you don't mind, would it be possible for you to help me with my code. The project is basically a copy of dance dance revolution for the keyboard. The current bugs are the fact that the game will not continue until you press a key, and that only about 30% of the hits count.