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.

Accepted Reply

Hi,

Does AXIsProcessTrusted or AXIsProcessTrustedWithOptions APIs can help you ?

  • Oh, let me try those!

  • Yes, that helps a lot! I'm able to remove my tap from the run loop if this is false, and that seems to solve the issues. Thank you!

Add a Comment

Replies

Hi,

Does AXIsProcessTrusted or AXIsProcessTrustedWithOptions APIs can help you ?

  • Oh, let me try those!

  • Yes, that helps a lot! I'm able to remove my tap from the run loop if this is false, and that seems to solve the issues. Thank you!

Add a Comment

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"

  • Oh, thanks Quinn! This is the right answer, but I don’t see a way to change the selected answer.

    The documentation is very thin, but it seems requesting Post implies Listen, and grants both kTCCServicePostEvent and kTCCServiceAccessibility in the TCC database. Requesting only Listen grants only kTCCServiceListenEvent and not kTCCServicePostEvent or kTCCServiceAccessibility.

  • So, it seems that if the user revokes Accessibility, the TCC DB shows both kTCCServicePostEvent and kTCCServiceAccessibility revoked, but the preflight calls continue to return true, while AXIsProcessTrusted returns false. I think I'll have to stick to that call for determining status.

Add a Comment