Jump to content
  • Advertisement
Sign in to follow this  
Code-R

DInput8: Buffered, yet I'm missing keys

This topic is 4676 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

I'm using DInput 8 to get keyboard keys, and I run my input sampling thread at 15 Hz. I miss a noticable amount of key presses. Is there something wrong I'm doing with buffered mode? My initialization code:
if(FAILED(lpdi->CreateDevice(GUID_SysKeyboard, &lpdiKey, NULL)))
{
	; //do nothing
}
// Set the Data Format of the Keyboard
if(FAILED(lpdiKey->SetDataFormat(&c_dfDIKeyboard)))
{
	;// error
} // end if(Failed(SetDataFormat()))
//setup the buffer
// Set buffer size //
DIPROPDWORD Property;
Property.diph.dwSize = sizeof(Property);
Property.diph.dwHeaderSize = sizeof(Property.diph);
Property.diph.dwObj = 0;
Property.diph.dwHow = DIPH_DEVICE;
Property.dwData = 64;
if(FAILED(lpdiKey->SetProperty(DIPROP_BUFFERSIZE, &Property.diph)))
{
	;//error
}
// Set the Keyboard's Cooperation Level
if(FAILED( lpdiKey->SetCooperativeLevel(INPUT_DX8::hWnd, DISCL_BACKGROUND  |
   DISCL_NONEXCLUSIVE | DISCL_NOWINKEY)))
{
	;// error
} // end if(Failed(SetCooperativeLevel()))

// Acquire the Keyboard
if(FAILED(lpdiKey->Acquire()))
{
	;// error
} // end if(Failed(Acquire()))

My input polling function:
DWORD dwCount;
	DIDEVICEOBJECTDATA KeyboardData;
	if(INPUT_DX8::lpdiKey)
	{
		dwCount = 1;
		if(lpdiKey->GetDeviceData(sizeof(KeyboardData), &KeyboardData, &dwCount, 0) == DIERR_INPUTLOST)
		{
			//try to re-acquire the device
			if(FAILED(lpdiKey->Acquire()))
			{
				log("kb acq failed");//error
			}
		}
		while(dwCount) //while there is keyboard input in the buffer
		{
			//set the according state
			KeyboardState[KeyboardData.dwOfs] = (BYTE)(KeyboardData.dwData&0xff);
			//check for more
			dwCount = 1;
			lpdiKey->GetDeviceData(sizeof(KeyboardData), &KeyboardData, &dwCount, 0);
		}

Share this post


Link to post
Share on other sites
Advertisement
I'm pretty sure it's your use of GetDeviceData() that's at fault. You should be passing in an array of LPDIDEVICEOBJECTDATA and not just a single element.

You set your buffer to be 64 elements, so it makes sense to pass in an array of LPDIDEVICEOBJECTDATA of equivalent size.

Note that the 3rd parameter is actually in/out - you pass in the size of your array, and it'll modify it to indicate how much of that array it's used. Whilst highly unlikely with 15hz and 64 elements, the function can return DI_BUFFEROVERFLOW if you haven't given it enough space.

hth
Jack

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!