sendkeys icon indicating copy to clipboard operation
sendkeys copied to clipboard

Fixed wrong CGSession used with the events posted (a case of multiple users)

Open grigorye opened this issue 9 months ago • 2 comments

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.)

https://github.com/user-attachments/assets/8b8cf13d-016e-40a3-bc97-9826bb40359e

grigorye avatar Apr 13 '25 21:04 grigorye