Global Hotkey Declare

I used to have a code snippet for global hotkeys which used a Carbon declare but I’ve lost it - can anyone help? (I don’t want to use MBS, thanks)

Any luck finding it? I would also be interested to figure out how to open my app with a keyboard shortcut.

Not able to pull out my own code right now, but have you looked if MacOSLib has it?

Didn’t see anything related in MacOSLib.

how do you want to use the hot key? Do you want to use it to launch your app? In that case, you’ll need a handle a separate helper for that. Or do you just want to use hot keys while your program is running?

No, it’s not to launch the app (although the app already has a helper app) - it’s to open a window when the app is running.

That’s exactly what I need also.

+1 here :slight_smile:

I can supply you with the code that just defines a hotkey whose code you already know and then reacts to it when the user hits it.

I also have code that does the whole user-friendly choosing of a random hotkey, but that requires a lot more code and explanations that I’m not willing to give here, as it would take me hours (if you need that and are willing to pay for it, contact me privately).

If all you need is the hotkey registration for a fixed key, I can see that I make that available.

That would be useful, thanks - I’m annoyed because I had the code previously and I can’t find it and haven’t had the time to dig through Carbon to figure it out again.

Here you are:

Thanks Thomas, works perfectly!

Be careful when using this. Those are deprecated Carbon API calls. It does still work with OS X 10.9 though (for now).

For Cocoa you can use NSEventMonitor but this has a huge disadvantage because you need to ask the user to have permission for these events. In OS X 10.6 up to 10.8 this can be done without permission from the user by changing some plist keys. However, this little trick isn’t working anymore with OS X 10.9

Well, we have NSEventMonitor already in the MBS Plugin…

Apple is not Xojo Inc. They do not usually remove APIs, they just tell us not to use them in new program because they won’t get updated or fixed any more, and the new ones are usually more efficient.

Thomas Tempelmann’s Hotkeys-module works nicely.

However, I’d like to know if it works with MAS apps or should I try something else?

HotKey API from Carbon Events is MAS compatible. No problem.
as well as the NSEventMonitor.

both available in MBS Plugins.