input-inject: protocol.md 10.5, feature README (assumptions, handshakes, work log), TODO ticks

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
lucioandClaude Opus 5 committed 2026-09-16 02:51:47 -07:00
1 parent d48f644450
commit f6fc2c5bd3
3 files changed
+321 -33

No files matched your search

+71
View File
@@ -781,3 +781,74 @@ sees them. One subsection per lane, appended, never rewritten.
sign convention of `scrollWheelEventFixedPtDeltaAxis2` against Windows'
"positive `WM_MOUSEHWHEEL` means scroll right" is **not yet verified** and
is a CP1 question.
### 10.5 input-inject (2026-09-16)
1. **The 10 ms sleep after a key-up never happens, on either side.**
`Event.KeybdEvent` sleeps 10 ms when `KeybdPackage.Kd.dwFlags is WM.WM_KEYUP
or WM.WM_SYSKEYUP` (`Event.cs:268-271`), i.e. when it equals 0x101 or 0x105.
But `dwFlags` on that path is the `LLKHF` bit field copied straight out of the
hook struct (`InputHook.cs:347`), whose only possible values are combinations
of `EXTENDED 0x01`, `INJECTED 0x10`, `ALTDOWN 0x20` and `UP 0x80` — never
0x101. The comparison is therefore always false and the sleep is dead code.
Neither the sender nor the receiver has anything to pace here; TODO §5's "10 ms
after key-up like Windows only if needed" is answered "not needed".
2. **The receiver intercepts four chords and eats three of them.**
`InputSimulation.InputProcessKeyEx` (`:372-475`) runs on every key *about to be
injected*: the receiver's own `HotKeyLockMachine` (`:406-416`) and Win+L
(`:450-460`) each set `eatKey`, call `ReleaseAllKeys` and `LockWorkStation`;
Ctrl+Alt+Del (`:440-448`) is eaten and only releases keys; Ctrl+Alt+End
(`:462-469`) starts the Windows service and is **not** eaten, so the key still
reaches the desktop. Locking on a remote chord is thus the *receiver's*
decision against the *receiver's* settings, not a packet type.
3. **The modifier state those chords match against is the remote keyboard's,
rebuilt from the wire.** Four booleans (`:358-361`) are driven only by the
side-specific VKs `LWIN/RWIN/LCONTROL/RCONTROL/LMENU/RMENU/LSHIFT/RSHIFT`
(`:380-398, 420-438`); the side-less `VK_SHIFT/CONTROL/MENU` do not touch them
even though `ReleaseAllKeys` (`InitAndCleanup.cs:225-229`) and the lock-chord
replay (`InputHook.cs:485-512`) both put those on the wire. They are a
*separate* set of facts from what the local keyboard is holding, which Windows
reads back with `GetAsyncKeyState`; `ResetModifiersState` (`:364-370`) edits
the first without touching the second.
4. **`SendMouse` fills in dx/dy for every message, and Windows uses them only for
moves.** `mi.dx/dy` are computed before the switch (`InputSimulation.cs:170-173`)
but `SendInput` ignores them unless `MOUSEEVENTF_MOVE` is set, which only the
`WM_MOUSEMOVE` case does (`:183-185`, `NativeMethods.cs:549`). So the position
in a button or wheel packet is discarded by a Windows receiver — confirmed by
`Receiver.cs:149-151`, which overwrites `Md.X/Y` from `GetCursorPos` before
calling `SendMouse` on the relative path. On macOS every mouse event carries a
location, so the equivalent is to post buttons and wheels at the **current
pointer**, never at the packet's coordinates.
5. **`MOUSEEVENTF_ABSOLUTE` is 0..65535 over the *primary* monitor, not the
desktop** (`NativeMethods.cs:561`; no `MOUSEEVENTF_VIRTUALDESK` anywhere in the
module). That is the whole reason `SendMouse` rescales the desktop rectangle
into primary units (`:165-171`) rather than mapping the universal value onto
the desktop directly. A macOS injector therefore lands an absolute move at
`Coordinates.fromUniversal(Coordinates.absoluteMove(u, desktop:, primary:),
in: primary)` — two steps, keeping the Windows rounding of each.
6. **The lock chord is replayed in a fixed, non-symmetric order**: Alt, Shift,
Win, Ctrl, then the key (`InputHook.cs:485-512`), with the ups sent in the
*same* order rather than reversed (`:548-562`), and with the side-less
`VK_MENU`/`VK_SHIFT`/`VK_CONTROL` plus `VK_LWIN`.
7. **macOS-side facts this lane established.**
- A modifier cannot be injected as a key press. `CGEvent(keyboardEventSource:
virtualKey:keyDown:)` for keycode 56 produces a `keyDown`, which is not how
anything on macOS learns that Shift is down; the event has to be re-typed to
`.flagsChanged`, and every *other* event we post has to carry the modifier
masks in `.flags` as well, because macOS keeps no global modifier state for
injected input the way `SendInput` does.
- **Click count is ours.** Windows drops `WM_*BUTTONDBLCLK` (no `MOUSEEVENTF`
case, `InputSimulation.cs:181-219`) and a double click travels as two plain
downs, so nothing on the wire says "double". macOS decides from
`mouseEventClickState`, so the receiver has to count consecutive downs of the
same button within `NSEvent.doubleClickInterval` and a few pixels, and repeat
the count on the matching up.
- `CGMouseButton` names only left/right/center, so an X-button event is created
as `.center` and corrected with `mouseEventButtonNumber` (3 or 4) afterwards.
- **Remote Win+L locks this Mac, and ⌘ is Win (README D4), so a remote ⌘L
locks it too.** Faithful to `:450-460`, and a CP1 question: on a Mac ⌘L is a
common application shortcut, so a Mac-to-Mac matrix may want this off.
- Whether the user's "natural scrolling" preference should apply to a remote
mouse's wheel is also a CP1 question; we post `.line` units with the sign the
capture side reads, so the two halves agree with each other whatever the
answer (see §10.4 note 10 for the still-unverified horizontal sign).