The easiest way to view global mouse events is to use the NSEvent addGlobalMonitorForEventsMatchingMask:handler: class method addGlobalMonitorForEventsMatchingMask:handler:
Example:
[NSEvent addGlobalMonitorForEventsMatchingMask:NSLeftMouseDraggedMask handler:^(NSEvent *event) { NSLog(@"Dragged..."); }];
Please note that this only works in other applications, in order to receive these events in your own application, you need to add an additional local event handler.
source share