I have a simple app that lives in the menu bar that I'm looking to listen to a return
key press when the user is in the browser (or anywhere, right now I just want it to fire). Adding a window
to applicationDidFinishLaunching
and having that window selected registers the keyDown
events but in actual use, the app won't have a UI and will just listen from the menu bar
When I remove the window
, the keyDown
function never fires.
Unsure of what I'm doing incorrectly here. Would love a hand. Thanks!
func applicationDidFinishLaunching(_ aNotification: Notification) {
NSEvent.addLocalMonitorForEvents(matching: .keyDown, handler: keyDown)
}
func keyDown(event: NSEvent) -> NSEvent {
NSLog("key down is \(event.keyCode)");
return event
}
Do I need to add this app to Accessibility settings? If so, I can't find the app to do so after a build and run.