Skip to content

Conversation

@grigorye
Copy link

@grigorye grigorye commented Apr 13, 2025

I've been using sendkeys to automate some testing inside VMs and discovered the following while trying to investigate why sendkeys "does nothing" in certain cases when I tried to employ multiple users in VM to benefit from some parallelization: basically it was not TCC problem, it did not complain about lack of permissions/the "Terminal" and etc was added there. Basically for some users (typically, the first logged in) it worked, while for the rest it silently did nothing (except for activating the app that was set as the destination).

Spent quite several hours trying to figure it out, and then accidentally encountered the case that is captured on the recording: basically, sendkeys is sending mouse clicks to a wrong user session. It turned out that it was matter of .cghidEventTap vs .cgSessionEventTap. That explains everything and fixes the problem for me (you can see the effect at the recording where /tmp/sendkeys is used - that's something compiled with the change).

The same problem is applicable to key presses (and is fixed as well).

(I did not try .cgAnnotatedSessionEventTap but I feel like .cgSessionEventTap does enough job.)

sendkeys-wrong-session-demo.mp4

@grigorye grigorye force-pushed the cgSessionEventTap branch from 41e9d2a to 95bafe4 Compare April 13, 2025 21:19
@socsieng
Copy link
Owner

Thanks for the PR. I'll do some testing in the next couple of days.

Assuming all is good, I'll aim to get this merged by the end of this week.

@tholu
Copy link

tholu commented Jul 3, 2025

@socsieng Did you run into any problems when testing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants