Skip to content

fix: Keyboard lost key-up bug - #2436

Merged
maximilien-noal merged 1 commit into
masterfrom
fix/keyboard_focus
Oct 22, 2026
Merged

maximilien-noal merged 1 commit into
masterfrom
fix/keyboard_focus

Conversation

@maximilien-noal

@maximilien-noal maximilien-noal commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Description of Changes

PS2Keyboard.cs (the core fix)

Added _pressedKeys — a HashSet tracking which keys the device believes are held.
EnqueueKeyEvent now adds/removes from the set (excluding the non-trackable None, Pause, PrintScreen).
Added ReleaseAllKeys() — emits a deterministic BREAK frame for each held key (sorted by enum order), then clears the set and resets the in-flight typematic repeat.
Wired _pressedKeys.Clear() + repeat reset into the buffer-overflow path in EnqueueScanCodeFrame, so a dropped key-up can't latch.
InputEventQueue.cs — added KeyboardDevice property and ReleaseAllKeys(), marshalled onto the emulator thread.

EmulatorMcpServices.cs — on pause (PauseHandler.Pausing), calls inputEventHub.ReleaseAllKeys().

MainWindowViewModel.cs / MainWindow.axaml.cs / Spice86DependencyInjection.cs — on window deactivation, calls inputEventHub.ReleaseAllKeys().

Rationale behind Changes

I fixed the lost-key-up bug by implementing a device-side release-all mechanism in the PS/2 keyboard, wired it to all three loss routes (window deactivation, pause, buffer overflow), and added tests. All new tests pass;

fixes #2407

Suggested Testing Steps

New file tests/Spice86.Tests/Emulator/Devices/Keyboard/PS2KeyboardReleaseAllKeysTests.cs (6 tests, all passing). The key engineering part was a controllable IEmulatedClock plus a drain helper that mimics what the guest does in INT9 (read 0x64, then 0x60), since the 8042's 0.3ms inter-byte delay and _waitingBytesFromKbd gating must be driven to observe the emitted scancodes.

@maximilien-noal maximilien-noal self-assigned this Oct 22, 2026
@maximilien-noal maximilien-noal added UI UI work input Emulator input method support bugfix fixes a bug keyboard related to keyboard handling and emulation labels Oct 22, 2026
@maximilien-noal
maximilien-noal merged commit f888005 into master Oct 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix fixes a bug input Emulator input method support keyboard related to keyboard handling and emulation UI UI work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stuck modifier keys: a lost key-up (focus loss, pause/resume, or input buffer overflow) leaves Alt/Ctrl/Shift latched in the guest indefinitely

2 participants