Sign in to follow this  

Two issues with dInput.

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

Alright, the first problem I'm having is recieving correct input from the mouse buttons. According to the system buttons 2 & 3 are being pressed all of the time. This is the only problem I'm having with the mouse structure, I'm having no problem with the x & y coords.
	bool cMouse::GetButtonState(int iButton)
	{
		if(m_pmousestate.rgbButtons[iButton] & 0xF0)
			return true;
		return false;
	};

Second problem is with the acquiring of the device; I assume that when you alt-tab out of a window a simple call to acquire will fix everything. Well, it doesn't.
	bool cMouse::tryUpdate()
	{
		return SUCCEEDED(mouse->GetDeviceState(sizeof(m_pmousestate),(LPVOID)&m_pmousestate));
	};

	bool cMouse::Update()
	{
		if(!tryUpdate() || (FAILED(mouse->Acquire()) && !tryUpdate()))
			return false;

		m_absolute.x += m_pmousestate.lX;
		m_absolute.y += m_pmousestate.lY;

		if(m_absolute.x < 0.0f)
			m_absolute.x = 0.0f;

		if(m_absolute.x > m_screen.x)
			m_absolute.x = m_screen.x;

		if(m_absolute.y < 0.0f)
			m_absolute.y = 0.0f;

		if(m_absolute.y > m_screen.y)
			m_absolute.y = m_screen.y;
		
		return true;

	};

I have the mouse updated every frame so it should reacquire it if it failed.

Share this post


Link to post
Share on other sites
Nope, that doesn't seem to do much more then what it did before. Let me clarify the problems I'm having. The first problem is with the mouse button states, I can move the mouse position around the screen without problem and they also return the correct values. As for the the mouse button states I pass these constants to find out the values for buttons 0 through 3. Just as a quick way of checking if I've pressed them I use sprintf to generate a string I display.

sprintf(DisplayStr, "Mouse B1: %i, B2: %i, B3: %i, B4: %i", (int)Mouse.GetButtonState(DIMOFS_BUTTON0),
(int)Mouse.GetButtonState(DIMOFS_BUTTON1),
(int)Mouse.GetButtonState(DIMOFS_BUTTON2),
(int)Mouse.GetButtonState(DIMOFS_BUTTON3));
TimeVerdana.Draw(DisplayStr, 0xFFFFFFFF, 10, 10, 20);







;
The button 0 value is always 0, the button 1 value changes depending on what part of the screen I'm on and it seems that the value for button 2 and 3 randomly happen.

The second problem I'm having is I guess reacquiring the mouse when a window program has been set to the background. The mouse update function is called once per frame so it should reacquire it when the next frame starts and it's in the foreground. But all it does is show a mouse cursor (which shouldn't happen because it's set to be exclusive) and the sprite that's drawn in the position it was last in before it was set to the background.
Edit: I figured it out, it seemed that the little piece of advice I got from someone didn't bother acquiring it once it was lost the first time. I just have to replace

if(!tryUpdate() || (FAILED(mouse->Acquire()) && !tryUpdate()))
return false;


with

if(tryUpdate() == false){
mouse->Acquire();
if(tryUpdate() == false)
return false;
}


[Edited by - PumpkinPieman on January 17, 2005 6:02:04 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Specchum
Regarding the acquire problem: Has the mouse been created with SetCooperativeLevel set to DISCL_EXCLUSIVE | DISCL_FOREGROUND flags?
Yeah, they are; I believe I fixed that problem. It had something to do with the order of execution in the if statement.

Share this post


Link to post
Share on other sites

This topic is 4715 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this