Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I detect user activity?

96 views
Skip to first unread message

Alex K. Angelopoulos (MVP)

unread,
Oct 8, 2002, 4:58:46 AM10/8/02
to
In news:u0x8LVqaCHA.2004@tkmsftngp12,
Ivan Brugiolo [MS] typed:
> There is no class that exposes the information available with the
> GetLastInputInfo API.
>

This is what I like about your answers, Ivan. <g>

Even when you say "You can't get there from here", you at least say _where_ it
is you can't get to.


I wasn't even aware of GetLastInputInfo; I looked it up, found a couple of
newsgroup refs as well using the API name, then put together a VB5/6 class that
can be used pretty easily as a "helper" COM object from script. It uses
GetTickCount so it isn't incredibly hi-res, but for user input a few
milliseconds +/- isn't usually important.

Returned output from calling the IdleTime method is in milliseconds. I did some
testing, and it is worth noting that _very_ minor inputs are detected. A user
sitting still with his or her hand on the mouse is likely to reset the idle time
several times in a minute.

Option Explicit
' Based on code by rolf.gerlicher(at)gmx.de (Rolf Gerlicher)
' Newsgroups: microsoft.public.VB.winapi
' Subject: Re: checking user idle time
' Date: 5 Mar 2002 02:06:51 -0800
' Message-ID: <b40f27f1.02030...@posting.google.com>

Private Type PLASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Private m_typPLII As PLASTINPUTINFO
Private Declare Function GetLastInputInfo Lib "user32" ( _
ByRef plii As PLASTINPUTINFO) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long

Public Function IdleTime() As Long
m_typPLII.dwTime = 0
m_typPLII.cbSize = Len(m_typPLII)
Dim ret As Long
ret = GetLastInputInfo(m_typPLII)
IdleTime = GetTickCount - m_typPLII.dwTime
End Function

--
Please respond in the newsgroup so everyone may benefit.
http://dev.remotenetworktechnology.com
----------
Subscribe to Microsoft's Security Bulletins:
http://www.microsoft.com/technet/security/bulletin/notify.asp

0 new messages