title: Why are NSResponder's keyboard actions not being called?
body: <p>NSResponder defines numerous actions that are related to keyboard actions like <code>moveUp:</code>, <code>moveUpAndModifySelection:</code> and <code>moveToBeginningOfLine:</code>. With the exception of the actions that aren't triggered by pressing a modifier key (e.x. <code>moveUp:</code> is simply the <code>Up</code> arrow key) I can't get any of the actions to be called on my custom <code>NSView</code>. </p>
  
  <p>Here's the setup: </p>
  
  <ul>
  <li>Xcode 5.1 / 10.9</li>
  <li>Basic Cocoa app with nothing more then a <code>Custom View</code> added to the main window.</li>
  <li>This custom view is just an <code>NSView</code> of class <code>STView</code></li>
  <li><code>STView</code> does nothing more than override <code>acceptsFirstResponder</code> to return <code>YES</code></li>
  </ul>
  
  <p>In this setup, my <code>STView</code> instance will correctly receive all keyboard events (including those with a modifier like <code>Ctl-A</code> in both <code>performKeyEquivalent:</code> and <code>keyDown:</code>, as expected. (Both methods are commented out for the discussion below.)</p>
  
  <p>If I provide an implementation for <code>moveUp:</code>, as defined in <code>NSResponder</code> then <code>moveUp:</code> is correctly called when the user presses the <code>Up</code> arrow key. </p>
  
  <p>Confusingly, <code>moveUp:</code> is also called whenever the <code>Up</code> arrow key is pressed with a modifier key. When a modifier key is being held (e.x.: <code>Ctl-Up</code>) I would expect the appropriate keyboard action method to be called.</p>
  
  <p>Ex: </p>
  
  <ul>
  <li><code>Ctl-Up</code> -> <code>moveUp:</code> (expected: <code>scrollPageUp:</code>)</li>
  <li><code>Alt-Up</code> -> <code>moveUp:</code> (expected: <code>moveToBeginningOfParagraph:</code>)</li>
  <li><code>Shift-Up</code> -> <code>moveUp:</code> (expected: <code>moveUpAndModifySelection:</code>)</li>
  <li><code>Command-Up</code> -> <code>moveUp:</code> (expected: <code>moveToBeginningOfDocument:</code>)</li>
  </ul>
  
  <p>This pattern repeats itself for all key/modifier combinations. </p>
  
  <p>Two areas in Apple's documentation seem relevant: </p>
  
  <ul>
  <li><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html" rel="nofollow">Handling Keyboard Actions and Inserting Text</a></li>
  <li><a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW10" rel="nofollow">The Path of Key Events</a></li>
  </ul>
  
  <p>Reading through that documentation, it looks like the system is responsible for mapping key events to their appropriate key action. And indeed, this works for me when a modifier key is not pressed. But when a modifier key is pressed, then the event is just being handled like any other event and passed through the normal responder chain. </p>
  
  <p>(I can see the modifier key event coming in through <code>NSApplication sendEvent</code>, though <code>NSApplication sendAction:to:from:</code> is never called, and continuing down the view hierarchy, which I would expect given my reading of the documentation above.  </p>
  
  <p>The documentation hints that text editing views might be treated differently. Are these keyboard actions only sent to views that edit text? If not, then how does one get a message like <code>moveUpAndModifySelection:</code> to be called on their custom <code>NSView</code> class when the user presses <code>Shift-Up</code>?</p>
  
  <p>For reference, I'm using this chart for keyboard bindings, though to be frank I've tried just about every combination, listed or not:  </p>
  
  <ul>
  <li><a href="http://www.hcs.harvard.edu/~jrus/site/system-bindings.html" rel="nofollow">Default Mac OS X System Key Bindings</a></li>
  </ul>
  
  <p>At the end of the day, I could likely just override <code>keyDown:</code> and manually handle all the combinations I'm interested in, but I was hoping to at least understand why this isn't working as intended for me. </p>
  
  <p>(Note that the intended application here is to allow the user to navigate a grid-like view of items, much like a collection view.) </p>
  
  <p>Any tips, advice or comments would be much appreciated. </p>
  
  <p><strong>Update:</strong></p>
  
  <p>If you do the following in your <code>keyDown</code></p>
  
  <pre><code>- (void)keyDown:(NSEvent *)theEvent {
    ...
    [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
  }
  </code></pre>
  
  <p>Then the "correct" actions will be called on your custom view. I assume this is because the actions I'm interested in are text-like actions, which require the input manager to interpret and convert to their appropriate actions. </p>
  
  <p>It's still not entirely clear to me why <code>moveUp:</code> is properly getting called. Who in the responder chain is recognizing the <code>Up</code> arrow key being pressed and then sending out a <code>moveUp:</code> message?</p>