I have a few checkboxes along with textfields on a NSPanel that opens to get user parameters. As an option, I'd like the user to be able to set/unset all the checkboxes on the panel by holding the option key when they press any of the checkboxes.
I'm not sure where/how to check what the key board is doing when the user clicks the button.
check [NSEvent modifierFlags]...
if ([NSEvent modifierFlags ] & NSAlternateKeyMask)
{
//do something
}
Just my 2c, a Swift 3 version:
if NSEvent.modifierFlags().contains(NSEventModifierFlags.command) {
print("Bingo")
}
One can see the rest of the flags in the documentation for NSEventModifierFlags
.
Update: NSAlternateKeyMask
is now deprecated. Use NSEventModifierFlagOption
instead.
See NSEventModifierFlags for a complete overview about all modifier flags.
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