5.8.2 - AnalogCursor doesn't release mouse capture on viewport when releasing virtual gamepad accept button

Hey!

We noticed a regression when updating to 5.8.2 where the mouse capture on viewport is never released when pressing ‘A’ on an xbox gamepad (virtual game accept key) or ‘X’ on a dualsense gamepad

While investigating, I stumbled upon the CL 52358853 on Epic’s main branch : [Input] Have FPointerEvent::PressedButtons copy by value instead of store a pointer so that it will be thread safe in the future if there are input events are safe to be copied across different threads.

So now, when creating the FPointerEvent for the mouse event, the currently pressed buttons are copied. The event is then passed to FSlateApplication::ProcessMouseButtonUpEvent where the currently pressed mouse button was cleared before routing the event but now as the event is a copy, it’s not cleared in the copy that the event holds. To take that in account, in the same CL, in FSlateApplication::OnMouseUp, the pressed buttons are cleared from of the current mouse button before creating the event and sending it to ProcessMouseButtonUpEvent.

This pre-clear is not done in FAnalogCursor::HandleKeyUp that simulates the release of the left mouse button when releasing the virtual gamepad accept key. So the event is created with the pressed key still containing the left mouse button. The event will then be processed by the SceneViewport down the line (FSceneViewport::OnMouseButtonUp) and the mouse capture will not be released because it still sees that the left mouse button is pressed.

To fix this we made this change in FAnalogCursor::HandleKeyUp

TSet<FKey> PressedMouseButtons;
if (bIsPrimaryUser)
{
    PressedMouseButtons = SlateApp.GetPressedMouseButtons();
    PressedMouseButtons.Remove(EKeys::LeftMouseButton);
}
else
{
    PressedMouseButtons = FTouchKeySet::EmptySet;
}
 
FPointerEvent MouseEvent(
    SlateUser->GetUserIndex(),
    FSlateApplication::CursorPointerIndex,
    SlateUser->GetCursorPosition(),
    SlateUser->GetPreviousCursorPosition(),
    PressedMouseButtons,
    EKeys::LeftMouseButton,
    0,
    bIsPrimaryUser ? SlateApp.GetModifierKeys() : FModifierKeysState()

We just clear the left mouse button from the pressed buttons before creating the event.

Let me know if you need anything else.

Cheers,

Corentin

[Attachment Removed]

Steps to Reproduce

[Attachment Removed]

Hi,

Your fix looks good, I’ve checked that in at CL#58338881. Thanks for the report!

[Attachment Removed]