• Advertisement
Sign in to follow this  

DInput and mouse button issues

This topic is 4181 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
NM ignore my last post. I keep thinking about the hold-to-rotate thing. gRotate = ! gRotate is correct for the click-to-toggle thing.

Share this post


Link to post
Share on other sites
That still didn't work... That issue is annyoning but this one where I alt tab is killing me. I narrowed it down to this code, if I comment it out works fine but use this code it doesn't allow me to alt tab back into the same screen mode? And I only call this code at initialization time?


unsigned int numModes = d3d9->GetAdapterModeCount(D3DADAPTER_DEFAULT, d3dDisplayMode.Format);
for(unsigned int i = 0; i < numModes; ++i)
{
// get the displaymode structure for this adapter mode
d3d9->EnumAdapterModes(D3DADAPTER_DEFAULT, d3dDisplayMode.Format, i, &d3dDisplayMode);
fout1 << endl;
fout1 << "Width = " << d3dDisplayMode.Width << endl;
fout1 << "Height = " << d3dDisplayMode.Height << endl;
fout1 << "Refresh Rate = " << d3dDisplayMode.RefreshRate << endl;
fout1 << "Format = " << d3dDisplayMode.Format << endl;
}



Thanks

Share this post


Link to post
Share on other sites
This code snippet only enumerates (lists) all available adapters and their supported display modes.

Are you perhaps using the d3dDisplayMode for your current mode as well? This enumeration changes that struct so you may end up not with the mode you wanted.

Share this post


Link to post
Share on other sites
Quote:
Original post by Endurion
This code snippet only enumerates (lists) all available adapters and their supported display modes.

Are you perhaps using the d3dDisplayMode for your current mode as well? This enumeration changes that struct so you may end up not with the mode you wanted.


Thanks that helped. I didn't know that would change the struct... I thought it would just update it with info you may need. Again thanks

Still mouse isn't working!! :)

Share this post


Link to post
Share on other sites
Hey. Sorry. Was a bit busy. The code I posted toggled with mouse state change. Not per click. Oops. Here is correct code.

bool gWasButtonPressed = false;
bool gIsButtonPressed = false;

gIsButtonPressed = directInput.mouseButtonDown( 1 );
if( gIsButtonPressed != gWasButtonPressed && gIsButtonPressed = false )
{
gRotate = ! gRotate;
}
gWasButtonPressed = gIsButtonPressed;

This should now only toggle if the mouse state changes in the depressed direction. You could change the end of the if to true if you wanted it to occur in the pressed direction.

Share this post


Link to post
Share on other sites
So far that seems to work ProgramMax... I will have to do more tests once my IB gets setup correctly. Thanks

Share this post


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

  • Advertisement