title: NSTextView keyDown Event
body: <p>I want trigger the keyDown Event with every Key action. Therefore I have created a subclass of NSView. </p>
  
  <pre><code>@interface CodrTextView : NSView {
      NSTextField *lineNumberSpace;
      NSTextView *mainTextView;
  }
  
  - (id) initWithTextView:(NSTextView *)textView lineNumberSpace:(NSTextField *)textField;
  </code></pre>
  
  <p>I already have the method's:</p>
  
  <pre><code>- (id) initWithTextView:(NSTextView *)textView lineNumberSpace:(NSTextField *)textField {
     self = [self init];
     if (self){
         mainTextView = textView;
         lineNumberSpace = textField;
     }
     return self;
  }
  
  - (BOOL) acceptsFirstResponder {
     return YES;
  }
  
  - (BOOL)canBecomeKeyView {
     return  YES;
  }
  </code></pre>
  
  <p>My plan is to count the lines in the textView and write the numbers in the lineNumberSpace. I know that the methods work, because I have test it already with an IBAction on a button. This is the method:</p>
  
  <pre><code>- (long) getLineCount{
      NSString *content = [mainTextView string];
      NSUInteger numberOfLines, index, contentLength = [content length];
      for (index = 0, numberOfLines = 0; index &lt; contentLength; numberOfLines++){
           index = NSMaxRange([content lineRangeForRange:NSMakeRange(index, 0)]);
      }
  
      NSLayoutManager *layoutManager = [mainTextView layoutManager];
      NSUInteger numberOfGlyphs =[layoutManager numberOfGlyphs];
      NSRange lineRange;
      for (numberOfLines = 0, index = 0; index &lt; numberOfGlyphs; numberOfLines++){
           (void) [layoutManager lineFragmentRectForGlyphAtIndex:index
                                             effectiveRange:&amp;lineRange];
            index = NSMaxRange(lineRange);
      }
      numberOfLines++;
      return numberOfLines;
  }
  
  - (void)keyDown:(NSEvent *)event {
       NSMutableString *lineNumberString = [NSMutableString string];
       long numberOfLines = [self getLineCount];
  
       for (int i = 1; i &lt;= numberOfLines; i++){
           [lineNumberString appendString:([NSString stringWithFormat:@"%d \n", i])];
       }
       [lineNumberSpace setStringValue:lineNumberString];
  }
  </code></pre>
  
  <p>This method works surely. The problem is, with a button the number in the lineNumberSpace is changing correctly but with the keyDown Event it don't work. What is my mistake here?</p>