Skip to content

Conversation

@haefele
Copy link
Owner

@haefele haefele commented Jan 22, 2026

…uilder

  • Add MapVirtualKey to NativeMethods.txt for scan code generation
  • Remove ABSOLUTE|VIRTUALDESK flags from mouse button/wheel (position sent separately)
  • Add scan code via MapVirtualKey in keyboard input
  • Add extended key check for 0xE000 prefix in unicode input
  • Update WindowsInputInjectionService to use new InputHelpers API

@greptile-apps
Copy link

greptile-apps bot commented Jan 22, 2026

Greptile Overview

Greptile Summary

Replaced H.InputSimulator library with custom InputHelpers using CsWin32-generated P/Invoke for direct Windows SendInput API calls. This eliminates an external dependency and provides more control over input injection.

Key changes:

  • Created new InputHelpers class with static methods for mouse/keyboard/unicode input
  • Migrated WindowsInputInjectionService to use InputHelpers instead of InputSimulator
  • Added MapVirtualKey to generate scan codes for keyboard input
  • Changed modifier tracking from VirtualKeyCode enum to ushort values
  • Removed H.InputSimulator package reference and license acknowledgment

Issues found:

  • Extended key detection incorrectly includes generic VK_CONTROL (0x11) and VK_MENU (0x12), which will cause left Control/Alt to be flagged as extended keys (should only apply to right variants 0xA3/0xA5)
  • Unicode input has incorrect extended key check for 0xE000 prefix - Unicode characters in that range are Private Use Area chars, not scan codes with extended key flags
  • Missing extended keys in detection: Windows keys (0x5B, 0x5C) and Apps key (0x5D)

Confidence Score: 2/5

  • This PR contains logic errors that will cause incorrect keyboard input behavior
  • Two critical logic errors exist: (1) Extended key detection incorrectly flags left Control/Alt keys, which will send wrong key events, and (2) Unicode input has meaningless 0xE000 check that confuses Unicode characters with scan codes. These will cause input injection to malfunction for common modifier keys and potentially certain Unicode characters.
  • Pay close attention to InputHelpers.cs - the extended key detection and Unicode input logic need fixes before merging

Important Files Changed

Filename Overview
src/RemoteViewer.Client/Services/InputInjection/InputHelpers.cs New input helper with two logic errors: incorrect extended key detection (includes generic VK_CONTROL/MENU) and wrong Unicode character check (0xE000 prefix is not for scan codes)
src/RemoteViewer.Client/Services/InputInjection/WindowsInputInjectionService.cs Successfully migrated from H.InputSimulator to custom InputHelpers, maintaining same functionality with cleaner code using pattern matching and direct Win32 calls

Sequence Diagram

sequenceDiagram
    participant App as Application
    participant WIIS as WindowsInputInjectionService
    participant Queue as BlockingCollection
    participant Thread as InputProcessor Thread
    participant IH as InputHelpers
    participant Win32 as Windows SendInput API

    App->>WIIS: InjectKey(keyCode, isDown)
    WIIS->>Queue: Add action to queue
    Queue->>Thread: GetConsumingEnumerable
    Thread->>Thread: CheckAndReleaseStuckModifiers()
    Thread->>IH: SendKeyDown(vk) or SendKeyUp(vk)
    IH->>IH: IsExtendedKey(vk)
    IH->>IH: CreateKeyboardInput(vk, flags)
    IH->>Win32: MapVirtualKey(vk, 0) for scan code
    Win32-->>IH: scan code
    IH->>IH: SendSingleInput(input)
    IH->>Win32: PInvoke.SendInput(input)
    Win32-->>IH: Result
    IH-->>Thread: Complete
    Thread-->>WIIS: Complete
    WIIS-->>App: Task.CompletedTask

    App->>WIIS: InjectText(text)
    WIIS->>Queue: Add action to queue
    Queue->>Thread: GetConsumingEnumerable
    Thread->>IH: SendUnicodeText(text)
    IH->>IH: CreateUnicodeInput for each char
    IH->>IH: SendInputs(inputs[])
    IH->>Win32: PInvoke.SendInput(inputs)
    Win32-->>IH: Result
    IH-->>Thread: Complete
    Thread-->>WIIS: Complete
    WIIS-->>App: Task.CompletedTask
Loading

@haefele haefele force-pushed the fix/input-helpers-match-h-inputsimulator branch from 6438b00 to ebdf3c5 Compare January 22, 2026 20:35
@haefele haefele enabled auto-merge (rebase) January 22, 2026 20:43
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@haefele haefele merged commit 07d14b9 into main Jan 22, 2026
2 checks passed
@haefele haefele deleted the fix/input-helpers-match-h-inputsimulator branch January 22, 2026 22:06
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