Here's mine and it looks the same:
Code:
bool CD3DApp::InitInput(void)
{
Input.Init(m_hAppInstance);
Keyboard=new CKeyboard(Input.GetInterface());
if (!Keyboard) return false;
Keyboard->Init(m_hwndAppWindowHandle);
Mouse=new CMouse(Input.GetInterface());
if (!Mouse) {return false;};
Mouse->Init(m_hwndAppWindowHandle);
return true;
}
Code:
#include "CDXinput.h"
HRESULT CDXInput::Init(HINSTANCE hinst)
{
//Create IDirectInput8 interface pointer
if (FAILED(DirectInput8Create(hinst,
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(void**)&_pDI8,
NULL)))
{
::MessageBox(0,"Failed to create DirectInput8 interface",0,0);
}
return true;
}
Code:
HRESULT CKeyboard::Init(HWND window)
{
//Create device
if (FAILED(_pDI8->CreateDevice(GUID_SysKeyboard,
&_pDID8,
NULL)))
{
::MessageBox(0,"Could not create keyboard device",0,0);
}
//Set cooperative level
if (FAILED(_pDID8->SetCooperativeLevel(window,
DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
::MessageBox(0,"Could not set keyboard cooperative level",0,0);
}
//Set data format
if (FAILED(_pDID8->SetDataFormat(&c_dfDIKeyboard)))
{
::MessageBox(0,"Could not set keyboard data format",0,0);
}
//Acquire the keyboard
if (FAILED(_pDID8->Acquire()))
{
::MessageBox(0,"Could not acquire keyboard device",0,0);
}
return true;
}
HRESULT CKeyboard::Update(void)
{
HRESULT hr;
//Make sure we still have the device
//If so fill keystate with current state values representing current
//keyboard state
hr=(_pDID8->GetDeviceState(sizeof(keystate),(LPVOID)&keystate));
if (hr==DIERR_INPUTLOST)
{
::MessageBox(0,"Input lost",0,0);
}
return true;
}
I split it up so the engine does all of it for you once you init the engine. You never call these functions directly.
But it looks the same. Not sure why you are having probs.