Skip to main content
gamedev.net
🔒 Locked

Simple question about DirectInput8?

Started by Spoogy 1 reply 1k views
Original Post
Spoogy
Spoogy
Hi, If I set DirectInput cooperativelevel with DISCL_BACKGROUND and DISCL_NONEXCLUSIVE flags. Everything works perfect BUT! If I'm running in windowed mode and DISCL_BACKGROUND is implemented, then application receives input even it's not active. And when my window is not active I'm not updating the scene. So this causes a little problem. If I set cooperative flag DISCL_FOREGROUND among with DISCL_NONEXCLUSIVE then everything works fine until window loses its focus. And when it's activated again, DirectInput doesn't get keyboard state anymore?!? I'm aware that GetDeviceState returns DIERR_INPUTLOST if it cannot get device state, but even if I try to re-acquire device it doesn't help, UNTIL I set cooperativelevel again with DISCL_BACKGROUND flag, which gaves me same result if I use it in the first place (when initializing). So, what to do? I tried to set window to topmost before re-acquiring, but that didn't help either. Please, help ObiWan Kenobi. You are my only hope. :)
PumpkinPieman
PumpkinPieman
You should have the flags DISCL_FOREGROUND | DISCL_NONEXCLUSIVE, unless you have other purposes for your program. What your having problems with is acquiring the device, when you switch from foreground to background with the foreground flag the device itself loses it's focus. What you have to do is everytime the program updates the keyboard if it fails make it try and reacquire the keyboard. Like in this example.

	bool cKeyboard::tryUpdate()	{		return SUCCEEDED(keyboard->GetDeviceState(sizeof(m_keyboardstate),(LPVOID)&m_keyboardstate));	};	bool cKeyboard::Update()	{		assert(input != NULL);		if(tryUpdate() == false){			keyboard->Acquire();            if(tryUpdate() == false)				return false;		}		return true;	};


Hope that helped.

It should reacquire, unless there is something wrong with the keyboard structure. So I don't see why it would act up like that.
Spoogy
Spoogy
Thanks for your answer, but I just got it to work by my self.

I don't know why, but when GetDeviceState gives DIERR_INPUTLOST result and I re-acquired the keyboard, everything seemed to continue working normally, but nothing was stored in the keyboard buffer.

Then I changed that so, when GetDeviceState gives DIERR_INPUTLOST (it's when window losts its focus), program enters into while loop and repeatly(?) calls device->acquire();

That helped and now it's working fine. I don't understand why that one call in every main loop cycle wasn't enough earlier. I mean that, in main loop I call the GetDeviceState and check its return value. And if it was inputlost, then I acquired device ONCE, but it seems to be so, that has to be called repeatly(?) when in "inputlost" state.

Now it works. Thanks anyway.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.