i want to simulate the keyboard with CGEventPost in the user session (MacOS).
CGEventRef keyEvent = CGEventCreateKeyboardEvent( NULL, keyCode, down ) ;
CGEventPost( kCGHIDEventTap, keyEvent ) ;
CFRelease( keyEvent ) ;
when i use this code in a normal app(whether run as root) , it works fine.
but when i run it in launchd-daemon like the project smjobbless , it's not working.
here is my launch.plist:
<dict>
<key>Label</key>
<string>com.apple.bsd.SMJobBlessHelper</string>
<key>RunAtLoad</key>
<true/>
<key>MachServices</key>
<dict>
<key>com.apple.bsd.SMJobBlessHelper</key>
<true/>
</dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
</dict>
the launchd-daemon project had been installed at /Library/PrivilegedHelperTools
success and everything is running OK (seems run as root) except the CGEventPost
, it's very strange , any suggestions?