My Cocoa application supports dropping files onto its Dock icon, but I'd like different behavior depending on whether a modifier key is held down (Command, Option, etc.).
I tried checking the modifierFlags
for the currentEvent
, but they are the same regardless of whether a modifier is held down, or not (I was testing with the Option key).
Code:
// Code is inside my AppDelegate
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)files {
BOOL optDown = (([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
== NSAlternateKeyMask);
NSLog(@"flags: %u, down? %@", [[NSApp currentEvent] modifierFlags],
optDown ? @"YES" : @"NO");
}
Output (dropping a file with the Option key down, then not):
flags: 1088, down? NO
flags: 1088, down? NO
Expected
flags: <not sure>, down? YES
flags: <different>, down? NO