moka
moka

Reputation: 4491

OSX Carbon: Quartz event taps to get keyboard input

I want to get Keyboard Input on OSX using c++ without using Cocoa, deprecated Carbon UPP handlers and if possible without using IOHID since that's alot of extra work. I allready implemented a simple mouse class using quartz event taps and it works like a charm and now I'd like to use them to implement a keyboard class. Anyways as the reference states under CGEventTapCreate: http://developer.apple.com/library/mac/#documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html

you can only access key events if one of the following is true:

  1. The current process is running as the root user.
  2. Access for assistive devices is enabled. In Mac OS X v10.4, you can enable this feature using System Preferences, Universal Access panel, Keyboard view.

that is a very serious limitation since I also want my application to work without any weird settings. Is there any way to work around this? If not, is there any alternative to using Taps in Carbon? Thanks!

Upvotes: 3

Views: 2141

Answers (2)

0xced
0xced

Reputation: 26538

You could try to use AXMakeProcessTrusted. This is supposed to be the same as Access for assistive devices on a per process basis.

Upvotes: 2

Yuji
Yuji

Reputation: 34185

The easiest way is to use the semi-deprecated Carbon function RegisterEventHotKey, see this SO Q&A, for example.

If not, you need to live with that restriction. The restriction is there to prevent a bad person to install keylogger behind the scenes. You need to ask the user to open the preferences, type the admin password etc.

Upvotes: 2

Related Questions