Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

Pipo DeClown


This topic is 5958 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

Im working with the keyboard and everything works fine...exually that was a lie. Everything works to fast. I get the Input every frame. But process the input every 0.032 I think. Can I somehow filter my input? Because I think he processes the same press twice.

Share this post

Link to post
Share on other sites
A better forum for this question would be the DirectX forum as this is a DirectX question (DirectInput is a component of DirectX).

Essentially what your looking for is what I call a "one shot" event. That is, you want to know that the user has pressed the key but you do not want to execute the event again until they have release the key and pressed it again.

There are basically 2 ways to solve this:

1) You can set a flag saying you''ve handled the event, than in each update loop watch for the key to not be pressed and clear that flag. If your code sees the key is pressed AND the flag is set, it does not execute the event.

This method is not precise and will lead to problems down the road (i.e. as your frame rate drops).

2) You can (and should) use DI buffering. Read the SDK docs on buffered device input, it''s not terribly complicated. Essentially what this does is to give you a record of every key press and key release that has occurred since the last time you polled. Now you dont have to worry about flags because you will only get 1 key press event for each time they press (and subsequently release) the key.

Keep in mind that you can get both buffered and state data from the device so you can have ''continuous'' events triggered by the state data (i.e. move forward if the move forward key is pressed), and ''one-shot'' events triggered from the buffered data. This is the scheme I use and I''m very happy with it.

Come join us on IRC in #directxdev @ irc.afternet.org

Share this post

Link to post
Share on other sites

  • 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!