Override keydownevent in NSTextfield
You can do it without subclassing by using NSTextFieldDelegate methods:
As @Darren Inksetter said, you can use control:textView:doCommandBySelector:
First, declare NSTextFieldDelegate in your interface tag. Then implement the method:
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector
{
if( commandSelector == @selector(moveUp:) ){
// Do yourthing here, like selectKeyViewFollowingView
return YES; // Return YES means don't pass it along responders chain. Return NO if you still want system's action on this key.
}
if( commandSelector == @selector(moveDown:) ){
// Do the same with the keys you want to track
return YES;
}
return NO;
}
The keydown event can't be overriden in a NSTextField, if you want , you could override the keydown event of the super view or you could use a NSTextView or just override the keyup event in the NSTextField
You will want to look at
control:textView:doCommandBySelector:
http://developer.apple.com/library/mac/#documentation/cocoa/reference/NSControlTextEditingDelegate_Protocol/Reference/Reference.html