views:

13

answers:

1

Can i capture keyDown event when user drops a file on application icon in the dock?

For example, if user drops on application icon some files, that's handle with "method_one". And if user drops on application icon some files and holding the option key, that's handle with "method_two".

And all "UI" in this application it's just a dock icon. No windows, panels etc. thanks

A: 

One method you could use would be to poll the key state when your application starts up. NSEvent does not provide a way to do this without receiving an event first but you can use CGEvent. As discussed here, you can create a new event and poll its modifier keys. The code snippet looks like this:

CGEventRef event = CGEventCreate( NULL );
CGEventFlags mods = CGEventGetFlags( event );
if( mods & kCGEventFlagMaskShift )
    NSLog( @"Shift key is being pressed" );
CFRelease( event );
Jon Steinmetz
exactly what i'm need. thanks!
cru3l
unfortunately first line in snippet — `CGEventRef event = CGEventCreate( NULL );` cause memory leak. Did i need somehow `release` this `event`?
cru3l
Yes, sorry, I did not extend the snippet to be leak free. I modified my answer to include a CFRelease.
Jon Steinmetz