With my OPENGL game I've gotten my characters to move around using the windows.h library, however I can't move both characters at the same time one uses wasd other uses arrow keys. here is my code, how do I make it still work if multiple keys are pressed at same time.
That's not the way processing key press in game.
All you need to do is to use an array to store state of each key, and iterate through them in your update function.
Sample code:
bool keys[256] = {}; // an array to store all key states, put to global or somewhere else
In the message loop
1 2 3 4 5 6 7
case WM_KEYDOWN:
keys[wParam] = true;
break;
case WM_KEYUP:
keys[wParam] = false;
break;
In your update function:
1 2 3 4 5
if (keys[VK_UP]) ...
if (keys[VK_DOWN]) ...
if (keys[VK_LEFT]) ...
if (keys[VK_RIGHT]) ...
...
while (1)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)
{
if (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg, NULL, 0, 0);
DispatchMessage(&msg, NULL, 0, 0);
}
else
{
break;
}
}
else
{
Update(); // This is where you update your character
Draw(); // This is where you draw your things
}
}