What methods can determine the user leaves the computer, and then lock the computer. For example windows' C++ method GetLastInputInfo()
Accepted Reply
You can use CGEventSourceSecondsSinceLastEventType() or CGEventSourceCounterForEventType() to determine if the user is idle. Note, though, that the user may not give any input for long periods even though they're at the computer. For example, they may be watching a long video. A video-playing app would typically use one of the IOPMAssertionCreate…() functions to prevent the display from sleeping despite the lack of user input, so you might want to check for that using IOPMCopyAssertionsStatus(). You would want to avoid locking the computer if something has asserted that the display won't sleep.
Replies
Which of Apple's platforms are you trying to develop the application for? Because the answer for several of them (like iOS) is "No, a Developer application isn't allowed to do that."
You can use CGEventSourceSecondsSinceLastEventType() or CGEventSourceCounterForEventType() to determine if the user is idle. Note, though, that the user may not give any input for long periods even though they're at the computer. For example, they may be watching a long video. A video-playing app would typically use one of the IOPMAssertionCreate…() functions to prevent the display from sleeping despite the lack of user input, so you might want to check for that using IOPMCopyAssertionsStatus(). You would want to avoid locking the computer if something has asserted that the display won't sleep.
Thanks for your answer, The method of CGEventSourceSecondsSinceLastEventType() is perfect.
Thanks for your answer!
You may wish to rethink your design goals here. The Windows methods you note are horribly flawed
and those available in iOS and OSX aren't much better. In Windows, the update service running still
allows the system to sleep. Virus scans and similar activities do as well. Even something which should
keep the system awake, like copying files from one location to another are not immune to the nonsensical
activity tracking methods. It would be far more productive to have your application keep the system alive
while it is running if the system sleeping is a problem for your tasks.
Listens to Mr. what one says victory to read ten year book