Hey - so I'm writing this game engine with help from a book. I'm encountering some difficulties with DirectInput. I keep having problems when I try to poll the keyboard.
When I first try to poll the keyboard - i get DIERR_NOTACQUIRED - which I found out means that the device is not acquired. now, i believe that I am calling the Acquire() method of the IDirectInput8Device for the keyboard (I have tested this and it says I'm successfully acquiring the device), but I still atempt to reaqcuire the device. this works successfully, again, and the game once again tries to poll the keyboard. this time, I get DIERR_INPUTLOST - which means the input device was lost and I need to reacquire it. so i do, successfully a third time, and it still throws a DIERR_INPUTLOST error when I try to poll the mouse. anyone know what's going on?
here's the part of the code that polls the mouse:
void Input::Update()
{
MessageBox(NULL,"Input::Update() invoked","Test",MB_OK);
static HRESULT result;
//poll the keyboard
while(1)
{
MessageBox(NULL,"Entered the keyboard polling loop","Test",MB_OK);
m_keyboard->Poll();
if(SUCCEEDED(result = m_keyboard->GetDeviceState(256,(LPVOID)&m_keyState)))
{
MessageBox(NULL,"Keyboard updated, breaking loop...","Test",MB_OK);
break;//we succeeded in updating the keyboard, break out of the loop
}
if(result == DIERR_INPUTLOST)
MessageBox(NULL,"Error: DIERR_INPUTLOST","test",MB_OK);
if(result == DIERR_NOTACQUIRED)
MessageBox(NULL,"Error: DIERR_NOTACQUIRED","test",MB_OK);
if(result != DIERR_INPUTLOST && result != DIERR_NOTACQUIRED)
{
MessageBox(NULL,"Unknown error encountered, aborting...","Test",MB_OK);
return;//we don't know what to do with the error returned to us, abort the function
}
MessageBox(NULL,"Atempting to reacquire keyboard to solve known error","Test",MB_OK);
if(FAILED(m_keyboard->Acquire()))//try to reaquire the keyboard device
{
MessageBox(NULL,"Reacquisition failed, aborting...","Test",MB_OK);
return;//if that doesn't work, abort the function (otherwise it will automatically restart the loop)
}
MessageBox(NULL,"Reacquisition succeeded - restarting loop","Test",MB_OK);
}
the codes in C++ btw