Skip to content

Fix Windows Win/Meta shortcuts after keyboard input - #84

Merged
anasvhora284 merged 2 commits into
anasvhora284:masterfrom
Kirara-kaka:fix/windows-meta-shortcuts
Nov 17, 2026
Merged

anasvhora284 merged 2 commits into
anasvhora284:masterfrom
Kirara-kaka:fix/windows-meta-shortcuts

Conversation

@Kirara-kaka

@Kirara-kaka Kirara-kaka commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Win/Meta shortcuts from a Windows Deskflow server can work once and then stop after the decoder learns the keyboard format. Ordinary Windows Set-1 scan codes overlap Linux evdev, so the decoder selects its evdev path. Extended Win codes (0x15b/0x15c) then pass through untranslated and cannot be sent as HID modifiers, while ordinary keys still use the HID keyboard.

Fix

Add a separate Windows Set-1 converter and identify that format when a known extended scan code matches the key's expected evdev position. This can refine the provisional evdev choice without reclassifying an established X11 or macOS connection. Translate Win, extended modifiers and navigation keys on the same physical keyboard path, retaining the existing paired key-up/repeat handling.

Validation

  • Added 16 tests covering Windows format detection, extended mappings, repeated Win+/, Win+Tab/Win+I after typing, right Win+Shift, leave/re-enter release behavior, and Linux evdev/X11/macOS compatibility.
  • The HID regression tests reproduced four Windows failures on the original implementation; the Linux/macOS cases passed.
  • All 238 keyboard/injection/HID-related tests pass after the fix.
  • WindowsScanCode has 22/22 executable lines and 12/12 branches covered; ProtocolScanCodeDecoder has 29/29 executable lines covered.
  • Full Windows JVM suite: 681 tests, 670 passed, 10 failed, 1 optional live-server test skipped. The 10 failures exactly match the unmodified upstream baseline: eight DataStore file-replacement failures and two TLS plaintext-detection fixture failures. No additional failures were introduced or suppressed. The full-suite coverage gate remains blocked by those existing test failures.
  • Release APK build and signature/alignment verification passed. The fix was manually verified on a Lenovo Xiaoxin 12.7 running DerpFest Android 17: Win combinations work repeatedly after typing, with no other issues observed so far.

Test APK

The side-by-side acceptance APK's package/signing adjustments are local build artifacts and are not part of this change.

AI Assistance

This fix and its regression tests were developed with assistance from OpenAI Codex. The changes were reviewed, and the fix was manually verified on a physical Android device.

Summary by Sourcery

Fix Windows keyboard shortcut handling by recognizing and translating Windows Set-1 scan codes without regressing other input formats.

Bug Fixes:

  • Restore reliable Windows Win/Meta shortcuts after ordinary keyboard input by detecting Windows Set-1 scan codes and translating extended modifiers and navigation keys correctly.
  • Reset keyboard decoding and modifier state at connection boundaries so reused injectors relearn each server's input format without affecting established X11, macOS, or Linux mappings.

Enhancements:

  • Add keypad Enter and divide scan-code mappings while preserving paired key-up, repeat, and leave/re-entry behavior across supported keyboard formats.

Tests:

  • Add regression coverage for Windows format detection, extended-key translation, repeated Win shortcuts, connection resets, release handling, and Linux/X11/macOS compatibility.

@sourcery-ai

sourcery-ai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

API

Add an optional injector lifecycle hook for resetting keyboard state before input arrives from a new server connection.

  • app/src/main/java/com/inputleaf/android/inject/InputInjector.kt L10-12

Uses of the API

Invoke the new-connection hook after a successful handshake so the active injector starts the session with fresh keyboard state.

  • app/src/main/java/com/inputleaf/android/service/ConnectionService.kt L312

Implementation

Add the Windows Set-1 mapping table and update scan-code decoding to recognize matching extended keys, translate them, and retain paired key handling without changing established X11 or macOS formats.

  • app/src/main/java/com/inputleaf/android/inject/KeyMapUtils.kt L29-30, L304-305
  • app/src/main/java/com/inputleaf/android/inject/ProtocolScanCodeDecoder.kt L33-39, L60-66 (+4 small edits)
  • app/src/main/java/com/inputleaf/android/inject/WindowsScanCode.kt L1-32

Reset decoder format and meta state on new connections and disconnects, while leaving cursor Leave handling distinct from a connection reset.

  • app/src/main/java/com/inputleaf/android/inject/AccessibilityInputInjector.kt L65-69, L92-93
  • app/src/main/java/com/inputleaf/android/shizuku/ShizukuInputInjector.kt L154-158, L222-223

Tests

Add decoder, injector-session, and HID regression tests for Windows mappings and shortcuts, connection resets, key release behavior, and compatibility with Linux, X11, and macOS.

  • app/src/test/java/com/inputleaf/android/inject/AccessibilityKeyboardSessionTest.kt L1-56
  • app/src/test/java/com/inputleaf/android/inject/KeyMapUtilsTest.kt L108-117
  • app/src/test/java/com/inputleaf/android/inject/ProtocolScanCodeDecoderTest.kt L102-198
  • app/src/test/java/com/inputleaf/android/inject/WindowsScanCodeTest.kt L1-37
  • app/src/test/java/com/inputleaf/android/shizuku/ShizukuInjectorHandoverTest.kt L5-7, L15-18, L135-191
  • app/src/test/java/com/inputleaf/android/shizuku/uhid/ProtocolKeyboardShortcutsTest.kt L1-204

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="app/src/main/java/com/inputleaf/android/inject/ProtocolScanCodeDecoder.kt" line_range="57" />
<code_context>
+        // when an extended scan code and its keysym agree; never reinterpret X11/Mac.
+        if (WindowsScanCode.matchesExtended(button, expected)) {
+            encoding = Encoding.WINDOWS
+            return
+        }
+        if (encoding != null) return
</code_context>
<issue_to_address>
**Reconnects use the old key format**

When the same injector reconnects to a server using a different scan-code format after learning Windows, the pressed-key reset leaves `encoding` as `WINDOWS`, so `ProtocolScanCodeDecoder` applies Set-1 translation to the new server’s buttons; X11/macOS keys and Linux evdev keys above `0x7f` are misdecoded or dropped, and shortcuts stop working.

Reset `encoding` when the injector connects to a server using a new scan-code format.

Also at `app/src/main/java/com/inputleaf/android/inject/ProtocolScanCodeDecoder.kt:38`, `app/src/main/java/com/inputleaf/android/inject/ProtocolScanCodeDecoder.kt:56`.
</issue_to_address>

### Comment 2
<location path="app/src/main/java/com/inputleaf/android/inject/ProtocolScanCodeDecoder.kt" line_range="55" />
<code_context>
         if (expected <= 0) return
+        // Ordinary Windows keys look like evdev. Upgrade that provisional choice
+        // when an extended scan code and its keysym agree; never reinterpret X11/Mac.
+        if (WindowsScanCode.matchesExtended(button, expected)) {
+            encoding = Encoding.WINDOWS
+            return
</code_context>
<issue_to_address>
**Keypad keys are not recognized as Windows**

When EVDEV is provisional or the encoding is unknown, and Windows keypad Enter or keypad slash arrives before another recognizable extended key, `learn` returns when `expected` is 0 before recognizing the extended Windows code, leaving the encoding unset or EVDEV; the key then maps to 0 or an unmapped extended button, so the virtual keyboard does not inject it.

Recognize these extended Windows codes before returning for an `expected` value of 0, and map them to their evdev codes.

Also at `app/src/main/java/com/inputleaf/android/inject/WindowsScanCode.kt:6`, `app/src/main/java/com/inputleaf/android/inject/WindowsScanCode.kt:8`.
</issue_to_address>

### Comment 3
<location path="app/src/main/java/com/inputleaf/android/inject/WindowsScanCode.kt" line_range="31" />
<code_context>
+        extendedEvdev[button] == expectedEvdev
+
+    fun toEvdev(button: Int): Int = extendedEvdev[button]
+        ?: if (button in 1..0x7f) button else 0
+}
</code_context>
<issue_to_address>
**Unmapped Windows extended keys are dropped**

When the decoder has selected Windows encoding and receives a valid extended scan code not listed in `extendedEvdev` with an unrecognized keysym, `WindowsScanCode.toEvdev` returns 0 for every extended code absent from `extendedEvdev`, and the Windows decoder uses that result instead of its pre-detection keysym-to-scan-code fallback. If an unsupported extended key has no recognized keysym, the injector receives no usable scan code and drops the key.

For unmapped Windows extended codes, preserve the existing keysym-based fallback or otherwise route them to a physical-key fallback instead of returning an unusable zero code.
</issue_to_address>

### Comment 4
<location path="app/src/main/java/com/inputleaf/android/inject/WindowsScanCode.kt" line_range="31" />
<code_context>
+        extendedEvdev[button] == expectedEvdev
+
+    fun toEvdev(button: Int): Int = extendedEvdev[button]
+        ?: if (button in 1..0x7f) button else 0
+}
</code_context>
<issue_to_address>
**Keypad navigation becomes keypad input**

When the Windows encoding has been learned and a keypad key is used with Num Lock off, `WindowsScanCode.toEvdev` returns the raw scan code for non-extended keypad keys, so with Num Lock off a Windows keypad 7 event carrying the Home keysym becomes evdev 71 (KP7), not 102 (Home). The HID path sends KP7 instead of the navigation key.

Use the keysym to disambiguate non-extended keypad scan codes whose meaning changes with Num Lock before injecting them as HID.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Reset learned scan-code encoding at a new server connection while retaining it across cursor Leave/Enter. Complete keypad Enter/divide scan-code mappings and add reconnect, wire-to-HID, fallback and cross-platform regression coverage.
@anasvhora284

Copy link
Copy Markdown
Owner

Hi @Kirara-kaka, a quick note on timing. My GitHub account has had a billing lock for the past two weeks (it's on the free plan with nothing owed, and I'm working with GitHub Support to get it lifted). Until it's fixed, GitHub Actions won't run, so CI checks, coverage and automated builds are stalled, and I'm holding off on merging and publishing releases.

1.4.6 is almost ready (PR #83): it finds the server on any network, follows it when its IP changes, and adds a Quick Settings tile, a custom cursor colour and number pad / Back-key fixes. An F-Droid listing is planned as well. It will go out as soon as the lock is lifted.

Thanks for the fix and the tests. It overlaps with files 1.4.6 touches, so I'll review it right after 1.4.6 and sort out any conflicts then.

Sorry for the delay, and thank you for your patience! 🍃

@Kirara-kaka

Copy link
Copy Markdown
Contributor Author

Thanks for the update! No worries about the delay. I appreciate your work on Input Leaf, and I'm happy to wait until 1.4.6 is released. I'll be glad to help resolve any conflicts or test further if needed.

@anasvhora284

Copy link
Copy Markdown
Owner

@Kirara-kaka 1.4.6 is out, so I'll review this PR next. Thanks for the detailed replies to the review comments, and for your patience!

@codecov

codecov Bot commented Nov 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@anasvhora284 anasvhora284 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Kirara-kaka, nice fix and great tests! The second commit covers the reconnect reset and the keypad keys Sourcery flagged, and your replies on the other two are right. All 707 unit tests pass on top of 1.4.6. I'll resolve the small overlap with my AltGr fix (#82) on my side. Merging, it'll ship in 1.4.7. 🍃

@anasvhora284
anasvhora284 merged commit cec3453 into anasvhora284:master Nov 17, 2026
5 checks passed
@Kirara-kaka

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for merging! Really glad I could contribute. Looking forward to 1.4.7! 🍃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants