• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to get key code from "SysDefined" Carbon Event
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get key code from "SysDefined" Carbon Event


  • Subject: Re: How to get key code from "SysDefined" Carbon Event
  • From: Jerry Krinock <email@hidden>
  • Date: Tue, 18 Oct 2011 21:21:10 -0700

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 (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to get key code from "SysDefined" Carbon Event
      • From: Ken Thomases <email@hidden>
References: 
 >How to get key code from "SysDefined" Carbon Event (From: Jerry Krinock <email@hidden>)
 >Re: How to get key code from "SysDefined" Carbon Event (From: James Walker <email@hidden>)

  • Prev by Date: Re: Custom NSArrayController that manages its own array?
  • Next by Date: Re: How to get key code from "SysDefined" Carbon Event
  • Previous by thread: Re: How to get key code from "SysDefined" Carbon Event
  • Next by thread: Re: How to get key code from "SysDefined" Carbon Event
  • Index(es):
    • Date
    • Thread