Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

directinput problems

Ok, simple. You look at my code, tell me what I did wrong, I learn something new, you gain the satisfaction of knowing that I will be back asking for more help very soon...

Note: I'm not sure if i have even defined everything correctly etc as i am only very new to directx and in particular directinput (this is the first time i've tried using directinput)

Here is the code for setting up direct input etc...



LPDIRECTINPUT8 lpdi;
LPDIRECTINPUTDEVICE8 lpdiKeyboard;
LPDIRECTINPUTDEVICE8 lpdiMouse;

DIMOUSESTATE MouseState;

///////////////////////////////
// DirectInput Init()
//
////////////////////////////////

bool DIInit(HWND hWnd)
{
if (FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION,
IID_IDirectInput8, (void**)&lpdi, NULL)))
return false;

// initialize the keyboard
if (FAILED(lpdi->CreateDevice(GUID_SysKeyboard, &lpdiKeyboard, NULL)))
return false;
if (FAILED(lpdiKeyboard->SetDataFormat(&c_dfDIKeyboard)))
return false;
if (FAILED(lpdiKeyboard->SetCooperativeLevel(hWnd, DISCL_BACKGROUND |
DISCL_NONEXCLUSIVE)))
return false;
if (FAILED(lpdiKeyboard->Acquire()))
return false;

// initialize the mouse
if (FAILED(lpdi->CreateDevice(GUID_SysMouse, &lpdiMouse, NULL)))
return false;
if (FAILED(lpdiMouse->SetCooperativeLevel(hWnd, DISCL_BACKGROUND |
DISCL_NONEXCLUSIVE)))
return false;
if (FAILED(lpdiMouse->SetDataFormat(&c_dfDIMouse)))
return false;
if (FAILED(lpdiMouse->Acquire()))
return false;

return true;
}

///////////////////////////
// Update DI devices
/////////////////////////////
UCHAR keystate[256];
DIMOUSESTATE mouse_state;

bool UpdateDeviceState(void)
{
if (FAILED(lpdiKeyboard->GetDeviceState(sizeof(UCHAR[256]), (LPVOID)keystate)))
return false;
if (FAILED(lpdiMouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouse_state)))
return false;

return true;
}


Now. Whenever I run the following function in the main program loop:



bool LMBDown()
{
if (MouseState.rgbButtons[0] & 0x80)
return TRUE;
else
return FALSE;
}


It appears to be returning false no matter wether I hold down LMB or not. Why?

Is this even the right approach to finding out wether or not the lmb is down?

Sign In or Register to comment.