Skip to content

Commit 943d499

Browse files
committed
Fix mouse buttons stick on low FPS
Thanks @Giperion Also remove code dublication when checking mouse hold
1 parent 7a1bb10 commit 943d499

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/xrEngine/Xr_input.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -517,20 +517,42 @@ void CInput::MouseUpdate()
517517
}
518518
}
519519

520-
if (mouseState[0] && mouse_prev[0])
520+
// Giperion: double check mouse buttons state
521+
DIMOUSESTATE2 MouseState;
522+
hr = pMouse->GetDeviceState(sizeof(MouseState), &MouseState);
523+
524+
auto RecheckMouseButtonFunc = [&](int i)
521525
{
522-
cbStack.back()->IR_OnMouseHold(0);
523-
}
526+
if (MouseState.rgbButtons[i] & 0x80 && mouseState[i] == FALSE)
527+
{
528+
mouseState[i] = TRUE;
529+
cbStack.back()->IR_OnMousePress(i);
530+
}
531+
else if (!(MouseState.rgbButtons[i] & 0x80) && mouseState[i] == TRUE)
532+
{
533+
mouseState[i] = FALSE;
534+
cbStack.back()->IR_OnMouseRelease(i);
535+
}
536+
};
524537

525-
if (mouseState[1] && mouse_prev[1])
538+
if (hr == S_OK)
526539
{
527-
cbStack.back()->IR_OnMouseHold(1);
540+
RecheckMouseButtonFunc(0);
541+
RecheckMouseButtonFunc(1);
542+
RecheckMouseButtonFunc(2);
528543
}
544+
//-Giperion
529545

530-
if (mouseState[2] && mouse_prev[2])
546+
auto isButtonOnHold = [&](int i)
531547
{
532-
cbStack.back()->IR_OnMouseHold(2);
533-
}
548+
if (mouseState[i] && mouse_prev[i])
549+
cbStack.back()->IR_OnMouseHold(i);
550+
};
551+
552+
isButtonOnHold(0);
553+
isButtonOnHold(1);
554+
isButtonOnHold(2);
555+
534556
if (dwElements)
535557
{
536558
if (offs[0] || offs[1])

0 commit comments

Comments
 (0)