Detect inactivity

  • Thread starter Thread starter Sonya
  • Start date Start date
S

Sonya

Hi,
can an application detect if windows starts the screensaver? So that my
application can do some work while the user is afk.

Greetings Sonya
 
Hi Sonya,
I do not believe there is any native event in .Net that will tell you
this, however you can override your forms WndProc method to capture raw
windows messages to see when the WM_SYSCOMMAND message is sent with a
parameter of SC_SCREENSAVE, this occurs when the screen saver starts. For
example:

using System;
using System.Windows.Forms;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
MyForm f = new MyForm();
Application.Run(f);
}
}

class MyForm : Form
{
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);

int WM_SYSCOMMAND = 0x112;
int SC_SCREENSAVE = 0xf140;

if ((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32() ==
SC_SCREENSAVE))
{
Console.WriteLine("Screen saver activated");
}
}
}
}


Mark
 
Mark said:
I do not believe there is any native event in .Net that will tell you
this, however you can override your forms WndProc method to capture raw
windows messages to see when the WM_SYSCOMMAND message is sent with a
parameter of SC_SCREENSAVE, this occurs when the screen saver starts.

Thanks a lot!
Sonya
 
Hi,

That works perfect for applications with visible forms but unfortunately
not with my tray application. ;(

Sonya
 
Hi Sonya
Do you must work paralel with the screen saver , or you can use some timeout
interval of inactivity to identified that the user is not working ?
 
semedao said:
Hi Sonya
Do you must work paralel with the screen saver , or you can use some timeout
interval of inactivity to identified that the user is not working ?

I could use any timeout interval but I thought in using screensaver
event but it seems I have to use simething else.
 
Back
Top