Skip to content

Fix global hotkey matching and event suppression#2

Draft
6BlackCats6 wants to merge 7 commits into
dmrkv:mainfrom
6BlackCats6:agent/fix-global-hotkey-matching
Draft

Fix global hotkey matching and event suppression#2
6BlackCats6 wants to merge 7 commits into
dmrkv:mainfrom
6BlackCats6:agent/fix-global-hotkey-matching

Conversation

@6BlackCats6

Copy link
Copy Markdown

Summary

  • consolidate the active global shortcut path around a single HotkeyManager
  • match both normalized modifier flags and the configured main key code
  • consume matching key-down, repeat, and key-up events with a CGEvent tap
  • retain intentional modifier-only shortcut behavior
  • suspend global matching while Settings records a shortcut
  • remove three unused hotkey-manager prototypes and their Xcode references
  • add permission-free regression tests for matching and consumption

Root cause

The running app creates SimpleAppDelegate, which in turn owned HotkeyManager. The stored shortcut included the main key code, but runtime matching only compared modifiers and was evaluated from flagsChanged. As a result, pressing Command alone matched Command+Space. The active NSEvent global monitor also could not suppress the foreground application's original event.

The new event processor requires an exact modifier-and-key-code match for ordinary shortcuts. The manager uses a default CGEvent tap and returns nil for matched events, so they are not delivered to the foreground app. Modifier-only shortcuts continue to use press/release transitions and remain pass-through.

Tests

The XCTest suite covers:

  • Command alone does not trigger Command+Space
  • Command+Space triggers exactly once
  • releasing Command does not trigger
  • Command plus an unrelated key does not trigger
  • a matched event is consumed
  • extra modifiers do not match
  • modifier-only press/release behavior remains supported

Validation completed on this host:

  • debug Swift build passed
  • release Swift build passed
  • permission-free event-processor smoke harness passed
  • git diff --check passed
  • Xcode project plist lint passed

Environment limitations

This host has only Apple Command Line Tools, so the XCTest target and full xcodebuild cannot run here without a full Xcode installation. A live end-to-end event-tap suppression check also requires a logged-in macOS GUI session with Accessibility permission.

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.

1 participant