Jump to content
  • Advertisement
Sign in to follow this  
Chris Oden

Is there a conventional way to get key input?

This topic is 3975 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Chris Oden
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?
What API are using for keyboard input?

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.

Share this post


Link to post
Share on other sites
Heh, just fix it!

I kid.

I'm using SDL in a win32 API, and as it is now I poll events in the main loop and then check what that event is in every class that needs it.

It only runs the movement if the event == SDL_KEYDOWN, I though it would make it run only once when the key was pressed but it runs continually.

Share this post


Link to post
Share on other sites
Quote:
Original post by Chris Oden
I'm using SDL in a win32 API, and as it is now I poll events in the main loop and then check what that event is in every class that needs it.
SDL has functions for enabling or disabling key repeats and for adjusting the parameters (delay and time interval) thereof.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!