Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xqbt

macrumors newbie
Original poster
Jan 20, 2016
3
0
Hi!

I am writing a C++ program and I want to integrate global hotkeys capabilities. There are ways to implement global hotkeys in objective-c, like by using DDHotkey or CGEventTap.

Setting aside the problems of invoking objective-c code from c++ code, my question is quite simple. (Using one of the techniques noted above) After I register a hotkey and I press that hotkey, what happens next? Is the program suspended and the event handler called right away? Or do I just call some function (whenever I want to), which calls the appropriate handlers if a hotkey was fired by that time? What is the program's flow like?

As you might see, I do not understand the big picture. All I see is a pile of code snippets, which tell me nothing. I am very new to Mac OS X development.

Extra credit question: is DDHotkey legacy, because it's based on Carbon, which is deprecated?

Please, let me kindly ask you to clarify the above points.
 

cruisin

macrumors 6502a
Apr 1, 2014
962
223
Canada
The general flow is not unique to OSX. I believe that most if not all devices since the beginning use something similar.

The first google search result for DDHotkey is a cocoa class: https://github.com/davedelong/DDHotKey. So it looks like it will still work.

The simplest method is to have your program continuously wait for input. On every input check against the current hotkey definition and jump to the correct handler or just ignore if it isn't one of the chosen hotkeys (or show an error). Then return to the waiting cycle.

The more involved method is to make the program call your functions asynchronously, that is to never suspend just call handlers based on the hotkey.

It really depends on what you are doing.
 
  • Like
Reactions: xqbt

xqbt

macrumors newbie
Original poster
Jan 20, 2016
3
0
Thanks for the reply :)
The thing is that, looking at DDHotkeyCenter.h from the provided link, it looks like there are only facilities to register/unregister a hotkey. I do not understand how to perform the "input check". BTW, yeah, I want synchronous stuff - just wait for an input.
 
Last edited:

xqbt

macrumors newbie
Original poster
Jan 20, 2016
3
0
Hmmm, alright, thanks, I will reflect on that link.

BTW, what code is executed after return NSApplicationMain(...) statement? I plowed through all the files and I have no clue.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.