sindresorhus / KeyboardShortcuts

⌨️ Add user-customizable global keyboard shortcuts (hotkeys) to your macOS app in minutes
https://swiftpackageindex.com/sindresorhus/KeyboardShortcuts/documentation/keyboardshortcuts/keyboardshortcuts
MIT License
1.99k stars 184 forks source link

Observe NSMenu #134

Closed decodism closed 1 year ago

decodism commented 1 year ago

Fixes #129

Also adds partial support for macOS 14. Menus have been rewritten and a local event monitor receives keyUp but not keyDown.

sindresorhus commented 1 year ago

Also adds partial support for macOS 14. Menus have been rewritten and a local event monitor receives keyUp but not keyDown.

Opened an issue: https://github.com/sindresorhus/KeyboardShortcuts/issues/135

sindresorhus commented 1 year ago

Seems to be working well. Thank you :)

sindresorhus commented 1 year ago

I have heard that this still works for observing key events in NSMenu on macOS 14:

let menuObserver = CFRunLoopObserverCreateWithHandler(nil, CFRunLoopActivity.beforeSources.rawValue, true, 0, { (observer, activity)
in
if let event = NSApp.currentEvent { ••• }
})
CFRunLoopAddObserver(CFRunLoopGetCurrent(), menuObserver, CFRunLoopMode.commonModes)