The only reliable way I've found to detect accessibility access is to try creating a new event tap with kCGEventTapOptionDefault. If the permission is missing, CGEventTapCreate will return NULL. In my case I was dealing with keyboard events, not mouse events, but I expect it will work the same. Here's the code I use:
bool EventListener::CanFilterEvents()
{
CFMachPortRef thePort = CGEventTapCreate(
kCGSessionEventTap,
kCGTailAppendEventTap,
kCGEventTapOptionDefault, // active filter, not passive listener
CGEventMaskBit(kCGEventKeyDown),
CTapListener::MyTapCallback,
NULL );
bool madeTap = (thePort != NULL);
if (madeTap)
{
CFMachPortInvalidate( thePort );
CFRelease( thePort );
}
return madeTap;
}
Topic:
App & System Services
SubTopic:
Core OS
Tags: