python and apple events ...

S

StŽphane

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;
    gMyHotKeyID.id = 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
hotkey
combo was pressed; we can do whatever we want here

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

    return noErr;
}
--- taken from a post on cocoa.mamasam.com

Thanks in advance for any help.
Stephane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top