11

I want to detect if the system is idle, ie: user not using the system. I want it like the Windows Live Messenger it changes automatically to away when I leave the computer for a time like 3 minutes, I want to set this time within the code.

I`m working on the WPF under C# environment using both visual studio 2008 and 2010 so if here is a way that work on both that`ll be great.

sikas
  • 5,435
  • 28
  • 75
  • 120

3 Answers3

9

There's an article on CodeProject that should get you started.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

I've provided an answer for detecting inactivity and activity in WPF and it might be interesting for you:

Community
  • 1
  • 1
Martin Buberl
  • 45,844
  • 25
  • 100
  • 144
0

Windows does provide some API's for that, although they're not reliable for multiple sessions or something like that.
What I used is a hook to WW_MOUSE_LL with SetWindowsHookEx(); That's in C. Must be pretty similar for C#.
Basicaly whenever the user does something with the mouse, the timer starts from 0 again, and if the timer reaches some value, you do something upon that(act-if system is idle).
You could also hook it with the keyboard, in case the user is just typing, and share the timer between the two threads. It works wonderful for me.

kundrata
  • 651
  • 3
  • 12
  • 24