Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Shift + Return in NSTextView

I'm using the following code to detect the return key in a text view. How do you detect if the shift key is being pressed too?

- (BOOL)textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector
{
    if(commandSelector == @selector(insertNewline:))
    {
        // return key
        return YES;
    }

    return NO;
}
like image 290
Berry Blue Avatar asked Sep 06 '25 01:09

Berry Blue


1 Answers

subclass NSTextView and override flagsChanged with this

-(void) flagsChanged:(NSEvent *)theEvent {

    if ([theEvent modifierFlags] & NSShiftKeyMask && [theEvent modifierFlags] & NSCommandKeyMask) {

       NSLog(@"pressed");
    }
}
like image 76
Zag Avatar answered Sep 08 '25 22:09

Zag