Jump to content
  • Advertisement

Archived

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

mfdemi

keyboard handling

This topic is 5821 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 test keyboard input in the WndProc funtion like the following: case WM_KEYDOWN: // Is A Key Being Held Down? { Keys[wParam] = true; // If So, Mark It As TRUE return 0; // Jump Back } case WM_KEYUP: // Has A Key Been Released? { Keys[wParam] = false; // If So, Mark It As FALSE return 0; // Jump Back } And in the main function I check for certain keys ever frame.But this doesn''t seem to be sensitive enough.For instance when the user presses the PAUSE key I want to pause the game.But not every time it happens.

Share this post


Link to post
Share on other sites
Advertisement
I think it is executed every time, but since you check every frame for the key, you''ll be executing your PAUSE-code multiple times. You could use a boolean to indicate whether the key is being pressed. Set it to 1 (=true) when executing the PAUSE-code, and if it is released, set it to zero (=false) again.

  
bool pp = 0; // indicate whether pause is being pressed

.
.
.
if (Keys[VK_PAUSE] && !pp)
{
pp = 1;
//your code

}
if (!Keys[VK_PAUSE] && pp)
{
pp = 0;
}

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!