By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,767 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,767 IT Pros & Developers. It's quick & easy.

python and apple events ...

P: n/a
Hello, I am wondering if any one knows how I could bind my python app to
answer to a hotkey combination under mac os x. I know it is possible to do
so in obj-c but it seems to call a pure C function, and this makes me a bit
confused on how I would use it under pyobjc here is an example:

#import <Carbon/Carbon.h>

const UInt32 kLockUIElementHotKeyIdentifier = 'lUIk';
const UInt32 kLockUIElementHotKey * * * *= 109; //F10 will be the key to
hit, in combo with Cmd

AppShell * * * * * * *gAppShell = NULL;

EventHotKeyRef gMyHotKeyRef;
EventHotKeyID * *gMyHotKeyID;
EventHandlerUPP * *gAppHotKeyFunction;

pascal OSStatus LockUIElementHotKeyHandler(EventHandlerCallRef
nextHandler,EventRef theEvent, void *userData);

- (void)awakeFromNib
** *EventTypeSpec eventType;

** *gAppHotKeyFunction = NewEventHandlerUPP(LockUIElementHotKeyHandler);
** *eventType.eventClass = kEventClassKeyboard;
** *eventType.eventKind = kEventHotKeyPressed;

InstallApplicationEventHandler(gAppHotKeyFunction, 1,&eventType,NULL,NULL);

** *gMyHotKeyID.signature = kLockUIElementHotKeyIdentifier;
** * = 1;

** *RegisterEventHotKey(kLockUIElementHotKey, cmdKey, gMyHotKeyID,
GetApplicationEventTarget(), 0, &gMyHotKeyRef);

pascal OSStatus LockUIElementHotKeyHandler(EventHandlerCallRef
nextHandler,EventRef theEvent, void *userData)
** *// We only register for one hotkey, so if we get here we know the
combo was pressed; we can do whatever we want here

** *NSLog(@"Hello, World! HotKey was pressed!");

** *return noErr;
--- taken from a post on

Thanks in advance for any help.
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.