User Idle Detection
This question came up a couple of times recently. I came across this a while ago.
There is a function called
CGSSecondsSinceLastInputEvent that is not defined in
any headers. So while this is a private API it seems to work
fine on Tiger and Leopard. Just declare the prototype and you
can easily find out when the user last provided input. That is
moved the mouse or pressed a key.
double CGSSecondsSinceLastInputEvent(long evType);
double idleTime = CGSSecondsSinceLastInputEvent(-1);
Of course there is no guaranty this will work in future versions
of OSX as well. So if you know an official way of doing that
– please let me know.
Update: Apparently
there is also a way
of finding out through the public API. Thanks to
Michael for posting this
on cocoa-dev.


