Recommended Posts

I'm having a little problem with my key input, I need a delay before the game registers the key again so my tetris blocks doesn't spin themselves dizzy. I've tried with brute force but that only resulted in the game also skipping key presses when I didn't want it to.
I'm going to experiment a bit but my thought was is there a conventional way to do it?

0

Share this post

Link to post

Share on other sites

Original post by Chris OdenI'm having a little problem with my key input, I need a delay before the game registers the key again so my tetris blocks doesn't spin themselves dizzy. I've tried with brute force but that only resulted in the game also skipping key presses when I didn't want it to.

I'm going to experiment a bit but my thought was is there a conventional way to do it?

Share this post

Link to post

Share on other sites

Depending on what API you are using, it might be possible and desirable to watch for other key state transitions. For example, in Win32 you could watch for the WM_KEYDOWN/WM_KEYUP messages, which are sent only when the key moves from one state to the other. This would allow a block to spin as fast as the button could be pressed, but would not spin wildly when held down.

Another way is to timestamp each keypress on a per-key basis. Then, if not enough time has elapsed, you simply reject each additional keypress. When enough time has elapsed between keypresses, you accept that keypress, update the timestamp to reflect the accepted keypress, and process that input as usual. This method gives a great deal of flexibility in how you can define the input to behave as well as being independent of game cycles.