Also, I'm confused about why adding a delay makes a difference. Maybe it has something to do with key repeat? The second key pressed will repeatedly be set as pressed while the first is only pressed once?
Anyway here's an alternative way, a bit uglier, but it works for me-
bool GetKeyEvent(unsigned char &Scancode, bool &Pressed)
{
DIDEVICEOBJECTDATA TheEvent;
unsigned long ArrayLen= 1;
HRESULT Result;
Result= Keyboard->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), &TheEvent, &ArrayLen, 0);
if (!SUCCEEDED(Result))
{
return false; // no keys pressed
}
if (ArrayLen == 1)
{
Scancode= (unsigned char) TheEvent.dwOfs;
if (TheEvent.dwData & 0x80)
Pressed= true;
else
Pressed= false;
return true;
}
else
return false;
}
Call this in your main loop:
while (GetKeyEvent(Scancode, Pressed))
register this key as pressed/released
You'll need an array of the keys you want to use in your program, and mark them as down/up in the above loop.
Then after the loop you can check your keyarray for the pressed keys.
This also fixes a problem you might run into later, if you have a shoot key for instance- it's possible to press and release the key inbetween calls to GetDeviceState, in which case the keypress would not be caught.
hope this is somewhat useful