Cocoa noob here. I'm wondering how I can capture the Enter
and tab
keys onKeyDown whilst the user is typing in an NSTextView?
Thanks!
The easiest way is to implement the - (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector
delegate method and look for the insertNewline:
and insertTab:
selectors.
- (BOOL)textView:(NSTextView *)aTextView doCommandBySelector:(SEL)aSelector
{
if (aSelector == @selector(insertNewline:)) {
// Handle the Enter key
return YES;
} else if (aSelector == @selector(insertTab:)) {
// Handle the Tab key
return YES;
}
return NO;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With