View Full Version : Global key listening running in the background

Dec 25, 2011, 07:54 AM
I have a new app idea and there are two parts I don't know how to build yet. I hope someone can point me in the right directions.

I need to respond on certain keys even if my app doesn't have the focus. For example: I'm now using Firefox and if I press cmd I wan't my app to respond.

Second part is that I want the app to stay in the background, so after pressing cmd a function in my app should be called, but as user I want to continue in Firefox without even noticing it.

I'm not building a key logger, but I do want to use it's functionalities. Does someone know a guide for either of these parts? I haven't found any.

Dec 25, 2011, 09:19 AM
You can set custom key commands for applications in system prefs. Cmd is probably not going to work that well on its own, since its used as a switch for normal character input by practically every key command in the os.

Dec 25, 2011, 05:13 PM
Cmd is just an example.

Is there any way I can do program this?

Dec 25, 2011, 07:22 PM
Take a look at Carbon Event Taps: http://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html . That may allow you do do what your're asking about. I don't think there is any Cocoa API that will do what you want, but I don't have any personal experience doing this.