I created a subclass of nstextfield and I override the keydown event, but my code does not work, then I override the keyup event and the code works fine. My code (doesn't work):
-(void)keyDown:(NSEvent *)event { NSLog(@"Key released: %hi", [event keyCode]); if ([event keyCode]==125){ [[self window] selectKeyViewFollowingView:self]; } if ([event keyCode]==126){ [[self window] selectKeyViewPrecedingView:self]; } }
My activation code (it works):
-(void)keyUp:(NSEvent*)event {if ([event keyCode]==125){ [[self window] selectKeyViewFollowingView:self]; } if ([event keyCode]==126){ [[self window] selectKeyViewPrecedingView:self]; } if ([event keyCode]==36){ [[self window] selectKeyViewFollowingView:self]; } }
I do not see where the problem is with my code. Any suggestion will be accepted.
EDIT: I read that you need to subclass NSTextView instead of NSTextField.
source share