title: How do you use CGEventTapCreate in Swift?
body: <p>Has anyone managed to get this function to work in Swift?</p>
  
  <p>Here is a reference SO post from last year: <a href="https://stackoverflow.com/questions/26673329/using-cgeventtapcreate-trouble-with-parameters-in-swift">Using CGEventTapCreate Trouble with parameters in Swift</a></p>
  
  <p>Apple Doc: <a href="https://developer.apple.com/library/prerelease/mac/documentation/Carbon/Reference/QuartzEventServicesRef/index.html#//apple_ref/c/func/CGEventTapCreate" rel="noreferrer">https://developer.apple.com/library/prerelease/mac/documentation/Carbon/Reference/QuartzEventServicesRef/index.html#//apple_ref/c/func/CGEventTapCreate</a></p>
  
  <p>Here is how the CGEventTapCallBack is defined:</p>
  
  <pre><code>typealias CGEventTapCallBack = CFunctionPointer&lt;((CGEventTapProxy, CGEventType, CGEvent!, UnsafeMutablePointer&lt;Void&gt;) -&gt; Unmanaged&lt;CGEvent&gt;!)&gt;
  </code></pre>
  
  <p>Here is how I've written the block:</p>
  
  <pre><code>let eventTapCallBackBlock : @objc_block
  (CGEventTapProxy, CGEventType, CGEventRef, UnsafeMutablePointer&lt;Void&gt;) -&gt; CGEventRef =
  { (eventTapProxy: CGEventTapProxy, eventType: CGEventType, event: CGEventRef, refcon: UnsafeMutablePointer&lt;Void&gt;) in
    return event
  }
  </code></pre>
  
  <p>Then I've called CGEventTapCreate with the callback parameter like <code>unsafeBitCast(eventTapCallBackBlock, CGEventTapCallBack.self)</code></p>
  
  <p>I get a valid <code>CFMachPortRef</code> back, but at run time I get an access violation exception on first event. It would "seem" I'm close to a solution in swift in its current release state.</p>
  
  <p>Using Xcode Version 6.4</p>