Jump to content
  • Advertisement
Sign in to follow this  
mvtapia

dinput doesn't work

This topic is 4927 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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 );
}




Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!