Jump to content
  • Advertisement
Sign in to follow this  
Tybon

GetKeyState problem

This topic is 5129 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'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);

}

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 =-)

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!