fix(input): keep held keyboard keys when pointer capture ends (#2779)

* fix(input): keep held keyboard keys when pointer capture ends

When a game gives up its pointer lock, Android pointer capture is
released and the session dropped every held input, including keyboard
keys. In a windowed session with Relative mouse on Auto, holding W to
run and releasing the mouse button after steering stopped the
character, because the key press is never sent again.

Losing pointer capture now releases only the mouse buttons, the pen and
the mouse back-button input. Keys are still released when the window
loses focus.

* fix(input): release held keys when pointer capture ends for the session menu

Opening the session menu releases pointer capture, and the menu then
consumes key events, including the key-up. A key held at that moment
would stay pressed in the guest after the menu closed. Capture loss with
the menu open now releases keys as before; other capture loss keeps them.

* fix(input): release held keys whenever another surface takes the keyboard

Capture loss released keys only while the session menu was open. The
other places that take input from the guest (on-screen keyboard,
achievements, input settings, WoW chat, touch editor, picture in picture)
have the same problem, so keys are now kept only when the session still
owns input and the game itself dropped its pointer lock.

* fix(input): release held keys when the session menu opens

While the menu is open it takes every key event, including the key-up,
so a key held when it opened stayed pressed in the guest. The keys are
now released when the menu opens, whether or not pointer capture was
active.

---------

Co-authored-by: zdennisz <15849186+zdennisz@users.noreply.github.com>
This commit is contained in:
Dennis Zabolotnyandzdennisz authored and GitHub committed 2026-11-18 09:53:39 -05:00
1 parent 0a167e41c2
commit 9e05e4c00c
2 files changed
+59 -4

No files matched your search

@@ -488,7 +488,10 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
}
drawerLayerOpen = false
drawerPinned = false
if (value) drawerDocked = dockDrawer() && openDockedMenu()
if (value) {
releaseHeldKeys()
drawerDocked = dockDrawer() && openDockedMenu()
}
drawerOpenState = value
if (!value && drawerDocked) closeDockedMenu()
}
@@ -825,7 +828,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
pointerCaptureRefused = false
if (usbMouse.active) updatePointerCapture()
} else {
releaseHeldGuestInput()
releaseHeldInputOnCaptureLoss()
uiHandler.postDelayed(::updatePointerCapture, 250)
}
}
@@ -5118,10 +5121,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private fun relativeMouseAttached(): Boolean = !isInMultiWindowMode && !glassesOutputActive && mouseAttached()
private fun sessionOwnsInput() =
resumed && !drawerOpen && !pcKeyboardOpen && !achievementsOpen && !inputSettingsOpen &&
!pipUi && !bottomOutputActive && !touchEditorOpen && !wowChatOnTop
private fun updatePointerCapture() {
if (!::surfaceView.isInitialized) return
val view = window.decorView
val want = (pointerLocked || relativeMouseAttached()) && resumed && hasWindowFocus() && !drawerOpen && !pcKeyboardOpen && !achievementsOpen && !inputSettingsOpen && !pipUi && !bottomOutputActive && !touchEditorOpen && !wowChatOnTop && mouseAttached()
val want = (pointerLocked || relativeMouseAttached()) && sessionOwnsInput() && hasWindowFocus() && mouseAttached()
releaseDesktopMouseGrab()
updateUsbMouse(want)
if (want == view.hasPointerCapture()) return
@@ -5444,14 +5451,26 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
private fun keyboardCoversPad() =
SessionState.mode == SessionService.MODE_STEAM && AgentGuest.steamKeyboard
private fun releaseHeldGuestInput() {
private fun releaseHeldInputOnCaptureLoss() {
if (sessionOwnsInput()) releaseHeldPointerInput() else releaseHeldGuestInput()
}
private fun releaseHeldPointerInput() {
mouseBackInput.cancel()
cancelPen(releaseKey = true)
heldButtons.release(1 or 2 or 8 or 16)
}
private fun releaseHeldKeys() {
guestKeysDown.toList().forEach { sendGuestKey(it, false) }
heldKeys.release(8 or 16 or 32)
}
private fun releaseHeldGuestInput() {
releaseHeldPointerInput()
releaseHeldKeys()
}
private fun sendGuestKey(key: Int, down: Boolean, owner: Int = 1) {
if (down && pipUi) return
val code = if (key == KEY_RIGHTCTRL && SessionState.mode == SessionService.MODE_DESKTOP) KEY_LEFTCTRL else key