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)
(DirectInput8) Mouse clicks :/
It is very simple to check if a mousebutton is being pressed, like:
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.
Jesus is Lord!!
Edit: Darn tags
[edited by - CD579 on January 24, 2004 5:49:13 PM]
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 declarationbool 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 framebool 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]
Above solution won''t work if the mousedown/mouseup both take place in the same frame. I suggest you look up buffered input in the SDK docs.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement