Keyboard Toggling
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?
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:
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]
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]
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement