tags:

views:

256

answers:

2

In general, the Screensaver will run when we do nothing for a period of time.
Now i wanna know how to get the unactive time.
In another word,i want to make a program which would run a function if we do nothing for a period of time.
Now i can use mouse or keyboard hook to solve the problem.
But you know,it needs administrator permissions. In another word,if in win vista or win 7,it is nauseating because of the UAC.
I need an API such to get last windows active time.

+1  A: 

Look into CallNtPowerInformation() and request a SYSTEM_POWER_INFORMATION structure.

John Deters
The SYSTEM_POWER_INFORMATION structure "Contains information about the idleness of the system." TimeRemaining is "The time remaining in the idle timer, in seconds." Idleness is that number expressed as a percentage.typedef struct _SYSTEM_POWER_INFORMATION { ULONG MaxIdlenessAllowed; ULONG Idleness; ULONG TimeRemaining; UCHAR CoolingMode;}SYSTEM_POWER_INFORMATION, *PSYSTEM_POWER_INFORMATION;
John Deters
+2  A: 

The CallNtPowerInformation() API is to get the last power information
I should use GetLastInputInfo()

Edwin Tai
GetLastInputInfo() does not give you system-wide idle time for when Windows will go idle or when the screensaver will kick in. It only gives you the idle time for the running process. CallNtPowerInformation() gives you the system idle time.
John Deters