NSEvent global event monitoring in background NSEvent global event monitoring in background python python

NSEvent global event monitoring in background


As you said "Only when I click on the app in the Dock does it start receiving events" , that means the handler gets registered after you click on the app in the Dock.

So it depends on at which point in the code you are calling this : NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(NSLeftMouseDownMask, handler) ,that is registering the handler.

You should register the handler in appdidfinishlaunching function.