2

Are there any resources that might guide me in how to make my app respond to any type of mouse click that is not the left / right button? Globally, even when my app is not active.

And for magic mouse / trackpad, are there any frameworks or resources available to easily attach my code to a specific gesture?

2 Answers2

0

You can find everything related to mouse events: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/HandlingMouseEvents/HandlingMouseEvents.html

and trackpad events: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/HandlingTouchEvents/HandlingTouchEvents.html#//apple_ref/doc/uid/10000060i-CH13-SW10

Here is a stack overflow link that has explanation for handling global events.

Community
  • 1
  • 1
Shashank
  • 1,743
  • 1
  • 14
  • 20
  • The problem is I have no NSView or NSWindow, the event can happen in any active application. –  Feb 20 '13 at 10:15
  • Check this out http://stackoverflow.com/questions/4752427/osx-detect-system-wide-keydown-events-solved-with-sample-code – Shashank Feb 20 '13 at 10:26
  • Thanks, that's exactly it, and in the handler I just check [evt buttonNumber] to find the button that I need. –  Feb 21 '13 at 11:13
0

Here's a code example based on Shashank's (very helpful) answer.

NSEventMask eventMask = NSOtherMouseDownMask|NSOtherMouseUpMask;
[NSEvent addGlobalMonitorForEventsMatchingMask:eventMask
       handler:^(NSEvent *event) {
           if (event.type == NSOtherMouseDown) {
               NSLog(@"middle click down");
           } else if (event.type == NSOtherMouseUp) {
               NSLog(@"middle click up");
           }
       }];
zekel
  • 9,227
  • 10
  • 65
  • 96