Skip to main content
gamedev.net
🔒 Locked

Question about programming keystrokes

Started by Apocalypse_Demon 1 reply 200+ views
Original Post
Apocalypse_Demon
Apocalypse_Demon
I''m having a problem with implementing a way to check if two keys are pressed at the same time in VC++. For example, I have it so that if they press the up key(VK_UP), the camera would move forward, and the same for other keys, but what if the user wants to move diagonally by pressing the up and right key at the same time? I tried: case VK_UP && VK_RIGHT: and typed in the necessary code(call to a function to setup movement), but it didn''t work(acted just as if there wasn''t an && there). Obviously, there is a different way to do this, but I don''t know. Any help is appreciated.
Alan Kemp
Alan Kemp

  
char KeyStates[255];

// In your init

for (int i = 0; i < 255; i++)
{
KeyStates[i] = 0;
}

// In your win proc

case WM_KEYDOWN:
KeyStates[wParam] = 1;
break;
case WM_KEYUP:
KeyStates[wParam] = 0;
break;

// When you want to test keys

if (KeyStates[VK_UP] && KeyStates[VK_LEFT])
{
// both up and left are pressed

}



Alan
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.