Get mouse position in Login Window

Hi there. Im try to get mouse position in mac os. In user session im use


CGEventRef ourEvent = CGEventCerate(NULL);
CGPoint point = CGEventGetLocation(ourEvent);
CFRelease(ourEvent);


But, i need get cursor position in Login Window. Im try start my app like sudo or root user. This can`t help me. Im start app like daemon from /Library/LaunchDaemons/ this too can`t help me.


How i cat get grab position in Login Window? May be need use some notification, or start app like super user?

Replies

Daemons can’t reliably connect to the window server, and thus shouldn’t use APIs like Core Graphics. You can learn more about this in Technote 2083 Daemons and Agents (which that technote could do with an update, the discussion of the macOS’s architecturally fundamentals is still sound).

There’s two supported ways to talk to the window server from a pre-login context:

  • Via a pre-login launchd agent, as illustrated by the PreLoginAgents sample code

  • From a non-privileged authorisation plug-in

The former is probably what you want; the latter is useful if you need to run synchronously with respect to the login process.

IMPORTANT If you create a pre-login launchd agent, carefully read the read me for the PreLoginAgents sample code. Specifically, when working with Core Graphics events, you may run in to a known bug (r. 5636091).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"