I’ve seen some things about registering a global hotkey for an application, even when the application is only in the menubar does anyone know any code I can use to register a global hotkey?
Model: MacBook Pro
AppleScript: 2.1.2
Browser: Rockmelt
Operating System: Mac OS X (10.6)
Couldn’t find anything else in 2010 with the keywords “global” “shortcut” and “keyboard”… I too remember something about this subject being asked a while ago…
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)
Well the answer seems to be that it’s going to involve some Objective-C or C code.
The addGlobalMonitorForEventsMatchingMask:handler: method of NSEvent requires blocks, so it can’t be done directly inASObjC. More to the point, it has to handle every event, so even if ASObjC could do it, overall computer responsiveness would probably take a huge hit.
The other method is a Carbon call, RegisterEventHotKey, so that means writing some C and wrapping it in Objective-C to call from ASObjC.
I think that’s it. This is what I remembered… but would this work for a hot key like magikseb wanted to do? I guess if we used NSKeyDown and NSFlagsChanged…
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)