Reading Mouse Events with CGEvent tap from a background app in macOS 27.3

WIth macOS 27.3 (beta 2) things have changed quite a bit for security, see Updates to Device Control and Data Access, and Full Disk Access in macOS

I have an app which uses what (used to be called) the Privacy & Security / Accessibility permissions in order to receive mouse events in the background to read them and occasionally modify them.

The method used:

  1. The app checks AXIsProcessTrustedWithOptions to see if it has permission.
  2. If it doesn't have permission, it uses the kAXTrustedCheckOptionPrompt option which would open up the privacy & Security / Accessibility pane.
  3. Because that process has been a little flakey in macOS, my app has a backup option, where it runs 'open "x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_Accessibility"' and then walks the user through the steps with onscreen instructions.
  4. When permission is granted, the app creates a CGEvent tap SessionEvent tap using the HeadInsertEvent option to receive mouse and touch mouse events. See CGEvent.tapCreate

In macOS 27.3 beta 2,

  1. always returns false
  2. using kAXTrustedCheckOptionPrompt fails to do anything
  3. open "x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_Accessibility fails to do anything.
  4. CGEvent tap fails

A few questions:

  • will my third party app be allowed to use CGEventTaps to read mouse and touchpad events? Or has this been cut off completely and only available to first party apps?
  • If it is allowed, how? Has the permission for this moved to a different System Preference pane?
  • is a CGEvent tap the way to do it?

I totally understand that security is important, and apps should not have wide-ranging permissions. I'd love to find a way to keep my app running with the minimal permissions needed.

In 27.3 beta 2, the UI for Accessibility permission says:

"Apps with Accessibility access bypass built-in system protections that keep your data private and secure. They can see everything on your screen, including apps in the background, and control apps as if they were you without asking."

That's clearly not the permissions that my app needs - I just want to monitor (and sometimes change) mouse and touchpad events.

There's a different Input Monitoring permission which says

"Allow the applications below to monitor input from your keyboard even while using other applications".

This is closer to what my app wants, but for mouse and touch events, not for keyboard.

I want to make sure you’ve seen this article from Apple Support: If an app asks for Full Disk Access or System & App Protection Override on your Mac. It explains the general lay of the land.

Written by XMI in 857997021

will my third party app be allowed to use CGEventTaps to read mouse and touchpad events?

AFAIK we’ve not removed any functionality here, but rather reorganised how we gate access to that functionality.

Written by XMI in 916970022

There's a different Input Monitoring permission

Historically, Input Monitor gated access to CGEventTap, but you could also gain access to it via Accessibility. If you only need CGEventTap and don’t need other Accessibility APIs, that’s the direction I’d go.

Written by XMI in 857997021

open x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_Accessibility fails to do anything.

That doesn’t surprise me. AFAICT that specific URL has never been documented. See Supported URL Schemes for more.

Note that the closely related Full Disk Access URL is documented (albeit obscurely) and we’re discuss that over on this thread.

Finally, I want to remind you that Feedback Assistant is not just for bug reports. If you have specific feedback about any of this, please record it there, and than post the FB number here, just for the record.

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

Historically, Input Monitor gated access to CGEventTap, but you could also gain access to it via Accessibility. If you only need CGEventTap and don’t need other Accessibility APIs, that’s the direction I’d go.

I'll give that a try, and report back here with success or failure, and will definitly file Feedback cases as needed.

Running some tests in 27.3 beta 2 and I'm seeing behavior which I don't understand.

I have an app which tries to set up a CGEventTap with various combinations of options

Location: always cgSessionEventTap
Place: always headInsertEventTap
Options: either defaultTap or listenOnly

eventsOfInterest: which events are in the mask.

InputMonitoring: whether the app has been manually added to System Settings / Privacy & Security / Input Monitoring

General Results:

Options: defaultTap fails for any combination of events, regardless of InputMonitoring permissions.

Keyboard Events:

Options: listenOnly returns keyboard FlagsChanged event, regardless of InputMonitoring permissions (but only when the App is frontmost).

Options: listenOnly returns keyUp and keyDown events, but only when InputMonitoring permission is enabled, and works when the App is not frontmost.

Mouse Events:

Options: listenOnly returns mouse events, regardless of InputMonitoring setting (but only when the App is frontmost).

Options: listenOnly returns mouse events, but only when InputMonitoring permission is enabled, and works when the App is not frontmost.

Notes/Issues/Questions:

  1. System Settings / Privacy & Security / Input Monitoring when set for an app, appears to enable the app to set up a CGEventTap in listenOnly mode - so it can get events (either mouse or keyboard), but can't modify these events.
  2. I could find no way to enable CGEventTap in default (read and modify mode). Presumably this is gated by the Accessibility permission still?
  3. None of my app's attempts to set up CGEventTaps triggered any OS dialogs. I would have expected the OS to put up some sort of "Your app is attempting to listen to Mouse or Keyboard events, Allow?" dialog but I never saw anything.

If I'm understanding things, it seems an App's ability to read and modify events with a CGEventTap is not possible in 27.3.

So what you’ve described largely makes sense to me. Input Monitoring is intended to allow for… well… input monitoring, so it lets you see events but not post them. This corresponds to CG’s .listenOnly option.

Written by XMI in 917697022

Options: listenOnly returns keyboard FlagsChanged event, regardless of InputMonitoring permissions (but only when the App is frontmost).

This is a bit weird, but I don’t consider it be problematic because if you’re at the front you have other ways to monitor for modifier changes.

Written by XMI in 917697022

2- I could find no way to enable CGEventTap in default (read and modify mode). Presumably this is gated by the Accessibility permission still?

Kinda.

There’s actually a separate TCC service for this, PostEvent. Annoyingly, this has never showed up as a separate item in System Settings. Rather, it’s always been accounted for under Accessibility, which is a confusing because that means that apps can show up in Accessibility for two entirely different purposes.

The 27.3 beta changes don’t fundamentally change this. The difference now is that Accessibility is reserved for assistive technology products and other products that uses these facilities are listed under System & App Protection Override.

However, my understanding is that 27.3b2 has a bug that is causing problems for folks who rely on the PostEvent privilege, see here, and I suspect that’s the cause of some confusion here. We should be able to nail this down once the fix for that bug ships.

Written by XMI in 917697022

3- None of my app's attempts to set up CGEventTaps triggered any OS dialogs.

I suspect that’s a deliberate change, but there’s an experiment I’d like you to try:

  1. Create a tiny test app with a button that calls CGRequestListenEventAccess.
  2. Run it on macOS 26. Clicking the button should present an alert.
  3. Repeat this in macOS 27.3b2.

Do you get the alert?

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