Domanda

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;
}
È stato utile?

Soluzione

subclass NSTextView and override flagsChanged with this

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

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

       NSLog(@"pressed");
    }
}

Altri suggerimenti

Swift 4

override func flagsChanged(with event: NSEvent) {

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

    super.flagsChanged(with: event)
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top