PDA

View Full Version : Finding if system is idle.



jitendra_jkr
April 5th, 2007, 02:08 AM
Hi,
I am working on C#.net window application.
i want some code in C#.net to know if sytem is idle.
my problem is - if user does not touch keyboard or mouse for some time, system go to sleep mood and screensaver starts.

I want to know when system go in this state, also when he/she move mouse or press any key, then do some work using c#.net code.

please help me if anyone have solution.

Esherido
April 8th, 2007, 07:55 PM
You're asking in the wrong forum, go to the Programming (C#, C++, Java, etc.) (http://www.kirupa.com/forum/forumdisplay.php?f=137) forum.

TheColonial
April 8th, 2007, 09:01 PM
There are two ways of detecting if a screensaver is active.
You can call the SystemParametersInfo() (http://msdn2.microsoft.com/en-us/library/ms724947.aspx) API function passing the SPI_GETSCREENSAVERRUNNING flag (for an example look at this (http://www.codeguru.com/forum/showthread.php?t=257949)). You can create a global Windows message hook, and intercept the WM_SYSCOMMAND message. When you find this message, check to see if wParam is SC_SCREENSAVE. This is a bit more of a pain in C# than C/C++, but it's definitely doable. For more information have a look at this (http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraskdr/html/drgui48.asp).

I'd suggest you get used to Googling, as there's already a stack of information out there for handling keyboard and mouse input in C# (such as this (http://www.codeproject.com/csharp/globalhook.asp) and this (http://www.codeguru.com/csharp/csharp/cs_syntax/anandctutorials/article.php/c5823/)).

Cheers
OJ

jitendra_jkr
May 31st, 2007, 02:13 AM
Thank you!


There are two ways of detecting if a screensaver is active.

You can call the SystemParametersInfo() (http://msdn2.microsoft.com/en-us/library/ms724947.aspx) API function passing the SPI_GETSCREENSAVERRUNNING flag (for an example look at this (http://www.codeguru.com/forum/showthread.php?t=257949)).
You can create a global Windows message hook, and intercept the WM_SYSCOMMAND message. When you find this message, check to see if wParam is SC_SCREENSAVE. This is a bit more of a pain in C# than C/C++, but it's definitely doable. For more information have a look at this (http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraskdr/html/drgui48.asp).
I'd suggest you get used to Googling, as there's already a stack of information out there for handling keyboard and mouse input in C# (such as this (http://www.codeproject.com/csharp/globalhook.asp) and this (http://www.codeguru.com/csharp/csharp/cs_syntax/anandctutorials/article.php/c5823/)).

Cheers
OJ