Jump to content
  • Advertisement
Sign in to follow this  
maya18222

WM_KEYDOWN

This topic is 3717 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 processing these messages and setting the states of my keys as such WM_KEYDOWN if wparam < 255 keystates[wparam] = true WM_KEYUP if wparam < 255 keystates[wparam] = false and then depending on my code, performing actions based off the keys states such as if keystates['M'] renderMap = !rendermap which im using as a toggle to display my map or not, but i seem to be having the issue where when the 'm' is pressed *down* it seems to toggle on and off, many times, meaning that you have to keep pressing it until your lucky enough it toggles th way you want, Can anybody tell me why this would be happening

Share this post


Link to post
Share on other sites
Advertisement
The way you have it right now, the rendermap variable will toggle every frame the 'M' key is held down. What you probably want is for the rendermap variable to toggle if the 'M' key is HIT, not pressed.

To detect key hits, you'll need to check if the key is currently down, but not down the previous frame. So, you'll have to create an array that holds the key states from the previous frame, like this (in C++):

for (int i = 0; i < 255; i = i + 1)
keystatesLastFrame = keystates;

if (wparam < 255)
keystates[wparam] = true;
else
keystates[wparam] = false;

and to check for a key HIT, you'd do

if (keystates['M'] && !keystatesLastFrame['M'])
rendermap = !rendermap

Hope this helps!

--ProgrammerZ

Share this post


Link to post
Share on other sites
You could also do
if (keystates['M'])
{
renderMap = !renderMap;
keystates['M'] = false;
}

No extra variables needed, and it works!

Share this post


Link to post
Share on other sites
Sign in to follow this  

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