dinput doesn't work

Started by
2 comments, last by Drew_Benton 18 years, 11 months ago
Hi everyone, the last couple of days I been trying to learn what some say is the most basic part of directx, dinput. Unfortunally, I have not been successfull. So far I initialize the directinput device, mouse and keyboard with no problem. I can even see that it works because if I change the mouse for exclusive to non exclusive, the mouse disappearse. The problem is I can't seem to retreive the data from either one of them. this is what I have written to retreive data:

void WINAPI ProcessKBInput(HWND hWnd)
{ 
if (KeyInit==true)
{
	if (hWnd != GetActiveWindow())
	{
		//MessageBox(NULL, "Not Active Window!", "Start", MB_OK);
		return;
	}

	hr = g_lpDIDevice->GetDeviceState(sizeof(keybuffer),(LPVOID)&keybuffer); 

	if FAILED(hr) 
	{ 
		SetAcquire(hWnd);
		// If it failed, the device has probably been lost. 
		// Check for (hr == DIERR_INPUTLOST) 
		// and attempt to reacquire it here. 
	} 

	if (KEYDOWN(keybuffer, DIK_ESCAPE))
	{
		PostQuitMessage(0);
		//exit(NULL);
		return;
	}
	if (KEYUP(keybuffer, DIK_ESCAPE))
	{
		//PostQuitMessage(0);
		//exit(NULL);
		return;
	}
}
return;
} 

//-----------------------------------------------------------------------------
// Name: OnMouseInput()
// Desc: Gets the Mouse Input
//-----------------------------------------------------------------------------

VOID OnMouseInput(HWND hWnd)
{ 
if (MouseInit==true)
{
	if (hWnd != GetActiveWindow())
	{
		//MessageBox(NULL, "Not Active Window!", "Start", MB_OK);
		return;
	}

	hr = g_pMouse->GetDeviceState(sizeof(mousebuffer),(LPVOID)&mousebuffer); 

	if FAILED(hr) 
	{ 
		SetAcquire(hWnd);
		// If it failed, the device has probably been lost. 
		// Check for (hr == DIERR_INPUTLOST) 
		// and attempt to reacquire it here. 
	} 

if (mousebuffer.rgbButtons[0] & 0x80)
{
  PostQuitMessage(0);
}
}
return;
}
I hope is not to long to read or to figure out. Maybe I'm just calling it in the wrong place. But when i call it it does go in the respective routines but it does not fill the buffer variable. Thank you in advance. [Edited by - Coder on April 26, 2005 10:46:41 PM]
Marco Tapia
Advertisement
A couple of things: you need to clear your keyBuffer to all zeros each time and you need your re-acquire loop to be working, it should look something like this:

HRESULT hr=m_diKeyboardDevice->GetDeviceState( sizeof(keys), keys );if (FAILED(hr)){       // If input is lost then acquire and keep trying until we get it back        hr=m_diKeyboardDevice->Acquire();       while( hr == DIERR_INPUTLOST )        {                      hr = m_diKeyboardDevice->Acquire();       }       // Now get them again       m_diKeyboardDevice->GetDeviceState( sizeof(keys), keys );}
------------------------See my games programming site at: www.toymaker.info
I'm sorry, the SetAcquire loop is like this..
 void SetAcquire(HWND hWnd){	if (hWnd != GetActiveWindow())	{		MessageBox(NULL, "Not Active Window!", "Start", MB_OK);		return;	}if (KeyInit==true){	hr = g_lpDIDevice->GetDeviceState(sizeof(keybuffer),(LPVOID)&keybuffer); 	if FAILED(hr) 	{ 		if (hr==DIERR_NOTACQUIRED || hr==DIERR_INPUTLOST)		{			while (hr == DIERR_INPUTLOST || hr==DIERR_NOTACQUIRED)					// if not acquired				hr = g_lpDIDevice->Acquire();					// get it back		}		else												// otherwise it was some other error			return;		// If it failed, the device has probably been lost. 		// Check for (hr == DIERR_INPUTLOST) 		// and attempt to reacquire it here. 	} }if(MouseInit==true){	hr = g_pMouse->GetDeviceState(sizeof(mousebuffer),(LPVOID)&mousebuffer); 	if FAILED(hr) 	{ 		if (hr==DIERR_NOTACQUIRED || hr==DIERR_INPUTLOST)		{			while (hr == DIERR_INPUTLOST || hr==DIERR_NOTACQUIRED)					// if not acquired				hr = g_pMouse->Acquire();					// get it back		}		else												// otherwise it was some other error			return;		// If it failed, the device has probably been lost. 		// Check for (hr == DIERR_INPUTLOST) 		// and attempt to reacquire it here. 	} }return;}



[Edited by - mvtapia on April 26, 2005 7:36:48 PM]
Marco Tapia
To post source code, you can use the [source] [/source] tags [smile]. You can edit your posts, so you can get more help [wink].

This topic is closed to new replies.

Advertisement