Global hotkey problem in Leopard
Global hotkey problem in Leopard
- Subject: Global hotkey problem in Leopard
- From: email@hidden
- Date: Sun, 11 Nov 2007 12:52:38 +0100
Dear list,
Please forgive me if this should have been posted on carbon-dev, but I
believe it has more to do with the cocoa implementation than carbon
itself (and there is no Cocoa way of doing it), so here goes:
In Tiger, I used the (stripped down) code below to enable/disable
global hotkeys. In Leopard, the code no longer works. The keys are
registered and unregistered alright, but the HotKeyEventHandlerProc
function is never called. At first, I thought something was broken in
Leopard, but I verified the Apple sample code that demonstrates the
use of global hotkeys (the iTunes controller) still works as expected,
so I now believe the problem lies elsewhere. Please help me out!
Thanks.
#import "Hotkey.h"
void RegisterHotKey( Boolean registerKeys );
const EventTypeSpec hotKeyEvents[] = { { kEventClassKeyboard,
kEventHotKeyPressed }, { kEventClassKeyboard, kEventHotKeyReleased
} };
static OSStatus HotKeyEventHandlerProc( EventHandlerCallRef inCallRef,
EventRef inEvent, void* inUserData );
@implementation Hotkey
- (void)awakeFromNib
{
InstallApplicationEventHandler(
NewEventHandlerUPP(HotKeyEventHandlerProc),
GetEventTypeCount(hotKeyEvents), hotKeyEvents, 0, NULL );
RegisterHotKey( true );
}
void RegisterHotKey( Boolean registerKeys )
{
static Boolean hotKeysRegistered;
static EventHotKeyRef eventHotKeyRef;
if ( registerKeys == true )
{
if ( hotKeysRegistered == false )
{
EventHotKeyID quitID = { 'XHfq', 1 };
OSStatus err = RegisterEventHotKey( 12, (cmdKey | optionKey),
quitID, GetApplicationEventTarget(), 0, &eventHotKeyRef );
if (err) NSLog(@"Error installing event handler: %d",err);
hotKeysRegistered = true;
}
}
else if ( registerKeys == false )
{
if ( hotKeysRegistered == true )
{
UnregisterEventHotKey( eventHotKeyRef );
hotKeysRegistered = false;
}
}
return;
}
static OSStatus HotKeyEventHandlerProc( EventHandlerCallRef inCallRef,
EventRef inEvent, void* inUserData )
{
NSLog(@"OK");
}
_______________________________________________
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