Original Post
Ok so Im having issue getting my mouse to work... Im making an .dll based engine... and I am just trying to get the base down before I start throwing in serious things and start tweaking. All I want for now is basic mouse and keyboard... The keyboard works fine but the mouse is only working 1 feature at a time. If I get the button working the X,Y axis dont work. If I get he X to work the Y axis and buttons dont work. Heres the code: This is the .h This is the .cpp Sorry for the messy code...
#pragma once
#ifdef KAIGANINPUTS_EXPORTS
#define KAIGANINPUTS_API __declspec(dllexport)
#else
#define KAIGANINPUTS_API __declspec(dllimport)
#endif
#include <dinput.h>
#define KeyDown(data, n) ((data[n] & 0x80) ? true : false)
#define KeyUp(data, n) ((data[n] & 0x80) ? false : true)
/***************************************************************
class KInput - Handles All atributes of Inputs
***************************************************************/
class KAIGANINPUTS_API KInput
{
public:
KInput(HWND wHandle);
~KInput();
bool KeyboardState(int keyDown);
bool MouseButtonState(int buttonDown);
long RelMouseX();
long RelMouseY();
long MouseScroll();
private:
HWND wndHandle;
LPDIRECTINPUT8 pDXInput;
LPDIRECTINPUTDEVICE8 pDXKeyboard;
LPDIRECTINPUTDEVICE8 pDXMouse;
char keystate[256];
DIMOUSESTATE mouseState;
};
#include "KaiganInputs.h"
/***************************************************************
class KInput - Handles All atributes of Inputs
***************************************************************/
KInput::KInput(HWND wHandle)
{
wndHandle = wHandle;
mouseState.lX = NULL;
mouseState.lY = NULL;
mouseState.lZ = NULL;
// Create Input Device
if(FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&pDXInput, NULL)))
return;
// Create Keyboard Device
if(FAILED(pDXInput->CreateDevice(GUID_SysKeyboard, &pDXKeyboard, NULL)))
return;
if(FAILED(pDXKeyboard->SetDataFormat(&c_dfDIKeyboard)))
return;
if(FAILED(pDXKeyboard->SetCooperativeLevel(wndHandle, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))
return;
// Create Mouse Device
if(FAILED(pDXInput->CreateDevice(GUID_SysMouse, &pDXMouse, NULL)))
return;
if(FAILED(pDXMouse->SetDataFormat(&c_dfDIMouse)))
return;
if(FAILED(pDXMouse->SetCooperativeLevel(wndHandle, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))
return;
if(FAILED(pDXMouse->Acquire()));
return;
}
KInput::~KInput()
{
if (pDXKeyboard)
pDXKeyboard->Release();
if(pDXMouse)
pDXMouse->Release();
if (pDXInput)
pDXInput->Release();
}
bool KInput::KeyboardState(int keyDown)
{
if(FAILED(pDXKeyboard->Acquire()))
return false;
if(FAILED(pDXKeyboard->GetDeviceState(sizeof(char[256]), (LPVOID)&keystate)))
return false;
if(keystate[keyDown])
return true;
return false;
}
bool KInput::MouseButtonState(int buttonDown)
{
if(FAILED(pDXMouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouseState)))
return false;
if(mouseState.rgbButtons[buttonDown])
return true;
return false;
}
long KInput::RelMouseX()
{
if(FAILED(pDXMouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouseState)))
return -2;
return mouseState.lX;
}
long KInput::RelMouseY()
{
if(FAILED(pDXMouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouseState)))
return -2;
return mouseState.lY;
}
long KInput::MouseScroll()
{
if(FAILED(pDXMouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouseState)))
return -2;
return mouseState.lZ;
}