title: Check modifierFlags of NSEvent if a certain modifier was pressed but no other
body: <p>I just experimented with the <code>addLocalMonitorForEventsMatchingMask:handler:</code> method in NSEvent and came across the following question: How do I find out if <strong><em>only</em></strong> certain modifiers were pressed?</p>
  
  <p>A short example to set this question into context: I wanted to listen for the shortcut "&#x2318;+W". Therefore I wrote the following code:</p>
  
  <pre><code>[NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask handler:^(NSEvent *theEvent) {
      if ([theEvent modifierFlags] &amp; NSCommandKeyMask &amp;&amp; [theEvent keyCode] == 13) {
          [self.window performClose:self];
      }
      return theEvent;
  }];
  </code></pre>
  
  <p>This works well, however the shortcut will be triggered, even if more modifier keys are pressed, e.g. "&#x2303;+&#x2318;+W" or "&#x21E7;+&#x2303;+&#x2325;+&#x2318;+W". Is there a way to circumvent this?</p>
  
  <p>A simple solution would be to check for all other modifier keys and ensure they are not pressed. This seems tedious and error prone - besides it's ugly enough as it is now with the unary "&amp;". In addition you may get into trouble if (for some reason) another modifier key is added to keyboard layouts.</p>
  
  <p>As always I'm thankful for any recommendations.</p>