GetKeyState problem

Started by
2 comments, last by Extrarius 19 years, 4 months ago
Hi. I'm having trouble with GetKeyState when multiple keys are pressed down. For example, I use the arrow keys to control the camera movement, as shown below. If I have both up arrow and down arrow keys pressed down, then the left arrow key doesn't work, but strangely the right arrow key works. Similarly, if I have both left and right arrow keys pressed down, then the up arrow key doesn't work but the down arrow key works. I'm not sure how GetKeyState works internally, but there seems to be something wrong when multiple keys are pressed. Any help is appreciated!

void get_keyboard_input()
{
	if(GetKeyState(VK_UP) & 0x80)
		Camera.MoveCamera(MOVE_FORWARD);

	if(GetKeyState(VK_DOWN) & 0x80)
		Camera.MoveCamera(MOVE_BACKWARD);

	if(GetKeyState(VK_RIGHT) & 0x80)
		Camera.MoveCamera(MOVE_RIGHT);

	if(GetKeyState(VK_LEFT) & 0x80)
		Camera.MoveCamera(MOVE_LEFT);

}

Advertisement
Maybe you can try GetAsyncKeyState state which is not dependent on messages sent to your window. You should watch whether your window is active or not then, but that should not be problem (just create some variable which is toggled when window gets/loses focus).
I have tried GetAsyncKeyState but the same thing happens... Anyways GetKeyState functions seem pretty weak so I think I'll just learn how to use direct input and see if it works better. Thanks.
You could try GetKeyboardState, and then index that array instead of calling a function for every key. It might not fix your problem, but it is easy to try while DirectInput isn't quite so simple and wouldn't be needed if this fixes your problem =-)
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk

This topic is closed to new replies.

Advertisement