Search code examples
c#.netuser-inputscreensaver

Detecting that the user is away from the PC with .NET


I have a desktop application in which I would like to know two things:

  1. Is the user currently on the PC (more specifically, is he giving any input to the PC), so I can change his state to "away" if needed; and
  2. Is the screensaver running right now, so I can perform more CPU intensive work during that time.

I'm using C#/.NET. How would you suggest to tackle these two tasks?

NOTE: WIN32 invocation will be just as good, as well as any unmanaged code solution.


Solution

  • http://dataerror.blogspot.com/2005/02/detect-windows-idle-time.html

    ^ Detect Windows Idle Time. :)

    The enabler for this feature is the GetLastInputInfo() Win32 API and the LASTINPUTINFO Win32 structure.