Jump to content
  • Advertisement

Archived

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

Peaceman

Keyboard Toggling

This topic is 5967 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, I am currently working on a 3d-Engine (ain''t we all... ) but came across some problems with the input. I don''t use DI, and don''t use the WinProc. Instead I use GetKeyState() like this: if(GetKeyState(VK_SPACE)) { toggle = true; } if(!GetKeyState(VK_SPACE)) { toggle = false; } However this way toggle (a special zoom) is only used when the space bar is pressed down. This makes sense, but I want to toggle the zoom on and off, however I could''nt work out a way to accomplish this. The problem I ran into is that GetKeyState ist called too often so that he toggles on and off straight away and not only once per hit. Any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
You really shouldn't be checking to see if the entire return value is zero or non-zero, as the documents state that the high bit of the return value as what you should be checking. So something like this:

if(GetKeyState(VK_SPACE) & 0x8000)
{
// Space is down!
}
else
{
// Space is up!
}


I'm not trying to be nitpicky. It's just that you aren't gauranteed that the rest of the value will be 0 if the high bit is 0.

[edited by - Zipster on August 12, 2002 4:33:58 PM]

Share this post


Link to post
Share on other sites
in init:
BOOL PrevState = FALSE;


where your current code is:

if(GetKeyState(VK_SPACE) & 0x8000 && PrevState == FALSE){
toggle = true;
PrevState = TRUE;
}
if (!(GetKeyState(VK_SPACE) & 0x8000) && PrevState == TRUE{
toggle = false;
PrevState = FALSE;
}

If I made a typo, then change it :0. It should be something to this effect.

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.

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!