title: NSTextField enter key detection or firstResponder detection
body: <p>I have two <code>NSTextField</code>s: <code>textFieldUserID</code> and <code>textFieldPassword</code>.</p>
  
  <p>For <code>textFieldPassword</code>, I have a delegate as follows:</p>
  
  <pre><code>- (void)controlTextDidEndEditing:(NSNotification *)aNotification
  </code></pre>
  
  <p>This delegate gets called when <code>textFieldPassword</code> has focus and I hit the enter key. This is exactly what I want. </p>
  
  <p>My problem is that <code>controlTextDidEndEditing</code> also gets called when <code>textFieldPassword</code> has focus and I move the focus to <code>textFieldUserID</code> (via mouse or tab key). This is NOT what I want.</p>
  
  <p>I tried using <code>controlTextDidChange</code> notification (which is getting called once per key press) but I was unable to figure out how to detect enter key ( <code>[textFieldPassword stringValue]</code> does not include the enter key). Can someone please help me figure this one out?</p>
  
  <p>I also tried to detect if <code>textFieldUserID</code> was a <code>firstResponder</code>, but it did not work for me. Here is the code I tried out:</p>
  
  <pre><code>if ( [[[self window] firstResponder] isKindOfClass:[NSTextView class]] &amp;&amp;
      [[self window] fieldEditor:NO forObject:nil] != nil ) {
      NSTextField *field = [[[self window] firstResponder] delegate];
      if (field == textFieldUserID) {
          // do something based upon first-responder status
          NSLog(@"is true");
      }
  }
  </code></pre>
  
  <p>I sure could use some help here!</p>