C
Celestiaz
Guest
I'm building a game that uses both the keyboard and a joystick, if there is one. For this I use DirectInput but, as I said in the title, when I call Acquire() on the keyboard, it returns an ACCESS_DENIED error.
// Called after DirectInput8Create(...)
int create_keyboard()
{
// DirectInput Device Keyboard
HRESULT result;
result = g_lpdi->CreateDevice(GUID_SysKeyboard, &gDIDeviceKeyboard, NULL);
result = gDIDeviceKeyboard->SetDataFormat(&c_dfDIKeyboard);
result = gDIDeviceKeyboard->SetCooperativeLevel(sHWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
result = gDIDeviceKeyboard->Acquire(); // result == ACCESS_DENIED
sKeyboardIsInitialized = true;
return 0;
}
Sometimes though Acquire() does not return an error but when I read the keyboard state I have an error. Here is the function that gets called each frame.
void InputSys_Keyboard_UpdateState()
{
CopyMemory(sKeyboard.prevState, sKeyboard.curState, INPUT_NUMVB * sizeof(unsigned char));
// This call returns an error
HRESULT hr = gDIDeviceKeyboard->GetDeviceState(256, sKeyboard.rawState);
if (DI_OK != hr) {// hr is not DI_OK
// I tried to reacquire the keyboard but I get the ACCESS_DENIED here now
HRESULT result = gDIDeviceKeyboard->Acquire();
if (DI_OK != result) {
// TODO: log error
OutputDebugString(L"ERROR: InputSys: GetKeyboardState");
return;
}
}
// Doing some stuff here
return;
}
I'd like to say that first I wrote the code to set up a joystick and it worked completely fine. But then when I added the code to set up the keyboard I got this error from Acquire() on the keyboard.
Continue reading...
// Called after DirectInput8Create(...)
int create_keyboard()
{
// DirectInput Device Keyboard
HRESULT result;
result = g_lpdi->CreateDevice(GUID_SysKeyboard, &gDIDeviceKeyboard, NULL);
result = gDIDeviceKeyboard->SetDataFormat(&c_dfDIKeyboard);
result = gDIDeviceKeyboard->SetCooperativeLevel(sHWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
result = gDIDeviceKeyboard->Acquire(); // result == ACCESS_DENIED
sKeyboardIsInitialized = true;
return 0;
}
Sometimes though Acquire() does not return an error but when I read the keyboard state I have an error. Here is the function that gets called each frame.
void InputSys_Keyboard_UpdateState()
{
CopyMemory(sKeyboard.prevState, sKeyboard.curState, INPUT_NUMVB * sizeof(unsigned char));
// This call returns an error
HRESULT hr = gDIDeviceKeyboard->GetDeviceState(256, sKeyboard.rawState);
if (DI_OK != hr) {// hr is not DI_OK
// I tried to reacquire the keyboard but I get the ACCESS_DENIED here now
HRESULT result = gDIDeviceKeyboard->Acquire();
if (DI_OK != result) {
// TODO: log error
OutputDebugString(L"ERROR: InputSys: GetKeyboardState");
return;
}
}
// Doing some stuff here
return;
}
I'd like to say that first I wrote the code to set up a joystick and it worked completely fine. But then when I added the code to set up the keyboard I got this error from Acquire() on the keyboard.
Continue reading...