User Presence Detection

What I would like to do is determine if the user is actively using a computer running Windows (2000 or newer). Preferably, I would like to do this without resorting to using screensavers.

Reference Information. We have a customer service department, which is located in the search group and can be "Available" or not. If they are “Available,” calls will be redirected to their phone, rather than sitting in line. When the phone rings to the extension, the incoming caller hears the sound of a “ring”, and does not hold the music. Unfortunately, we also have representatives who forget to break out of "Affordable" when they leave for lunch or leave the next day.

The end result is likely to be written using .NET

Any thoughts?

+3
source share
4 answers

To do this, use the GetLastInputInfo () API .

+3
source

, Windows API " ", WTSRegisterSessionNotification WTSUnRegisterSessionNotification. , Windows , , , .

: http://support.microsoft.com/kb/310153

:

private const int NOTIFY_FOR_THIS_SESSION = 0x0;
private const int WM_WTSSESSION_CHANGE = 0x2B1;
private const int WTS_CONSOLE_CONNECT = 0x1;
private const int WTS_CONSOLE_DISCONNECT = 0x2;
private const int WTS_SESSION_LOCK = 0x7;
private const int WTS_SESSION_UNLOCK = 0x8;
private const int WM_DESTROY = 0x2;
private const int WM_ACTIVATEAPP = 0x1C;

// The WTSUnRegisterSessionNotification function unregisters the specified 
// window so that the specified window receives no more session-change notifications.
[DllImport("Wtsapi32.dll")]
private static extern bool WTSUnRegisterSessionNotification(IntPtr hWnd);

// The WTSRegisterSessionNotification function registers the specified 
// window to receive session-change notifications.
[DllImport("Wtsapi32.dll")]
private static extern bool WTSRegisterSessionNotification(IntPtr hWnd, Int32 dwFlags);

// The PostQuitMessage function indicates to the system that a thread 
// has made a request to quit. The PostQuitMessage function is typically used in 
// response to a WM_DESTROY message.
[DllImport("user32.dll")]
private static extern void PostQuitMessage(Int32 nExitCode);

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr PostMessage(HandleRef hwnd, int msg, int wparam, int lparam);

private void Unsubscribe() {
   if (this.Handle != IntPtr.Zero) {
      WTSUnRegisterSessionNotification(this.Handle);
   }
}

private void Subscribe() {
   if (this.Handle != IntPtr.Zero) {
      WTSRegisterSessionNotification(this.Handle, NOTIFY_FOR_THIS_SESSION);
   }
}

// override WndProc in order to catch process the Session-Notification events:
protected override void WndProc(ref Message m) {
   switch (m.Msg) {
      case WM_WTSSESSION_CHANGE:
         switch (m.WParam.ToInt32()) {
            case WTS_CONSOLE_CONNECT:
               // User-switch : Sign-on
               break;
            case WTS_CONSOLE_DISCONNECT:
               // User-switch : Sign-off
               break;
            case WTS_SESSION_LOCK:
               // Screen Lock
               break;
            case WTS_SESSION_UNLOCK:
               // Screen Unlock
               break;
            default:
               break;
         }
         break;
      default:
         break;
   }

   base.WndProc(ref m);
}
+2

You can use the Windows API to add a low-level keyboard / mouse hook, and then mark it as absent if there has been no activity for a while, and then mark it as available when the action starts again.

http://www.codeproject.com/KB/cs/globalhook.aspx there is something on this, but it is in C #.

0
source

Take a look at SetWindowsHookEx and the WH_FOREGROUNDIDLE class.

0
source

All Articles