On 2011 Oct 18, at 13:22, James Walker wrote:

> The only documented parameter in the kEventClassKeyboard / 
> kEventHotKeyPressed Carbon Event is
> 
>  kEventParamDirectObject (in, typeEventHotKeyID)
>       The ID of the hot key that was pressed.
> 
> That's the ID that was passed to RegisterEventHotKey.  That's what you should 
> use to distinguish different hot keys.

Aha!  In the header for RegisterEventHotKey(), I had read about that hot key ID 
parameter being somehow  available in the callback, but for the life of me I 
couldn't figure out how, because all its parameters are "opaque".  But thanks 
to your telling me what to look for, I found that the answer is: 
GetEventParameter().  Like this…

EventHotKeyID hotKeyID ;
OSStatus result = GetEventParameter(
                                    carbonEvent,
                                    kEventParamDirectObject,
                                    typeEventHotKeyID,
                                    NULL,
                                    sizeof(EventHotKeyID),
                                    NULL,
                                    &hotKeyID) ;
UInt32 keyID = hotKeyID.id ;

So now I set the hotKeyID.id to a unique value when registering each hot key, 
and pass an object which can decode the keyID and perform the desired function 
in the userData.  Key code and modifier flags are not necessary.

Jerry

P.S.  typeEventHotKeyID should be eventTypeHotKeyID

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to