iOS: fix hardware keyboard keys getting stuck - #19441
Open
frees11 wants to merge 1 commit into
Open
Conversation
- Handle pressesCancelled as key release; UIKit delivers it instead of pressesEnded when the system interrupts a press, leaving the key latched in apple_key_state (libretro#16212) - De-dup key events per (timestamp, keycode, direction) instead of timestamp alone, which dropped the second of two keys pressed or released in the same frame - Reset keyboard state when the app resigns active, matching the macOS port
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes hardware keyboard keys staying "held" on iOS (#16212).
Three independent causes in the iOS keyboard path:
pressesCancelled:withEvent:was not implemented (App Store build path,HAVE_APPLE_STORE). UIKit deliverspressesCancelledinstead ofpressesEndedwhen the system interrupts a press (app switcher, keyboard-shortcut HUD, incoming call, ...). Without a handler the key stays latched inapple_key_state[]until it is pressed again — the emulated character keeps walking after the key was released.Key-event de-dup was global instead of per-key (non-store build path).
handleKeyUIEvent:/_keyCommandForEvent:drop any event carrying the same timestamp as the previous one. Two keys pressed or released within the same frame share a timestamp, so the second key's event was silently discarded — that key stayed stuck (lost key-up) or appeared dead (lost key-down). The de-dup is now keyed on (timestamp, keyCode, isKeyDown).Keyboard state was not reset on focus loss on iOS. The macOS port calls
apple_input_keyboard_reset()inapplicationWillResignActive(ui_cocoa.m); the iOS port only cleared stale touches. Keys held while switching away never received their release event. Now mirrored on iOS.Testing
Built with
HAVE_APPLE_STORE(public presses path) fromRetroArch_iOS13.xcodeprojand deployed to a physical iPhone 17 Pro Max (iOS 27.0 beta) with a USB-C HID keyboard case (Akko MetaKey). An instrumented run logging the press pipeline recorded 629 keypresses with 629 matching key-down and 629 key-up events — no stuck keys during fast direction mashing, and no keys latched after app switching. Before the patch, the stuck-direction repro of #16212 appeared within seconds of fast direction input.The non-store
handleKeyUIEvent:change is compile-tested only — that path is not built in the configuration I deployed.