Re: [Q] capture or assign global hot key like spotlight or quicksilver
Re: [Q] capture or assign global hot key like spotlight or quicksilver
- Subject: Re: [Q] capture or assign global hot key like spotlight or quicksilver
- From: email@hidden
- Date: Thu, 15 Nov 2007 16:45:14 +0100
Have a look at Apple's iTunesController sample code, if you want
several keys. If you just want one single hotkey, here's a simple
implementation:
#import "Hotkey.h" // Import Carbon.h in the header
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 )
{
// Set name of your key
EventHotKeyID keyID = { 'hotK', 1 };
// Set keycode and modifiers for you key.
Keycode 49 = space bar.
OSStatus err = RegisterEventHotKey( 49,
cmdKey+optionKey, quitID, GetApplicationEventTarget(),
0, &eventHotKeyRef );
hotKeysRegistered = true;
}
}
else if ( registerKeys == false )
{
if ( hotKeysRegistered == true )
{
UnregisterEventHotKey( eventHotKeyRef );
hotKeysRegistered = false;
}
}
return;
}
static OSStatus HotKeyEventHandlerProc( EventHandlerCallRef inCallRef,
EventRef inEvent, void* inUserData )
{
NSLog(@"Hot key pressed");
}
On Nov 15, 2007 3:26 PM, "S.J.Chun" <email@hidden> wrote:
> Hi,
>
> I'd like to create application like quicksilver or sptlight. They
> appear to the screen when user presses specified hot key
> and the hot key is global - they work even if your active
> application is not them.
>
> Are there any sample application or resource/documentation
> for this?
>
> Thanks in advance.
> _______________________________________________
>
> 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
>
_______________________________________________
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