Various programs can do stuff only when you haven’t used the computer for a while (eg screensaver, Google Desktop indexing, etc).
How do they know when it has been inactive? Is there some function in Windows that tells you how long it has been inactive, or do you have to use some kind of keyboard/mouse hook to track activity yourself?
I’m using C#, but I’m interested in any method of determining the inactivity.
EDIT: changed answer, providing text and detail behind Shy’s answer (which should be and was accepted). Feel free to merge and delete this one.
GetLastInputInfo Function The GetLastInputInfo function retrieves the time of the last input event.
Pasted here from P/Invoke
This function retrieves the time since last user input
FWIW: I implemented a global keyboard and mouse hook during AnAppADay. See this app for the source – it’s pretty close to what you want. The classes you’ll want are in the AnAppADay.Utils namespace.[scratched due to linkrot]