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

using direct input in a multi threaded process

This topic is 4856 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 trying to use direct input 8 in a multithreaded process where a window created in another thread is the foreground/active window. I can't seem to get the cooperation modes right, and I've tried the 4 permutations of fore/background and [non]exclusive. the weird thing is, when I'm debugging my app, it works. I think this has something to do with the visual studio window being in the foreground. I'm puzzled, and I'm not that good with DX to begin with. any ideas? TIA

Share this post


Link to post
Share on other sites
Advertisement
when I pause my process and type anything in the debugger, keys I type get caught by GetDeviceData(). when I'm running my app normally, GetDeviceData() returns the count (dwCount) as zero. what would cause this behavior?

Share this post


Link to post
Share on other sites
Hello,

Well maybe the trouble is the way you are getting your device data, try using your GetDeviceData and Acquire methods inside a loop, to makesure DInput "catch" any inpu, like the following way:


while (1)
{
elements = 1;
hr = IDirectInputDevice7_GetDeviceData(in.keyboard, sizeof(DIDEVICEOBJECTDATA), &od, &elements, 0);

// if it did not work, try and re-acquire the device
if (FAILED(hr))
IDirectInputDevice7_Acquire(in.keyboard);

// If it failed, or there was no events, stop
if (FAILED(hr) || elements==0)
break;

// Process your data here
}



Hope that helps you,
Oscar

Share this post


Link to post
Share on other sites
I get the input in my window proc.
Pseudocode:


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



any ideas?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!