title: Click-through buttons and not raising the window
body: <p>The iTunes mini-player (to give just one example) supports click-through where the application  isn't brought to the front when the play/pause and volume controls are used.</p>
  
  <p>How is this done?</p>
  
  <p>I've been looking through Apple's documentation and have a little to go on, in <a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW4" rel="nofollow noreferrer">Cocoa Event-Handling Guide, Event Dispatch</a> it states:</p>
  
  <blockquote>
    <p>Some events, many of which are defined by the Application Kit (type NSAppKitDefined), have to do with actions controlled by a window or the application object itself. Examples of these events are those related to activating, deactivating, hiding, and showing the application. NSApp filters out these events early in its dispatch routine and handles them itself.</p>
  </blockquote>
  
  <p>So, from my limited understanding (<a href="http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW1" rel="nofollow noreferrer">How an Event Enters a Cocoa, Application</a>) subclassing NSApplication and overriding
  <code>- (void)sendEvent:(NSEvent *)theEvent</code> should trap every mouse and keyboard event, but still, the window is raised on click. So either the window is raised before the event is seen by NSApplication or I'm missing something else. </p>
  
  <p>I've looked at Matt Gallagher's <a href="http://cocoawithlove.com/2009/01/demystifying-nsapplication-by.html" rel="nofollow noreferrer">Demystifying NSApplication by recreating it</a>, unfortunately Matt didn't cover the event queue, so other than that, I'm stumped.</p>
  
  <p>Any help would be appreciated, thanks.</p>
  
  <p><b>Edited to add:</b> Found a post at <a href="http://www.lloydslounge.org/entry.php?id=1099862874" rel="nofollow noreferrer">Lloyd's Lounge</a> in which he talks about the same problem and links to a post at <a href="http://www.cocoabuilder.com/archive/message/cocoa/2004/9/1/116398" rel="nofollow noreferrer">CocoaBuilder, capture first right mouse down</a>. I'm currently trying out the code supplied there, after some fiddling around and reactivating the NSLog for [theEvent type], the left mouse button activity is being caught.</p>
  
  <p>Now, left clicking on the window to bring it forward produces a sequence of event types, <code>13, 1, 13</code>, these are NSAppKitDefined, NSLeftMouseDown and NSAppKitDefined again. Can I filter these out or find where they are going?</p>