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:
1 parent
d48f644450
commit
f6fc2c5bd3
3 files changed
+321
-33
No files matched your search
@@ -101,17 +101,20 @@ concurrency, shared constants, checkpoints) is fixed in `docs/contracts.md`.
|
||||
controlling remote, restore; `HideMouse (50)`; clamp while
|
||||
controlled §5.3.
|
||||
|
||||
## 5. input-inject (mac) — `Sources/MWBMac/Injector.swift`, `KeyState.swift`
|
||||
## 5. input-inject (mac) — `Sources/MWBMac/Injector.swift`, `KeyState.swift` — done 2026-09-16
|
||||
|
||||
- [ ] `Keyboard` packet → `CGEvent` down/up via KeyMap; modifiers as
|
||||
- [x] `Keyboard` packet → `CGEvent` down/up via KeyMap; modifiers as
|
||||
`flagsChanged`; repeats as repeated downs; 10 ms after key-up like
|
||||
Windows only if needed.
|
||||
- [ ] `Mouse` packet → absolute move (de-normalise onto desktop bounds
|
||||
Windows only if needed. *(Not needed: the Windows sleep compares
|
||||
`LLKHF` bits against `WM_KEYUP` and never fires — §10.5 note 1.)*
|
||||
- [x] `Mouse` packet → absolute move (de-normalise onto desktop bounds
|
||||
§4.4), buttons with click-count, wheel (`WheelDelta`/120), X-buttons.
|
||||
- [ ] Reads the injected-event tag from `InputTypes.swift` (C4); tracks
|
||||
- [x] Reads the injected-event tag from `InputTypes.swift` (C4); tracks
|
||||
held keys/buttons; `releaseAll()` = `ReleaseAllKeys` for every
|
||||
recovery row in C2 plus switch/lock/mode change; remote Win+L ⇒
|
||||
lock (`CGSession -suspend`); remote Ctrl+Alt+Del ⇒ ignored, logged.
|
||||
*(`releaseAll()` and `lockThisMac()` are published; calling them on
|
||||
each recovery row is app-shell's wiring — see the lane's Handshakes.)*
|
||||
|
||||
## 6. app-shell (app + core + mac) — `Sources/mwb/*`, `Sources/MWBCore/Settings.swift`, `Sources/MWBMac/StatusItem.swift`, `Sources/MWBMac/SettingsWindow/*.swift`, `Sources/MWBMac/Notifications.swift`
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@ ignored, and `releaseAll()` — the `ReleaseAllKeys` of
|
||||
|
||||
## Assumptions
|
||||
|
||||
Written before the work; **amended 2026-09-16** where the code shipped
|
||||
differently. Each amendment is marked *(amended)* and explained in the
|
||||
work log.
|
||||
|
||||
- **One `CGEventSource(stateID: .hidSystemState)` per `Injector`, with
|
||||
`userData = InputTypes.injectedEventTag`** so every event it creates
|
||||
carries the tag in `eventSourceUserData` and the tap's `RealData`
|
||||
@@ -23,21 +27,36 @@ ignored, and `releaseAll()` — the `ReleaseAllKeys` of
|
||||
would `MapVirtualKey` them; we have no keycode to post). `LLKHF.UP`
|
||||
→ key up. Modifier VKs (`LSHIFT`…`RWIN`, `SHIFT`/`CONTROL`/`MENU`
|
||||
generic forms mapped to the left key) post as key events for the
|
||||
modifier keycode, which macOS delivers as `flagsChanged`; the injector
|
||||
keeps a `KeyState` of held modifiers and sets `event.flags` on
|
||||
**every** posted key and mouse event from it, otherwise ⌘C from a
|
||||
Windows keyboard arrives as a bare C. `EXTENDED` is informational
|
||||
here (the keycode already distinguishes keypad Enter etc.). Repeats
|
||||
arrive as repeated downs and are posted as such with
|
||||
modifier keycode, ***(amended)*** **re-typed to `.flagsChanged` before
|
||||
posting** — macOS does not do that conversion for us, and a `keyDown`
|
||||
for keycode 56 is not how anything learns that Shift is down
|
||||
(docs/protocol.md §10.5 note 7). The injector keeps a `KeyState` of
|
||||
held modifiers and sets `event.flags` on **every** posted key and mouse
|
||||
event from it, otherwise ⌘C from a Windows keyboard arrives as a bare
|
||||
C. ***(amended)*** `EXTENDED` is **not** informational: `VK_RETURN`
|
||||
with the bit set is the keypad's Enter, which is the one key the table
|
||||
cannot distinguish (`KeyMap.keycode(forVK:)` gives back the main
|
||||
Return). Repeats arrive as repeated downs and are posted as such with
|
||||
`keyboardEventAutorepeat = 1` after the first. The 10 ms sleep after
|
||||
key-up (`Event.cs:268-271`) is the sender's, not ours.
|
||||
key-up (`Event.cs:268-271`) is the sender's, not ours — and is dead
|
||||
code there too (docs/protocol.md §10.5 note 1).
|
||||
- **Caps Lock**: `VK_CAPITAL` down+up toggles; post the keycode pair
|
||||
and let the system toggle the LED state.
|
||||
and let the system toggle the LED state. ***(amended)*** The pair is
|
||||
posted as `.flagsChanged` like the other modifiers, and the injector
|
||||
also tracks the lock itself so `kCGEventFlagMaskAlphaShift` is set on
|
||||
the events it posts whether or not the hardware state followed.
|
||||
- **Mouse** (`InputSimulation.cs:160-219`): `dwFlags` is a `WM_*` id.
|
||||
`WM_MOUSEMOVE` with absolute coordinates → `Coordinates.fromUniversal`
|
||||
onto the **desktop** bounds (`:160-173`); with the relative bias →
|
||||
`WM_MOUSEMOVE` with absolute coordinates → ***(amended)***
|
||||
`Coordinates.absoluteMove(…)` onto the desktop and then
|
||||
`fromUniversal` over the **primary** bounds, because
|
||||
`MOUSEEVENTF_ABSOLUTE` is 0..65535 over the primary monitor and that
|
||||
second scaling is what `SendMouse` (`:165-173`) is undoing
|
||||
(docs/protocol.md §10.5 note 5); with the relative bias →
|
||||
delta applied to the current pointer (`Receiver.cs:147-153`); the
|
||||
result is clamped to the desktop union. A move while a button is held
|
||||
result is clamped to the desktop union. ***(amended)*** Buttons and
|
||||
wheels are posted at the **current pointer**, never at the packet's
|
||||
coordinates, because Windows discards those (§10.5 note 4). A move
|
||||
while a button is held
|
||||
posts the matching `*MouseDragged` type (macOS needs it for drags;
|
||||
Windows does not distinguish). Buttons: L/R/M down/up → the CG button
|
||||
types with `mouseEventButtonNumber` 0/1/2; `WM_XBUTTON*` with
|
||||
@@ -58,16 +77,29 @@ ignored, and `releaseAll()` — the `ReleaseAllKeys` of
|
||||
`/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession -suspend`
|
||||
rather than injecting the chord (which would open Spotlight-like
|
||||
shortcuts); Ctrl+Alt+Del is swallowed and logged; Ctrl+Alt+End
|
||||
(service start) is ignored (README D6).
|
||||
(service start) is ignored (README D6). ***(amended)*** A fourth chord
|
||||
belongs here: the **receiver's own `HotKeyLockMachine`**
|
||||
(`:406-416`), matched against the remote's modifiers and against
|
||||
*this* Mac's setting, which is how the lock hotkey actually reaches a
|
||||
peer (§10.5 note 2). `InjectorConfig.lockMachine` carries it.
|
||||
Ctrl+Alt+End is not eaten by Windows, so the key still posts here.
|
||||
- **`releaseAll()`** posts key-up for every key and button the injector
|
||||
believes is down — a superset of Windows' fixed modifier list
|
||||
(`InitAndCleanup.cs:214-243`) because a lost key-up for a letter is as
|
||||
bad as for Shift — then clears `KeyState`. Rate limit of once per 2 s
|
||||
(`:218`) is **not** ported: recovery must always work (C2).
|
||||
***(amended)*** Ordinary keys are released before modifiers, so a
|
||||
release cannot spell a shortcut on the way out, and the chord booleans
|
||||
are cleared afterwards (`ResetSystemKeyFlags`, `:477-480`) — Windows
|
||||
leaves them, but we have just released the keys they describe.
|
||||
- **Threading**: the injector is driven by the Engine actor and posts
|
||||
from its own serial `DispatchQueue`; posting is thread-safe but the
|
||||
bookkeeping is not, so all of it lives on that queue. Not `Sendable`
|
||||
beyond that queue.
|
||||
bookkeeping is not, so all of it lives on that queue. ***(amended)***
|
||||
The class is `@unchecked Sendable` (justified in the file header)
|
||||
rather than non-`Sendable`: `releaseAll()` has to be callable from the
|
||||
quit and signal handlers (C2, last row), which cannot hop onto an
|
||||
actor. `inject` is `async` onto the queue; the accessors and
|
||||
`releaseAll` are `queue.sync`.
|
||||
- **Cursor bounds** come from `ScreenLayout` passed in with each
|
||||
packet; the injector never calls `Screens` itself.
|
||||
|
||||
@@ -76,37 +108,219 @@ ignored, and `releaseAll()` — the `ReleaseAllKeys` of
|
||||
### Consumed
|
||||
|
||||
- `input-capture`: `InputTypes.injectedEventTag`, `WindowsMessage`,
|
||||
`KeyFlag`, `KeyMap.keycode(forVK:)`, `ScreenLayout`, and the promise
|
||||
that tagged events are passed through untouched.
|
||||
- `session-matrix`: `Coordinates.fromUniversal`, the relative-bias decode.
|
||||
- `wire-core`: `Packet.mouse` / `Packet.keyboard`.
|
||||
`KeyFlag`, `KeyMap.keycode(forVK:)`, `KeyMap` modifier VKs and device
|
||||
masks, `KeyMap.keypadEnterKeycode`, `Hotkey`/`HotkeyConfig`,
|
||||
`ModifierState`, `ScreenLayout`, `EventTap.now()` (the lane's
|
||||
monotonic clock), and the promise that tagged events are passed
|
||||
through untouched.
|
||||
- `session-matrix`: `Coordinates.absoluteMove`, `Coordinates.fromUniversal`,
|
||||
`Coordinates.isRelative` / `untagRelative`, `Coordinates.centre`.
|
||||
- `wire-core`: `Packet.type`, `Packet.mouse`, `Packet.keyboard`,
|
||||
`MouseData`, `KeyboardData`.
|
||||
|
||||
### Promised (to app-shell)
|
||||
|
||||
As shipped 2026-09-16. Two public types in `MWBMac`, both in the lane's
|
||||
own files; nothing else in the target changed.
|
||||
|
||||
```swift
|
||||
public final class Injector {
|
||||
public init()
|
||||
public func inject(_ packet: Packet, layout: ScreenLayout) // Keyboard or Mouse; anything else ignored
|
||||
public func releaseAll() // C2; safe to call any time
|
||||
public func lockThisMac() // CGSession -suspend
|
||||
public var droppedUnmappedKeys: UInt64 { get }
|
||||
public var remoteModifiers: ModifierState { get } // for the menu bar / debugging
|
||||
// MWBMac/Injector.swift
|
||||
public struct InjectorConfig: Sendable, Equatable {
|
||||
public var lockMachine: Hotkey // HotKeyLockMachine, matched on receive
|
||||
public init(lockMachine: Hotkey = HotkeyConfig().lock)
|
||||
}
|
||||
public final class Injector: @unchecked Sendable {
|
||||
public static let cgSessionPath: String
|
||||
public init(config: InjectorConfig = InjectorConfig())
|
||||
public func reconfigure(_ config: InjectorConfig)
|
||||
public func inject(_ packet: Packet, layout: ScreenLayout) // .keyboard / .mouse; else ignored
|
||||
public func releaseAll() // C2; any thread, blocks until posted
|
||||
public func lockThisMac() // CGSession -suspend
|
||||
public static func lockChord(for hotkey: Hotkey) -> [KeyboardData] // downs then ups
|
||||
public var canInject: Bool { get } // false ⇒ no CGEventSource, all injection is a no-op
|
||||
public var droppedUnmappedKeys: UInt64 { get }
|
||||
public var remoteModifiers: ModifierState { get }
|
||||
public var isHoldingAnything: Bool { get }
|
||||
}
|
||||
|
||||
// MWBMac/KeyState.swift
|
||||
public struct KeyDecision: Sendable, Equatable { // InputProcessKeyEx's verdict
|
||||
public var eatKey, releaseAllKeys, lockMachine: Bool
|
||||
public static let inject: KeyDecision
|
||||
}
|
||||
public struct KeyState: Sendable {
|
||||
public static let end, delete, letterL, shift, control, menu: Int32 // VK.cs
|
||||
public static let modifierVKs: Set<Int32>
|
||||
public static func reportsAsFlagsChanged(vk: Int32) -> Bool
|
||||
public static func normalise(vk: Int32) -> Int32 // side-less VK → left key
|
||||
public static func positionalFlags(forKeycode: Int64) -> UInt64
|
||||
public static let shiftMask, controlMask, optionMask, commandMask,
|
||||
numericPadMask, secondaryFnMask: UInt64
|
||||
public init()
|
||||
public private(set) var chord: ModifierState // the *remote* keyboard's modifiers
|
||||
public private(set) var heldKeys: Set<Int32>
|
||||
public private(set) var heldButtons: [Int64: Int64] // button → click count
|
||||
public private(set) var capsLockOn: Bool
|
||||
public mutating func process(vk: Int32, isUp: Bool, lockMachine: Hotkey) -> KeyDecision
|
||||
public mutating func resetChord(keeping: Hotkey); public mutating func resetChord()
|
||||
public func isHeld(_ vk: Int32) -> Bool
|
||||
public mutating func note(vk: Int32, down: Bool)
|
||||
public func releaseOrder() -> [Int32] // ordinary keys, then modifiers
|
||||
public mutating func buttonDown(_ number: Int64, clickState: Int64)
|
||||
public mutating func buttonUp(_ number: Int64) -> Int64
|
||||
public var draggingButton: Int64? { get }
|
||||
public func buttonReleaseOrder() -> [(number: Int64, clickState: Int64)]
|
||||
public var eventFlags: UInt64 { get }
|
||||
}
|
||||
public struct ClickTracker: Sendable {
|
||||
public static let movementTolerance: CGFloat // 4
|
||||
public var interval: TimeInterval // NSEvent.doubleClickInterval
|
||||
public init(interval: TimeInterval)
|
||||
public mutating func click(button: Int64, at: CGPoint, now: TimeInterval) -> Int64
|
||||
public mutating func reset()
|
||||
}
|
||||
```
|
||||
|
||||
Four deviations from the shape sketched at planning time, all deliberate:
|
||||
|
||||
- **`Injector` takes an `InjectorConfig`.** The receiver matches the
|
||||
lock hotkey itself (§10.5 note 2), so it needs that one setting; C4
|
||||
says a lane before app-shell takes a config struct rather than
|
||||
`Settings`.
|
||||
- **`Injector` is `@unchecked Sendable`**, so the quit and signal
|
||||
handlers of C2 can call `releaseAll()`.
|
||||
- **`KeyState` and `ClickTracker` are public.** They are the injector's
|
||||
state, but the Engine will want `remoteModifiers` and the menu bar
|
||||
`isHoldingAnything`, and a value type with no I/O is easier to reason
|
||||
about public than hidden.
|
||||
- **`Injector.lockChord(for:)` is a static encoder, not a send.** See the
|
||||
request below.
|
||||
|
||||
### Answering input-capture's open requests
|
||||
|
||||
1. *Every posted event carries `InputTypes.injectedEventTag`.* Done: the
|
||||
tag is on the single `CGEventSource` the injector owns, so every
|
||||
event it creates carries it, `releaseAll()`'s synthetic ups included.
|
||||
There is no code path that posts an event from another source.
|
||||
2. *`Injector` performs `.lockMachine` / `.lockAllMachines` by sending
|
||||
the chord.* **Partly declined, redirected to app-shell.** The
|
||||
injector has no peer connections and C1 says only the Engine stamps
|
||||
and distributes packets, so sending from here would be a contract
|
||||
violation. What ships instead is `Injector.lockChord(for:)`, the
|
||||
encoding half — Windows' `GetVkCodesList` order, downs then ups
|
||||
(`InputHook.cs:485-512, 548-562`) — which the Engine forwards, plus
|
||||
`lockThisMac()` for the local half.
|
||||
|
||||
### Requested of app-shell (open)
|
||||
|
||||
1. On `HotkeyAction.lockMachine`, forward `Injector.lockChord(for:
|
||||
settings.lockMachineShortcut)` to the machine in control. On
|
||||
`.lockAllMachines`, switch to ALL mode, forward the same chord,
|
||||
switch back, then call `Injector.lockThisMac()`
|
||||
(`InputHook.cs:544-566`).
|
||||
2. Call `injector.releaseAll()` on every C2 recovery row, and on every
|
||||
switch, mode change and lock — it is the `ReleaseAllKeys` those rows
|
||||
name.
|
||||
3. Hand `ScreenLayout` in on every `inject(_:layout:)` from
|
||||
`Screens.layout`; the injector never reads the displays itself.
|
||||
4. Map `Settings.HotKeyLockMachine` onto `InjectorConfig.lockMachine`
|
||||
and call `reconfigure(_:)` when it changes, or a remote lock chord
|
||||
will be matched against the default ⌘⌃⌥L.
|
||||
5. `canInject == false` means the process has no `CGEventSource`; show
|
||||
it next to the permissions state.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [ ] `Sources/MWBMac/KeyState.swift`: held keys/buttons, modifier flag
|
||||
- [x] `Sources/MWBMac/KeyState.swift`: held keys/buttons, modifier flag
|
||||
word, click-count tracking, remote-chord state
|
||||
(`InputSimulation.cs:358-475`, `InitAndCleanup.cs:214-243`).
|
||||
- [ ] `Sources/MWBMac/Injector.swift`: the tagged source, keyboard and
|
||||
- [x] `Sources/MWBMac/Injector.swift`: the tagged source, keyboard and
|
||||
mouse posting per Assumptions, wheel, clamping, `releaseAll`,
|
||||
`lockThisMac`, Ctrl+Alt+Del handling (`InputSimulation.cs:82-219,
|
||||
440-475`, `Receiver.cs:147-153`).
|
||||
- [ ] `docs/protocol.md`: append §10.5 with anything learned, cited.
|
||||
- [x] `docs/protocol.md`: append §10.5 with anything learned, cited.
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-09-16 — dev (lane `input-inject`, from 3c51e95)
|
||||
|
||||
Shipped `Sources/MWBMac/KeyState.swift` (362 lines) and
|
||||
`Sources/MWBMac/Injector.swift` (425 lines); no other source file
|
||||
touched. `tools/gates.sh` green. Nothing was run that posts a `CGEvent`,
|
||||
locks the screen or moves the cursor (CLAUDE.md invariant 5) — this lane
|
||||
was verified by building and by reading the Windows source, not by
|
||||
injecting.
|
||||
|
||||
**What was ported.**
|
||||
|
||||
- `InputSimulation.SendKey` (`:108-157`) → `Injector.injectKey` /
|
||||
`postKey`: `LLKHF.UP` → key up, `LLKHF.EXTENDED` used to pick the
|
||||
keypad's Enter over Return, `MapVirtualKey` dropped (macOS needs no
|
||||
scan code), unknown VKs counted rather than posted.
|
||||
- `InputSimulation.InputProcessKeyEx` (`:372-480`) → `KeyState.process`:
|
||||
the four intercepted chords, the side-specific modifier booleans,
|
||||
`ResetModifiersState`, `ResetSystemKeyFlags`.
|
||||
- `InputSimulation.SendMouse` (`:160-233`) and `MoveMouseRelative`
|
||||
(`:283-301`) → `Injector.injectMouse` and the `WM_*` switch, with the
|
||||
receive-side coordinate rules of `Receiver.cs:147-153`.
|
||||
- `InitAndCleanup.ReleaseAllKeys` (`:214-243`) → `Injector.releaseAll`.
|
||||
- `InputHook.GetVkCodesList` (`:485-512`) → `Injector.lockChord(for:)`.
|
||||
|
||||
**Decisions and deviations** (the amended Assumptions above say where;
|
||||
the reasoning here).
|
||||
|
||||
1. **Modifiers post as `.flagsChanged`, not as key presses.** The
|
||||
Assumptions said macOS "delivers" a modifier keycode as
|
||||
`flagsChanged`; it does not — that conversion has to be made by the
|
||||
poster. A `keyDown` for keycode 56 leaves every app believing Shift
|
||||
is up. The event is built with `CGEvent(keyboardEventSource:…)` and
|
||||
its `type` set to `.flagsChanged`; the flag word is still put on every
|
||||
other posted event, because injected input gets no global modifier
|
||||
state on macOS. Recorded as §10.5 note 7.
|
||||
2. **Absolute moves go through `Coordinates.absoluteMove` *and*
|
||||
`fromUniversal` over the primary bounds**, not `fromUniversal` over
|
||||
the desktop as the Assumptions said. `MOUSEEVENTF_ABSOLUTE` is
|
||||
0..65535 over the primary monitor, which is the whole reason
|
||||
`SendMouse` rescales the desktop into primary units; skipping the
|
||||
second step would have produced the right answer only when the
|
||||
desktop and the primary monitor are the same rectangle. §10.5 note 5.
|
||||
3. **Buttons and wheels are posted at the current pointer.** Windows
|
||||
computes a position for them and `SendInput` throws it away
|
||||
(§10.5 note 4); on macOS the location on a button event is load
|
||||
bearing, and the current pointer is the position the preceding move
|
||||
packet already put it at. This also makes the relative-mode path fall
|
||||
out for free — it is exactly what `Receiver.cs:149-151` does by hand.
|
||||
4. **`KeyState` keeps the chord booleans and the held-key set apart.**
|
||||
Folding them together looked tempting and is a bug: the lock hotkey
|
||||
runs `ResetModifiersState`, which would then delete keys from the
|
||||
release list while they are still physically down, and a modifier
|
||||
that is never released is exactly the failure invariant 3 forbids.
|
||||
Windows keeps them apart too — chord booleans vs `GetAsyncKeyState`.
|
||||
5. **`releaseAll()` releases ordinary keys before modifiers** and then
|
||||
clears the chord. Windows releases only its eleven modifier VKs and
|
||||
leaves the booleans; ours has to cover letters too because we, not
|
||||
the OS, are the only record of what we posted.
|
||||
6. **The 10 ms post-key-up sleep is not ported, and the TODO line that
|
||||
asked for it "only if needed" is answered no.** It is the sender's,
|
||||
and it is dead code on Windows as well: the condition compares
|
||||
`LLKHF` bits against `WM_KEYUP`. §10.5 note 1.
|
||||
7. **Click counting and `NSEvent.doubleClickInterval`** are as the
|
||||
Assumptions describe; the clock is `EventTap.now()` (monotonic) so an
|
||||
NTP step cannot manufacture a double click. The click count is
|
||||
remembered per button so the *up* repeats it, which AppKit requires.
|
||||
8. **Positional flags** (`NumericPad`, `SecondaryFn`) are synthesised
|
||||
from the keycode for the keypad, the arrows, the navigation block and
|
||||
the function keys — real macOS events carry them and some text views
|
||||
read them. Windows has no equivalent; this is the mirror image of
|
||||
input-capture synthesising `LLKHF_EXTENDED` (§10.4 note 6).
|
||||
9. **Two CP1 questions recorded, not decided**: remote ⌘L locks this Mac
|
||||
(faithful to Win+L with D4's Win=⌘, but ⌘L is a common Mac shortcut),
|
||||
and whether "natural scrolling" should apply to a remote wheel.
|
||||
|
||||
**Open handshake requests** are in Handshakes above: five to app-shell,
|
||||
and input-capture's request 2 partly declined with a redirect (the
|
||||
injector encodes the lock chord, the Engine sends it).
|
||||
|
||||
## QA log
|
||||
|
||||
## Review
|
||||
@@ -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).
|
||||
Reference in new issue
Block a user