I am new to Obj-C and Cocoa. I am trying to develop a very simple command line application that, when launched, waits for several global mouse events and exits. I implemented NSRunLoop correctly to close the cli application right away, but I cannot figure out how to listen for mouse events.
I am using this snippet:
[NSEvent addGlobalMonitorForEventsMatchingMask:NSMouseMovedMask handler:^(NSEvent *mouseEvent) {
NSLog(@"Mouse moved: %@", NSStringFromPoint([mouseEvent locationInWindow]));
}];
I am a CLI application, it just doesn’t start anything, although it compiles correctly, and it works just fine if it is inserted into an empty Cocoa application in the applicationDidFinishLaunching method in the appDelegate class.
What am I missing? Thank!
pd: I'm not 100% sure, this is the CLI that I need. I could also be an invisible or headless application, without a window, menu item, or anything related to what ever, is just a process that runs for a few seconds until the criteria are met.
source
share