-
GetKeyState(VK_.....);
Here is some code that acts funny, maybe I'm not using the function correctly. What it does is, sometimes it moves on its own (like the key is being pressed) and sometimes it acts like nothing is moving.
Code:
void MainLoop() //Main Game Loop
{
switch( LOWORD(GetKeyState (VK_LEFT)) )
{
case 0:
left = true;
break;
}
switch( LOWORD(GetKeyState (VK_RIGHT)) )
{
case 0:
right = true;
break;
}
switch( LOWORD(GetKeyState (VK_UP)) )
{
case 0:
up = true;
break;
}
switch( LOWORD(GetKeyState (VK_DOWN)) )
{
case 0:
down = true;
break;
}
UpdateShip(left, right, up, down);
left = false; right = false; up = false; down = false;
}
-
If you don't mind, just post up the whole program and I'll take a look at it.
-
thats an interesting setup of switch statements:confused:
-
lol i know. once i figure out how to use GetKeyState() I'll make it much more efficient.
-
[Docs]
If the function succeeds, the return value specifies the status of the given virtual key. If the high-order bit is 1, the key is down; otherwise, it is up. If the low-order bit is 1, the key is toggled.[/Docs]
Don't check the return value, check the high-order bit of the return value ( use a logical AND : & )
-
i just used it like:
Code:
if(GetKeyState(VK_UP))
//code here
-
I think this would be easier
Code:
BYTE KeyStates[256];
if(!GetKeyboardState(&KeyStates))//error
return FALSE;
UpdateShip(KeyStates[VK_LEFT] ,KeyStates[VK_RIGHT] ,KeyStates[VK_UP] ,KeyStates[VK_DOWN] );