2

How could I get user idle time on Windows in seconds?

I wrote small program to check work time on pure C, but all answers that I could find were written in C#. Is there a way to get it like on MacOSX or X11?

For OSX I used this solution - https://github.com/kairichard/idler

And for Linux - https://github.com/gpolitis/xidle

Andy
  • 31
  • 7
  • [`CallNtPowerInformation()`](http://stackoverflow.com/questions/1442246/how-to-get-the-last-windows-active-time-by-windows-api) with `SYSTEM_POWER_INFORMATION` seems to do, what you want. – dhke Mar 09 '16 at 14:13
  • It seems like what i need! Have you any code snippet shows how to use it? Unfortunately i never build program for windows system. If i understand correctly i need wrap function for https://msdn.microsoft.com/en-us/library/ms646302(VS.85).aspx , but this example on c++ not on pure c. – Алексей Маликов Mar 09 '16 at 14:19
  • http://pastebin.com/pAgcc2Z4 am i right? – Алексей Маликов Mar 09 '16 at 14:27
  • 2
    Idleness is the "percentage of idleness" the system considers itself to be in (whatever that is). `SYSTEM_POWER_INFORMATION.TimeRemaining` is essentially *time till the screensaver is activated*, which is also not all that useful. However, If I get the linked answer right, `GetTickCount() - GetLastUserInput()` should give you time since last user input in msecs, which is pretty close to what xidle does, too. – dhke Mar 09 '16 at 14:56
  • Did you come up with a solution for Windows? – simonhamp Sep 06 '16 at 21:52

0 Answers0