I am trying to get NSEvent to stop listening to local event. Is there a way to access the event after creating it?(which is what I unsuccessfully tried in removeEvent)
override func viewDidLoad() {
super.viewDidLoad()
NSEvent.addLocalMonitorForEvents(matching: .keyDown, handler: sayHello(event:))
}
func sayHello(event: NSEvent) -> NSEvent {
print("Welcome")
return event
}
@IBAction func removeEvent(_ sender: NSButton) {
let event = NSEvent.addLocalMonitorForEvents(matching: .keyDown, handler: sayHello(event:))
NSEvent.removeMonitor(event)
}