Detecting that a user is outside a .NET PC.

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

  • Is the user currently on the PC (more precisely, he enters any data on the PC), so I can change his status to “off” if necessary; and
  • The screensaver is working right now, so I can do more intensive work with the CPU during this time.

I am using C # /. NET How would you propose solving these two problems?

NOTE : a WIN32 call will be as good as any unmanaged code solution.

+2
source share
4 answers

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

^ Determine Windows downtime. :)

The subject of this function is the GetLastInputInfo () Win32 API and the Win32 LASTINPUTINFO structure.

+5
source

Here is the code to determine if the screen saver works. See details

const int SPI_GETSCREENSAVERRUNNING = 114; [DllImport( "user32.dll", CharSet = CharSet.Auto )] private static extern bool SystemParametersInfo( int uAction, int uParam, ref bool lpvParam, int flags ); // Returns TRUE if the screen saver is actually running public static bool GetScreenSaverRunning( ) { bool isRunning = false; SystemParametersInfo( SPI_GETSCREENSAVERRUNNING, 0, ref isRunning, 0 ); return isRunning; } 
+5
source

Instead of figuring out when to do more intensive work ... Think about doing your “intensive work” as early as possible, but with a lower priority thread.

I don’t think your questions have an answer in pure C #, unless you interview the position of the mouse and observe the movement ... Or something like that.

0
source

You can use the global keyboard / mouse hook and only reset your "counter" to 0 when you get the event out. When your counter reaches the timeout you are looking for, do your background actions.

Here is some code that makes it easy to bind to .NET: http://www.codeproject.com/KB/cs/globalhook.aspx

0
source

All Articles