Pregunta

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;
}
¿Fue útil?

Solución

subclass NSTextView and override flagsChanged with this

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

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

       NSLog(@"pressed");
    }
}

Otros consejos

Swift 4

override func flagsChanged(with event: NSEvent) {

    if event.modifierFlags.contains(.shift) {
        print("shift!")
    }

    super.flagsChanged(with: event)
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top