Keyboard and Mouse simulation are not working in macOS pre-login window

I'm a newbie to Launch agent and daemons. Now I'm currently developing the remote desktop (like VNC) application for macOS with Objective-C and my application supported macOS versions are 10.6 and later. I have created a pre-login agent and it will launch my application when login window open.


I am using CGEventPost to simulate keyboard and mouse events in user logged-in sessions. But it's not working in pre-login window (global login window)


Citrix, LogMeIn are providing the remote controls in Pre-login window too. How are they doing it?

Any help will be highly appreciated.


Please refer the code


//For Keyboard

CGEventRef keyEvent = CGEventCreateKeyboardEvent( NULL, keyCode, down ) ;

CGEventPost( kCGHIDEventTap, keyEvent ) ;

CFRelease( keyEvent ) ;


//For Mouse

CGEventRef event = CGEventCreateMouseEvent(eventSource, eventType, mouseLocation, mouseButton ); CGEventPost(kCGHIDEventTap, event);

CFRelease(event);


//Pre-login launch agent

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>Label</key>

<string>my app label</string>

<key>LimitLoadToSessionType</key>

<string>LoginWindow</string>

<key>RunAtLoad</key>

<true/>

<key>WorkingDirectory</key>

<string>My app directory</string>

<key>ProgramArguments</key>

<array>

<string>app absolute path</string>

<string>service</string>

<string>myservice</string>

</array>

<key>KeepAlive</key>

<true/>

</dict>

</plist>

Did you ever figured this out? I'm running into the same issue. I'm able to capture the screen during LoginWindow but CGEvents for mouse and keyboard aren't working.

Keyboard and Mouse simulation are not working in macOS pre-login window
 
 
Q