Jump to content
  • Advertisement
Sign in to follow this  
pjyelton

OpenGL Prevent repeating key press calls

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

Hi, this question isn't exactly OpenGL specific but I have run into this issue with my OpenGL terrain editor. I'm trying to allow the user to press certain keys to turn flags on and off, for example push the letter 'W' to toggle wireframe mode. The problem is everytime the user presses the key the message loops processes the press multiple times, meaning the flag gets set on and off many times in rapid succession. If I just barely tap the key I can sometimes get it to apply only once but often times I need to press it and hope that an odd number of calls are made. Here is an example of my code:
case WM_CHAR:
switch(wParam)  {
  case 'W':case 'w':
  wireframeMode=!wireframeMode;
  break;
}
What do I need to add or change to make it so it only applies once? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
As far as I know WM_CHAR should let you do that toggling.I use it like that and it doesn't toggle multiple times,if I don't hold it down of course.However if I use WM_KEYDOWN it gets toggled multiple times even on one press.

Also what happens when another char different thatn W is pressed?You don't have a break after the switch so it will just go through to the other case's.

Share this post


Link to post
Share on other sites
I do have the break in my code, I just wrote something quick up as an example. So I am the only one who has this problem using WM_CHAR in this way? I have 4 different toggles and this happens on all 4 of them...

Share this post


Link to post
Share on other sites
The way I would do is have an array called:

keys[255];

Catching the WM_KEYDOWN message you then set keys[keycode] to True. On WM_KEYUP You then set it to False.

I then have a separate routine that goes through the keys array and actions based on the values in the array.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!