tags:

views:

92

answers:

3

I want my application to be able to display certain information when no user input has been detected for some time (like a Welcome/Instruction layer). Is there anyway to have the application register any form of user input (keyboard, mousedown/move etc) without having to write handlers for each of those events?

Is there a generic input window message that gets sent before it is interpreted as being mouse or keyboard or other device? The behaviour I want is similar to Windows waking up from screen saver / sleep on keyboard or mouse input.

I want to avoid something like:

void SomeHandler(object sender, EventArgs e) { WakeUp(); }
...
this.KeyDown += SomeHandler;
this.MouseMove += SomeHandler;
this.SomeInputInteraction += SomeHandler;
+2  A: 

The GetLastInputInfo Function is probably what you're looking for. It retrieves the time of the last input event.

Andy West
Thanks, this is pretty much what I'm after
jeffora
A: 

Maybe this article on CodeProject will help you. It is about automatically logging off after a period of inactivity using WPF.

Hope this helps, Best regards, Tom.

tommieb75
Thanks, interesting read and useful information - bit more verbose method than I'm after though
jeffora
A: 

I don't know if this works in WPF but this may help:

public class DetectInput : IMessageFilter
{
 public bool PreFilterMessage(ref Message m)
 {

  if (   m.Msg == (int)WindowsMessages.WM_KEYDOWN 
            || m.Msg == (int)WindowsMessages.WM_MOUSEDOWN  
            // add more input types if you want
            )
  {
   // Do your stuff here
  }

  return false;
 }
}

and in Program:

Application.AddMessageFilter(new DetectInput ()); // Must come before Run
Application.Run(YourForm);
Courtney de Lautour