Repository navigation
Fix Windows Win/Meta shortcuts after keyboard input - #84
Conversation
Reviewer's GuideAPIAdd an optional injector lifecycle hook for resetting keyboard state before input arrives from a new server connection.
Uses of the APIInvoke the new-connection hook after a successful handshake so the active injector starts the session with fresh keyboard state.
ImplementationAdd 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.
Reset decoder format and meta state on new connections and disconnects, while leaving cursor Leave handling distinct from a connection reset.
TestsAdd decoder, injector-session, and HID regression tests for Windows mappings and shortcuts, connection resets, key release behavior, and compatibility with Linux, X11, and macOS.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>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.
|
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! 🍃 |
|
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. |
|
@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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
anasvhora284
left a comment
There was a problem hiding this comment.
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. 🍃
|
Thanks for the review and for merging! Really glad I could contribute. Looking forward to 1.4.7! 🍃 |
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
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:
Enhancements:
Tests: