In my program i've tried to inizialize two Input devices, the first dedicate to Mouse Input and the second for KeyBoard Input. So:
LPDIRECTINPUT8 g_lpDI; // the direct input object
LPDIRECTINPUTDEVICE8 g_lpDIDeviceMouse; // the direct input device
LPDIRECTINPUTDEVICE8 g_lpDIDeviceKeyboard; // the direct input device
LPDIRECTINPUT8 g_lpDIK; // the direct input object
I don't have problem when i try to inizialize the Mouse:
bool diManager::initDirectInputMouse(HINSTANCE hInst, HWND wndHandle)
{
HRESULT hr;
// Create the DirectInput object.
hr = DirectInput8Create(hInst, DIRECTINPUT_VERSION,
IID_IDirectInput8, (void**)&g_lpDI, NULL);
if FAILED(hr)
return FALSE;
// Retrieve a pointer to an IDirectInputDevice8 interface
hr = g_lpDI->CreateDevice(GUID_SysMouse, &g_lpDIDeviceMouse, NULL);
if FAILED(hr)
return FALSE;
hr = g_lpDIDeviceMouse->SetDataFormat(&c_dfDIMouse);
if FAILED(hr)
return FALSE;
// Set the cooperative level
hr = g_lpDIDeviceMouse->SetCooperativeLevel(wndHandle, DISCL_FOREGROUND | DISCL_EXCLUSIVE);
if FAILED(hr)
return FALSE;
// Get access to the input device.
hr = g_lpDIDeviceMouse->Acquire();
if FAILED(hr)
return FALSE;
return true;
}
But when i try to inizializze my Keyboard Device:
bool diManager::initDirectInputKeyboard(HINSTANCE hInst, HWND wndHandle)
{
HRESULT hr;
hr = DirectInput8Create(hInst, DIRECTINPUT_VERSION,
IID_IDirectInput8, (void**)&g_lpDIK, NULL);
if FAILED(hr)
return FALSE;
// Retrieve a pointer to an IDirectInputDevice8 interface
hr = g_lpDIK->CreateDevice(GUID_SysKeyboard, &g_lpDIDeviceKeyboard, NULL);
hr = g_lpDIDeviceKeyboard->SetDataFormat(&c_dfDIKeyboard);
if FAILED(hr)
return FALSE;
hr = g_lpDIDeviceKeyboard->SetCooperativeLevel(wndHandle,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if FAILED(hr)
return FALSE;
// Get access to the input device.
hr = g_lpDIDeviceKeyboard->Acquire();
if FAILED(hr)
return FALSE;
}
This return me "FALSE" in the first control of
hr. In WinMain i write this two controls:
if (!diMgr.initDirectInputMouse(hInst, wndHandle))
{
MessageBox(NULL, "Unable to init DirectInput MOUSE", "ERROR", MB_OK);
return false;
}
if (!diMgr.initDirectInputKeyboard(hInst, wndHandle))
{
MessageBox(NULL, "Unable to init DirectInput KEYBOARD", "ERROR", MB_OK);
return false;
}
But the second control give me FALSE.. Can i create a only device dedicated to Keyboard and mouse to solve this problem?