title: Why Doesn't Key Down Event Mask Work, but Mask All Does?
body: <p>I have a basic keystroke converter app in development. The conversion works with the following:</p>
  
  <pre><code>CFRunLoopSourceRef runLoopSource = NULL;
  CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, kCGEventMaskForAllEvents, myCGEventCallback, NULL);
  runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
  CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
  CGEventTapEnable(eventTap, true);
  </code></pre>
  
  <p>As you might expect, <code>kCGEventMaskForAllEvents</code> is constantly firing for any mouse movement or click in addition to the keyboard, and I suspect tying up system resources. I tried substituting <code>CGEventMaskBit(kCGEventKeyDown)</code>, which best I can tell from <a href="https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/c/tdef/CGEventType" rel="nofollow">Quartz Event doc on Event Types</a> is what I want, and would weed out mouse movements and clicks. Unfortunately, using this seems to just eat the keystrokes, rather than convert them.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>The following works, but I still don't understand why <code>CGEventMaskBit(kCGEventKeyUp)</code> by itself isn't the correct implementation.</p>
  
  <pre><code>CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(NX_SYSDEFINED)
  </code></pre>