// Use DirectInput 8 to correspond to the rest of our program (uses DirectX 9.0c)
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#include "stdafx.h"
#include "CDx_Input.h"
#include "CONSTANTS.h"
#include "Log.h"
CDx_Input::CDx_Input(void)
{
//m_lpDI8 = NULL;
//m_mouse = NULL;
//m_keyboard = NULL;
}
CDx_Input::~CDx_Input(void)
{
Close();
}
HRESULT CDx_Input::Init_DirectInput(void)
{
HRESULT hr = S_OK;
// This command is FAILING for some reason.
hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_lpDI8, NULL);
if(SUCCEEDED(hr))
Write_Log(E_NONE, "Succeeded in instantiating DirectInput8 on startup.");
else
Write_Log(E_FATAL, "Failed to instantiate DirectInput8 on startup!");
// Return.
return hr;
}
**snip**
#ifndef _DIRECTXMANAGERS_CDXINPUT_H
#define _DIRECTXMANAGERS_CDXINPUT_H
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
// Define button is down and button is released. Button released is just the opposite of button down.
#define KeyDown(name, key) ((name[key] & 0x80) ? true : false)
#define KeyUp(name, key)((name[key] & 0x80) ? false : true)
class CDx_Input
{
public:
CDx_Input(void);
~CDx_Input(void);
HRESULT Init_DirectInput(void);
HRESULT Init_Keyboard(HWND hWnd);
HRESULT Init_Mouse(HWND hWnd);
void Update(void);
void Close(void);
private:
LPDIRECTINPUT8 m_lpDI8;
IDirectInputDevice8* m_keyboard;
IDirectInputDevice8* m_mouse;
};
#endif // _DIRECTXMANAGERS_CDXINPUT_H