Installing multiple hotkeys in app
Installing multiple hotkeys in app
- Subject: Installing multiple hotkeys in app
- From: Dale Gillard <email@hidden>
- Date: Sun, 4 Jan 2004 22:05:50 +1100
Hi all
I'm figuring out how to use the Carbon HotKey APIs. (How I wish Apple
would have added this to Cocoa at the same time they added it to Carbon
in 10.2!).
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!
The code below (partial but mostly complete) works, but the second
hotkey overrides the first even though I've given them different
variables and handlers, and limited their scope inside two methods.
I've checked the Carbon ref material re: the parameters I'm passing and
can't understand why this code doesn't provide me with two hotkeys.
I'd appreciate any suggestions to help solve this impasse.
Thanks in advance.
Dale
//
------------------------------------------------------------------------
-------------------------------------------------------
pascal OSStatus AW6HotKeyHandler(EventHandlerCallRef nextHandler,
EventRef theEvent, void *userData);
pascal OSStatus ClassicAW6HotKeyHandler(EventHandlerCallRef
nextHandler, EventRef theEvent, void *userData);
- (void)registerAW6HotKey
{
const UInt32 kAW6HotKeyIdentifier = 'sAW6';
const UInt32 kAW6HotKey = 22; // The 6 key
EventHotKeyRef gAW6HotKeyRef;
EventHotKeyID gAW6HotKeyID;
EventHandlerUPP gAW6HotKeyFunction;
EventTypeSpec eventType;
gAW6HotKeyFunction = NewEventHandlerUPP(AW6HotKeyHandler);
eventType.eventClass = kEventClassKeyboard;
eventType.eventKind = kEventHotKeyPressed;
InstallApplicationEventHandler( gAW6HotKeyFunction, 1, &eventType,
NULL, NULL );
gAW6HotKeyID.signature = kAW6HotKeyIdentifier;
gAW6HotKeyID.id = 1;
int err = RegisterEventHotKey( kAW6HotKey, cmdKey + optionKey,
gAW6HotKeyID,
GetApplicationEventTarget(), 0, &gAW6HotKeyRef); //
cmdKey + optionKey combines modifiers.
NSLog(@"registerAW6HotKey: %i", err);
}
- (void)registerClassicAW6HotKey
{
const UInt32 kClassicAW6HotKeyIdentifier = 'sCAW';
const UInt32 kClassicAW6HotKey = 23; // The 5 key
EventHotKeyRef gClassicAW6HotKeyRef;
EventHotKeyID gClassicAW6HotKeyID;
EventHandlerUPP gClassicAW6HotKeyFunction;
EventTypeSpec eventType;
gClassicAW6HotKeyFunction =
NewEventHandlerUPP(ClassicAW6HotKeyHandler);
eventType.eventClass = kEventClassKeyboard;
eventType.eventKind = kEventHotKeyPressed;
InstallApplicationEventHandler( gClassicAW6HotKeyFunction, 1,
&eventType, NULL, NULL );
gClassicAW6HotKeyID.signature = kClassicAW6HotKeyIdentifier;
gClassicAW6HotKeyID.id = 1;
int err = RegisterEventHotKey( kClassicAW6HotKey, cmdKey +
optionKey + shiftKey, gClassicAW6HotKeyID,
GetApplicationEventTarget(), 0,
&gClassicAW6HotKeyRef);
NSLog(@"registerClassicAW6HotKey: %i", err);
}
//
------------------------------------------------------------------------
-------------------------------------------------------
_______________________________________________
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.