Skip to main content
gamedev.net
🔒 Locked

DInput and mouse button issues

Started by MARS_999 Aug 10, 2006 at 3:37 AM 14 replies 2.8k views
Original Post
MARS_999
MARS_999
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
gammaGT
gammaGT
Hi,

are you using MDX or unmanaged?
--I love deadlines. I like the whooshing sound they make as they fly by. (Douglas Adams)
MARS_999
MARS_999
C++ Or I guess unmanaged?
MARS_999
MARS_999
*BUMP Thanks
Evil Steve
Evil Steve
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;
MARS_999
MARS_999
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...
ProgramMax
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.
ProgramMax
ProgramMax
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;

}
MARS_999
MARS_999
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
ProgramMax
ProgramMax
Or better yet, don't have gRotate = !gRotate;. Instead have gRotate = IsButtonDown;. It might be a little more clear and self-documenting.
ProgramMax
ProgramMax
NM ignore my last post. I keep thinking about the hold-to-rotate thing. gRotate = ! gRotate is correct for the click-to-toggle thing.
MARS_999
MARS_999
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
Endurion
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.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
MARS_999
MARS_999
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!! :)
ProgramMax
ProgramMax
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.
MARS_999
MARS_999
So far that seems to work ProgramMax... I will have to do more tests once my IB gets setup correctly. Thanks

Topic Locked

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

Sign in to reply to this topic.