Jump to content
  • Advertisement

Archived

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

EGD Eric

Finding the difference between holding the key and pressing it repeatedly

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

So far, Win32 has served my purpose just fine for making this game, but now I''m not sure how to figure out the difference between holding a key and pressing it rapidly. What I''ve been doing is just filling a 256 bool array in WinProc, then checking the array for whether a key is down or not. Now, I want the player to be able to shoot rapidly by pressing the key real fast, and shoot at a steady speed by just holding it. I''m not sure how to do that with Win32. Before I go hacking away on this problem, does DirectInput have an easy way of catching the time between button presses?

Share this post


Link to post
Share on other sites
Advertisement
if (KeyDown(SpaceKey)) {
if (space_keystate == 0) {
// shot wheneva key is hit!
space_keystate = 1;
lastshot = timer + 0.1f;
shoot();
} else {
if {timer > lastshot} {
// shoot every 0.1 sec, when key is held
lastshot = timer + 0.1f;
shoot();
}
}
} else {
space_keystate = 0;
}


something like that would work, could be something better out there, but hey! :D

Dun mes wit me!

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!