unable to monitor events in command line tool app in macOS

71 Views Asked by At

New to macOS and trying some PoCs. Following is code that runs well if I choose the Project template as App, however, when I used Command Line Tool as the Project template in XCode, I do not receive events.

Accessibility access is enabled for my Application and there is no Sandboxing otherwise. I also tried to test addLocalMonitorForEvents in Command Line Tool App, and the result is same, no event.

Is there a restriction in using events' monitor in "Command Line Tool"?

               func event(e: NSEvent?) {
                print(e.windowNumber)
            }
            
            NSEvent.addGlobalMonitorForEvents(matching: [NSEvent.EventTypeMask.leftMouseDown], handler: event)
0

There are 0 best solutions below