LaunchAgent on LoginWindow cannot send CGEventCreateKeyboardEvent created event

Originator:tadelv
Number:rdar://17572986 Date Originated:7.7.2014
Status:Open Resolved:
Product:OS X Product Version:any
Classification:bug Reproducible:always
 
When developing a LaunchAgent for OS X that functions as a keyboard proxy, you cannot post keyboard events created with CGEventCreateKeyboardEvent functions.
Using the deprecated CGPostKeyboardEvent function however works.
Please check the supplied sample code (modified PreLoginAgentCocoa example) and console log, which shows the window server messages.

I can provide a modification that will show the problem more extensively.

Steps to Reproduce:
0. have a mac with a user account that requires authentication on login window (no automatic login)
1. Install Xcode, build the supplied example
2. install the supplied launchd plist to /Library/LaunchAgents
3. install the build .app into /Library/PrivilegedHelperTools
4. restart the machine
5. on login window, press the button labeled "Keyboard" in the example application window
6. after login, check console messages for Window server not available messages

Expected Results:
Window server should be available and the keyboard event should be posted.

Actual Results:
An error is logged in the system.log and no keyboard event is posted

Version:
OS X >= 10.6

Notes:
Workaround is to use deprecated CGPostKeyboardEvent function when running in login window

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!