Friday, 23 August 2013

Mouse events and switch

Mouse events and switch

I'm very very new to Cocoa and I'm looking for a way to execute an
applescript when the mouse is dragged, at a global level. I need this app
to be running all the time and it has no interface really, just running in
background and intercept mouse event in certain conditions.
So far, with this bit of code I can get close to what I want but the
applescript will be executed countless times instead of just once.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[NSEvent addGlobalMonitorForEventsMatchingMask:NSLeftMouseDraggedMask
handler:^(NSEvent *event) {
if (NSLeftMouseDragged) //with more conditions than that
NSAppleScript *run = [[NSAppleScript alloc]
initWithSource:@"MyScriptHere"];
[run executeAndReturnError:nil];
}
];
}
Then found that NSEvent has two ways to deal with mouse events. The "Three
Method Approach" which is probably what I'm doing and the "Mouse Tracking
Loop Approach" which use Switch and Case.
I don't know how to implement the latest in the
"applicationDidFinishLaunching" method. Could anyone help? Thanks

No comments:

Post a Comment