• Advertisement
Sign in to follow this  

DInput and mouse button issues

This topic is 4269 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 am trying to have DInput set a variable to allow me to rotate when I click a button. As of now DInput with this function
if(directInput.mouseButtonDown(1))
		gRotate = !gRotate;

is causing me a headache, due to it returns everytime the button is down... Now the issue is unless you can tap it quick enough it jumps in and out of true/false so quick sometime it will rotate and sometimes not... So you have to keep clicking until it lands on true or false correctly. Do I need to do Mousebutton UP state? Or how do I go about fixing this... Thanks

Share this post


Link to post
Share on other sites
Advertisement
Personally, I have code that returns true only the first time the check is made, which is handy for UI stuff, etc.

Something like: input.DidButtonJustBecomePressed(MOUSE_Left);

It's easy enough to implement, but this would obviously be better done in the dinput class:

bool gRotate = false;
bool gRotating = true;

if(directInput.mouseButtonDown(1) && !gRotating)
{
gRotate = !gRotate;
gRotating = true;
}
else
gRotating = false;

Share this post


Link to post
Share on other sites
Hmm it still isn't working... Basically I hit the mouse button and its like its going to fast and it misses and doesn't register and then if I keep hitting it it will register... I still think its due to it ping pongs the true/false state...

Share this post


Link to post
Share on other sites
Are you saying that every time you call the function it returns true if the mouse button is down? And hence it is flipping the variable every time you poll?

If that's the case why not just:
g_IsRotating = blah.mouseButtonDown( 1 );

I must be missunderstanding the problem.

Share this post


Link to post
Share on other sites
Oh I am missunderstanding the problem. I reread your post and saw that you want a click to toggle wether or not you are rotating. So you can do this:

bool WasButtonDown( false );
bool IsButtonDown( false );

do // your loop
{

IsButtonDown = directInput.mouseButtonDown( 1 );
if( IsButtonDown != WasButtonDown )
{
// mouse button state has changed since we last polled
gRotate = !gRotate;
}
WasButtonDown = IsButtonDown;

}

Share this post


Link to post
Share on other sites
Quote:
Original post by ProgramMax
Are you saying that every time you call the function it returns true if the mouse button is down? And hence it is flipping the variable every time you poll?

If that's the case why not just:
g_IsRotating = blah.mouseButtonDown( 1 );

I must be missunderstanding the problem.


Yeah that works fine if you want to hold the button down while you rotate, but I want to click a button and then rotate and click again to shutdown the rotation. Hope that clears things up a bit...

On a side note I for some reason now when I alt-tab lose my screen size? What are cause of this? I had it working and now its messed up and I don't recall changing anything that would affect it. Thanks

Share this post


Link to post
Share on other sites
Or better yet, don't have gRotate = !gRotate;. Instead have gRotate = IsButtonDown;. It might be a little more clear and self-documenting.

Share this post


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

  • Advertisement