0

I am developing a macOS app which takes control of the cursor. I am using a CGEvent Tap and I am adding some arithmetic to the CGEvents in order to offset the final mouse position. Although the app is in principle working as expected, in some cases - more specifically: when running the app with certain popular illustration software and using a stylus pen - the app is producing some flickering 'ghost' positions for the mouse at its original location. The good thing is, this problem can be resolved when running the app while being logged in as root user. I have read quite some SO posts but this particular post addresses the issue best:

https://stackoverflow.com/a/9899901/5066660

As described in this post the issue is probably:

Unfortunately, the CGEventTapCreate() doc says: Only processes running as the root user may locate an event tap at the point where HID events enter the window server; for other users, this function returns NULL.

Well the function is definitely not returning null because the tap is in effect. Also I tried all possible combinations of arguments for that function, but they all act the same. Further down in that post it is proposed to tackle the problem as follows:

Perhaps you can spin this functionality off into a separate process that has super-user permissions, leaving the rest of your app in normal user mode? I believe there's also a way to request root permissions for just a specific action taken by your program.

Now if this is a possible solution I would love to implement it! So my question is: how? I've stumbled upon running scripts with elevated permissions, but not just CoreGraphics code as for example an CGEventTap. Is this possible? Could anybody give me an example of how this could be accomplished, or any other solution to the problem?

All help is welcome, thank you very very much.

fy data
  • 195
  • 1
  • 9
  • I have made a helper app running as root by using/modifying this handy project: https://github.com/erikberglund/SwiftPrivilegedHelper. I've put my CGEventTap code in the helper, but the problem persists. Somehow running a helper in root is not the same as logging in as root user and then running the app. Why?? – fy data Oct 30 '17 at 13:19

1 Answers1

0

From Apple documentation:

Event taps receive key up and key down events if one of the following conditions is true:

- The current process is running as the root user.

- Access for assistive devices is enabled. In OS X v10.4, you can enable this feature using System Preferences, Universal Access panel, Keyboard view.

So giving the the application Accessibility rights solved it for me (no need to run as admin). This can be achieved System Preferences -> Security & Privacy -> Accessibility and add you program there.

Ville R
  • 61
  • 4
  • Thank you but while that does seem to do the trick for key-strokes, unfortunately it does not fix the ghost-position bug when giving privileges in this way for the mouse. :( – fy data May 25 '20 at 14:11