Re: Installing multiple hotkeys in app
Re: Installing multiple hotkeys in app
- Subject: Re: Installing multiple hotkeys in app
- From: Bill Cheeseman <email@hidden>
- Date: Sun, 04 Jan 2004 07:28:48 -0500
on 2004-01-04 6:05 AM, Dale Gillard at email@hidden wrote:
>
I've got one hotkey installed in my test app and it works fine. Now
>
I've moved onto installing a second hotkey into my test app. This is to
>
verify that multiple hotkeys can be added to an app, as well as to help
>
me figure out what code can be factored into a single reusable 'install
>
hotkey' method for installing multiple hotkeys. But I can't seem to
>
have 2 hotkeys installed at once - the last installed hotkey overrides
>
the first!
I have no difficulty with two hot keys installed at once.
I haven't parsed your code carefully, but I do notice one significant
difference between the way you're doing it and the way I do it. I declare
the following as global variables, whereas you declare them locally: the
UInt32 hot key identifiers, the UInt32 hot keys, the eventHotKeyRefs, the
EventHotKeyID, the EventHandlerUPP, and the handler function. I don't recall
whether this makes a difference, but I think that at least some of them do
have to be declared globally.
I use a single hot key handler, which takes variables to distinguish which
hot key is which.
There are two sets of sample code from Apple for hot keys. One is
UIElementInspector. I don't recall the other.
There is one conceptual issue you need to tackle. As I understand it, these
hot keys are global to all applications -- at least they were in Jaguar. So,
as a good Mac citizen, your app needs to be careful not to use up a lot of
hot keys in the global hot key space. If another developer's app uses the
same hot keys, both his app and yours will respond to the same hot key, in
an undefined order, potentially leading to mayhem. Apple's documentation
warns about this somewhere, with a faint suggestion that a future version of
Mac OS X may deal with the issue.
One thing I believe any app should do, if it implements global hot keys, is
to provide a preference where the user can change the hot keys in case this
sort of conflict arises. You can see the UI that I implemented for this by
downloading the trial version of PreFab UI Browser
<
http://www.prefab.com/uibrowser> and looking at the Hot Keys tab in
Preferences.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.