Advertisement

DirectInput

Started by July 26, 2002 05:16 AM
0 comments, last by Pipo DeClown 22 years, 4 months ago
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.
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

This topic is closed to new replies.

Advertisement