Determining if Accessibility (for CGEventTap) access was revoked?

My app depends on the user granting Accessibility access (Allow this application to control your computer). There’s no formal permissions API (that I know of) for this, it just happens implicitly when I use the API for the first time. I get an error if the user hasn’t granted permission.

If the user grants permission and I'm able to successfully register my CGEventTap (a modifier key event tap), but then later revokes it, key responsiveness goes awry. I don’t get any kind of error to my callback, but I do get tapDisabledByTimeout events periodically. I believe something is causing significant delays (but not preventing) in delivering events to my tap.

Upon receiving this, I'm considering attempting to register another tap as a way to test permission, and disabling the real one if I no longer have permission.

Does anyone have any better ideas?

For Apple: see FB13533901.

Answered by Mox in 776604022

Hi,

Does AXIsProcessTrusted or AXIsProcessTrustedWithOptions APIs can help you ?

Accepted Answer

Hi,

Does AXIsProcessTrusted or AXIsProcessTrustedWithOptions APIs can help you ?

There’s no formal permissions API (that I know of) for this, it just happens implicitly when I use the API for the first time. I get an error if the user hasn’t granted permission.

It depends on what else you’re using. If you’re using just using CGEventTap, there’s CGPreflightListenEventAccess, CGRequestListenEventAccess, CGPreflightPostEventAccess, and CGRequestPostEventAccess. You only need the Accessibility privilege if you’re doing other stuff with Accessibility APIs.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Determining if Accessibility (for CGEventTap) access was revoked?
 
 
Q