Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

shrt

(DirectInput8) Mouse clicks :/

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

It is very simple to check if a mousebutton is being pressed, like:
	bool CInput::MouseButtonDown(int iButton)
	{
		if (m_MouseState.rgbButtons[iButton] & 0x80) {
			return true;
		} else
			return false;
	}
But how do I check if a mousebutton is clicked ? (definition of click: mousebtn down, then mousebtn up)

Share this post


Link to post
Share on other sites
Advertisement
I assume you are checking the state of the mouse each frame?(although we all know what happens when you assume)

Simply keep a state of the mouse from the previous frame and then it's simple logic from there.


bool CInput::MouseButtonDown(int iButton){
if (m_MouseState.rgbButtons[iButton] & 0x80) {
return true;
} else{
return false;
}
}

// note that the above can be reduced to:
bool CInput::MouseButtonDown(int iButton){
return m_MouseState.rgbButtons[iButton] & 0x80;
}
// but you should check the value of iButton to make sure
// you don't go outside the array and crash your program

// in class declaration
bool prevButtons[MAX_BUTTONS];


// loop through and copy the current buttons(& 0x80 them when
// you copy to turn it into a bool) to the prevButtons
// before you check the new state of the mouse

// Button was down last frame, and is up this frame
bool CInput::MouseButtonUp(int iButton){
return prevButtons[iButton] && (!m_MouseState.rgbButtons[iButton] & 0x80);
}


Jesus is Lord!!

Edit: Darn tags

[edited by - CD579 on January 24, 2004 5:49:13 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!