// Make sure the mouse has been initialized
if( !m_bInitialized )
return FALSE;
// Get the state of the mouse into the key buffer
r = m_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &m_dims2 );
if( FAILED( r ) )
{
// If the device is not acquired...
if( r == DIERR_INPUTLOST || r == DIERR_NOTACQUIRED)
{
// ...then reacquire the device
while( r == DIERR_INPUTLOST || r == DIERR_NOTACQUIRED)
r = m_pMouse->Acquire();
if( SUCCEEDED( r ) )
m_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &m_dims2 );
else
return FALSE;
}
else
// ...Otherwise it was some other error
return FALSE;
}
// Check if the mouse was clicked
if( key & 0x80 )
return TRUE;
else
return FALSE;
Mouse clicking
I''m using Direct Input 8 to check the mouse for left clicks in my game for the purpose of navigating through a selection of menu screens. The problem I''m having is that when one button is clicked and the screen loads the next option menu, the button below that gets clicked too as the input is checked again and the mouse is still registered as being pressed. Is there a good way to reset the state of the mouse after each check so this doesnt happen?
Cheers
Dave
What I do is I store whether or not the mouse button was pressed down last frame. So to check for a click, I check to see if it is currently pressed, but wasn''t pressed last frame.
tj963
tj963
I''m pretty sure I have that.
The "hack" i have at the moment is to set a trigger when a mouse is clicked. It then will not accept mouse clicks for 6 or seven frames but that doesnt appear to work!
The "hack" i have at the moment is to set a trigger when a mouse is clicked. It then will not accept mouse clicks for 6 or seven frames but that doesnt appear to work!
Instead of just checking if the mouse is down, have a second variable that is for a "click". It gets set to true if the mouse is down, gets set to false when it gets accessed (when you check it, use a function), and can''t be set again until the mouse has been released (needing a thrid variable lock). That way you only get one "event" per mouse click. If the user double-clicks on a button then its their own fault.
Karg
Karg
// Make MouseDown either global, or static within the functionbool MouseDown = false;// Check if the mouse was clickedbool MouseClickedThisFrame = false;if (key & 0x80){ if (MouseDown == false) { MouseClickedThisFrame = true; } MouseDown = true;}else{ MouseDown = false;}return MouseClickedThisFrame;
Alan
I have done the following.
Then prior to getting the current mouse state I have
memcpy(&old_m_dims2, &m_dims2, sizeof(m_dims2));
MOUSEDOWN would not normally be used, however;
MOUSE_DOWN returns true if the mouse button is down
MOUSE_PRESS returns true if the mouse was pressed since was last checked
MOUSE_RELEASE returns true if the mouse was released since last checked
Thus your program would just use
if MOUSE_PRESS(MOUSE_LEFT) { ''do whatever}
Stephen
First add the following to an appropriate header file#define MOUSE_LEFT (0) // Standard mouse buttons#define MOUSE_MIDDLE (2)#define MOUSE_RIGHT (1)#define MOUSE_LLEFT (3) // Left side on 5 button mouse#define MOUSE_RRIGHT (4) // Right Side on 5 button mouse#define MOUSEDOWN(name,button)(name.rgbButtons[button] & 0x80)#define MOUSE_DOWN(button) (MOUSEDOWN(m_dims2,button))#define MOUSE_PRESS(button) ((MOUSEDOWN(m_dims2,button) && !MOUSEDOWN(old_m_dims2,button)))#define MOUSE_RELEASE(button) ((!MOUSEDOWN(m_dims2,button) && MOUSEDOWN(old_m_dims2,button)))DIMOUSESTATE2 old_m_dims2
Then prior to getting the current mouse state I have
memcpy(&old_m_dims2, &m_dims2, sizeof(m_dims2));
MOUSEDOWN would not normally be used, however;
MOUSE_DOWN returns true if the mouse button is down
MOUSE_PRESS returns true if the mouse was pressed since was last checked
MOUSE_RELEASE returns true if the mouse was released since last checked
Thus your program would just use
if MOUSE_PRESS(MOUSE_LEFT) { ''do whatever}
Stephen
ConClusion: make two DIMOUSESTATE2's
[edited by - pipo declown on September 15, 2002 3:39:18 PM]
[edited by - pipo declown on September 15, 2002 3:39:18 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement