Archived

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

Getting Keystrokes at 30 fps

This topic is 5402 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 making the menu for a game that''s controlled by the keyboard w/ DInput. The up/down arrows select the item and then you press enter to choose it. However the game is running at about 30 fps so when someone press the up key it goes up a few items. I tried to fix this by having an int that is set to 0. Then when the key is pressed the int is increased by one and if it is above 4, a diffrent item is selected. This works ok but is still a little jerky. for example, if the person let go of the key when the int is a 4, the next time he presses the key it will jump to the next item very quickly. I hope this makes some sort of sense. Does anyone have any other ideas how to implement this? thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
First, your menu should be outside of your main rendering loop.

Secondly, you can fix your problem by testing for the key down and key up sequences. Initially the key will be up, then when the user presses it will be down, and finally when the user releases the key it will be up again. Test for this sequence in the array that you get back from IDirectInputDevice::GetDeviceState().

Share this post


Link to post
Share on other sites
Do not use DirectInput in this situation, instead use windows messages handler, the WindProc, to handle keyboard key presses. It works a gazillion times better in this situation. You can use it simultaneously with DI.

Possibility

Share this post


Link to post
Share on other sites
DInput buffered is pretty much equivalent (and a little more reliable) than Windows messaging here, because you can tell it to work even if your application loses focus etc. Plus if you already have DInput set up...

Also using DInput you can bypass the standard Windows messaging loop... which is helpful if you have an exclusive-mode application.

Share this post


Link to post
Share on other sites