diff --git a/Sources/MWBMac/EventTap.swift b/Sources/MWBMac/EventTap.swift index 1e2aca4..fb4a017 100644 --- a/Sources/MWBMac/EventTap.swift +++ b/Sources/MWBMac/EventTap.swift @@ -296,7 +296,10 @@ public final class EventTap: @unchecked Sendable { if !isUp && !isRepeat, let match = matchHotkey(vk: vk, snapshot: snapshot) { if match.routesLocal { routing.routeLocal() } enqueue(.hotkey(match.action)) - return nil + // A hotkey that Windows lets through (`InputHook.cs:518-522`) is + // still sent and still typed here, as `ProcessHotKeys` returning + // `true` leaves it to `KeyboardEvent` and `CallNextHookEx`. + if match.swallows { return nil } } var flags: Int32 = isUp ? KeyFlag.up : 0 diff --git a/Sources/MWBMac/Hotkeys.swift b/Sources/MWBMac/Hotkeys.swift index 52a343f..6730ebe 100644 --- a/Sources/MWBMac/Hotkeys.swift +++ b/Sources/MWBMac/Hotkeys.swift @@ -21,11 +21,15 @@ public struct HotkeyMatch: Sendable, Equatable { /// Whether the tap must route control back to this Mac before returning /// (contracts C2). True for the escape set only. public var routesLocal: Bool + /// Whether the key event is eaten. True for every hotkey but one — see + /// `switchToAll` in `match(vk:…)` (`InputHook.cs:518-522`). + public var swallows: Bool /// A match. - public init(action: HotkeyAction, routesLocal: Bool = false) { + public init(action: HotkeyAction, routesLocal: Bool = false, swallows: Bool = true) { self.action = action self.routesLocal = routesLocal + self.swallows = swallows } } @@ -49,7 +53,8 @@ public struct HotkeyMatcher: Sendable { } /// Classifies one key-down. Returns `nil` when the key is an ordinary - /// keystroke; any non-`nil` result means the key is swallowed locally. + /// keystroke; a non-`nil` result means the key is a command, and its + /// `swallows` says whether it is also eaten. /// /// Windows checks in this order and so do we; only the order makes the /// `else if` chain in `ProcessHotKeys` behave (`InputHook.cs:516-624`). The @@ -63,7 +68,17 @@ public struct HotkeyMatcher: Sendable { return HotkeyMatch(action: .escapedToLocal, routesLocal: true) } if config.switchToAll.matches(vk: vk, modifiers: modifiers) { - return HotkeyMatch(action: .toggleSwitchToAll) // InputHook.cs:518-522 + // The one hotkey `ProcessHotKeys` does not eat: its branch + // (`InputHook.cs:518-522`) falls through instead of returning + // `false`, so the key still reaches the OS unless the chord itself + // holds Ctrl+Alt and is caught by the `if (CtrlDown && altDown)` + // block below (`:585-621`). Unreachable until a hotkey editor + // exists — `Switch2AllPCShortcut` ships empty + // (`MouseWithoutBordersProperties.cs:30`) and an empty hotkey never + // matches (`Common.cs:127-129`). + return HotkeyMatch( + action: .toggleSwitchToAll, + swallows: config.switchToAll.control && config.switchToAll.option) } if config.toggleEasyMouse.matches(vk: vk, modifiers: modifiers) { return HotkeyMatch(action: .toggleEasyMouse) // InputHook.cs:524-537 diff --git a/docs/features/input-capture/README.md b/docs/features/input-capture/README.md index a49ede3..07be5c5 100644 --- a/docs/features/input-capture/README.md +++ b/docs/features/input-capture/README.md @@ -112,6 +112,18 @@ code does not enforce is here. switch-machine is ignored when Shift or ⌘ is also held (`InputHook.cs:604-610`). Escape set (contracts C2): switch-machine naming the local slot while control is remote, and ⌃⌥⌘Escape, which is checked first so no veto can shadow it. + **Switch-to-all is the one hotkey that is not always swallowed**: its branch + in `ProcessHotKeys` (`InputHook.cs:518-522`) falls through instead of + returning `false`, so on Windows a chord that does not itself hold Ctrl+Alt + toggles ALL mode *and* reaches the OS. `HotkeyMatch.swallows` reproduces that: + true unless `switchToAll` requires neither ⌃ nor ⌥, in which case the tap + queues the action and then handles the key as an ordinary keystroke. app-shell + inherits this the moment it exposes a hotkey editor — the shortcut ships empty + (`MouseWithoutBordersProperties.cs:30`) and an empty hotkey never matches + (`Common.cs:127-129`), so nothing reaches it today. Windows' own swallow is + narrower still (the fall-through is caught only when the VK also lands in the + switch-machine range, `:611-620`); the ⌃⌥ test is the honest approximation and + the residual case is a hotkey editor's problem, not the wire's. - **Easy Mouse** (`EasyMouseOption.cs`, `InputHook.cs:467-473`): the tap pushes `.edgeCandidate(point:now:)` on moves only when the mode allows it — always for `Enable`, while ⌃ / ⇧ is held for those modes, never for `Disable` — and @@ -255,7 +267,9 @@ public final class EventTap: @unchecked Sendable { var unmappedKeyCount: UInt64 { get } static func now() -> TimeInterval // the lane's clock } -public struct HotkeyMatch: Sendable, Equatable { var action: HotkeyAction; var routesLocal: Bool } +public struct HotkeyMatch: Sendable, Equatable { + var action: HotkeyAction; var routesLocal: Bool; var swallows: Bool +} public struct HotkeyMatcher: Sendable { static let lockDoublePressWindow: TimeInterval // 0.5 var config: HotkeyConfig diff --git a/docs/protocol.md b/docs/protocol.md index 652231d..dcbc949 100644 --- a/docs/protocol.md +++ b/docs/protocol.md @@ -318,7 +318,12 @@ in relative mode (`Receiver.cs:156-170`). | `HotKeyExitMM` | 0 (disabled) | `Setting.cs:811-817` | Hotkeys are ignored if Shift or Win is also held with Ctrl+Alt -(`InputHook.cs:604-610`). Easy Mouse (`EasyMouseOption.cs`, default 1 = +(`InputHook.cs:604-610`). Every matched hotkey is swallowed except +`Switch2AllPCShortcut`: its branch (`InputHook.cs:518-522`) falls through +instead of returning `false`, so with a chord that does not itself hold Ctrl+Alt +the key toggles ALL mode *and* reaches the OS. Only reachable with a non-default +setting — the shortcut ships empty (`MouseWithoutBordersProperties.cs:30`) and +an empty hotkey never matches (`Common.cs:127-129`). Easy Mouse (`EasyMouseOption.cs`, default 1 = always): 0 disabled, 1 enabled, Ctrl/Shift variants require the modifier. ---