Reputation: 53
How to get the remaining time to the next system auto locking or auto sleep?
Upvotes: 1
Views: 316
Reputation: 26259
You can get the time to next sleep by using CallNtPowerInformation
with the SystemPowerInformation
option and then look at the TimeRemaining
field in the returned struct. However, this can be always 0
. So, let's see another approach.
GetLastInputInfo
will give you the time (in ticks) when the last user input (such as keypress or mouse move) happened.SystemParametersInfoW
function with the SPI_GETSCREENSAVETIMEOUT
flag will get the screensaver timeout from Windows settings (in seconds).Combine these two with the current time and a "tick to seconds" conversion to find out how long until the screensaver fires.
Also, note that not all users have screensavers or sleep/hybernate enabled. You might have to check these too.
Upvotes: 1