keyboard/printer: release modifiers before pressing new ones (fixes pikvm/pikvm#1549)#229
Open
mawadSur wants to merge 1 commit into
Open
keyboard/printer: release modifiers before pressing new ones (fixes pikvm/pikvm#1549)#229mawadSur wants to merge 1 commit into
mawadSur wants to merge 1 commit into
Conversation
When typing/pasting text via /hid/print, switching from a character that needs AltGr (e.g. "}" on the Swedish layout = AltGr+0) to one that needs Shift (e.g. the double quote = Shift+2) caused Shift to be pressed before AltGr was released. For one moment both Shift and AltGr were held at once, which on ~20 layouts (cz, da, de, de-ch, es, fi, fo, fr-ca, fr-ch, hr, hu, is, it, lv, nl, no, pt, pt-br, sl, sv) produces a wrong symbol and corrupts all subsequent input. Fix the ordering so that no-longer-needed modifiers are always released before the required ones are pressed, eliminating the transient Shift+AltGr combination. Modifiers shared by consecutive characters are still kept pressed. Adds a regression test for the ordering and the no-overlap invariant. Fixes pikvm/pikvm#1549 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
Fixes pikvm/pikvm#1549.
Pasting/typing text via the Web UI Text feature (
POST /hid/print→text_to_evdev_keys) breaks the input when two consecutive characters need different modifiers. The classic repro on the Swedish layout is the sequence}":}= AltGr +0"= Shift +2After this sequence, all following input produces wrong characters until a modifier key is tapped. The reporter confirmed it on ~20 layouts:
cz, da, de, de-ch, es, fi, fo, fr-ca, fr-ch, hr, hu, is, it, lv, nl, no, pt, pt-br, sl, sv.Root cause
In
text_to_evdev_keys, the Shift modifier block was always handled before the AltGr block. When switching from an AltGr-character to a Shift-character, this pressedKEY_LEFTSHIFTbefore releasingKEY_RIGHTALT, so for one moment both Shift and AltGr were held at the same time — which selects a different symbol level on these layouts and corrupts subsequent input.This matches the
evtestcapture in the issue exactly (LEFTSHIFTdown emitted beforeRIGHTALTup):Fix
Release the modifiers that are no longer needed before pressing the newly required ones, so Shift and AltGr are never held simultaneously across a key switch. Modifiers shared by consecutive characters are still kept pressed (the existing optimization is preserved).
Resulting order for
}":Tests
Adds
testenv/tests/keyboard/test_printer.py:test_ok__printer_no_modifier_overlap— invariant (parametrized over several sequences): Shift and AltGr are never held at once, and everything is released at the end.test_ok__printer_release_before_press— asserts the exact corrected event order for}".test_ok__printer_keeps_shared_modifier_pressed— ensures a modifier shared by consecutive characters stays held.🤖 Generated with Claude Code