This is code someone else gave me. It detects mouse movement. I use it
to log the person out of my program if they leave it the set number of
minutes. sysLogOffSecs is the number of minutes (in seconds) I set to
log them off.
Dim MousePos As POINTAPI 'holds mouse position
Dim mdtLastKBorMouseEvent As Date
Dim mbIsIdle As Boolean
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Call subDetectIdle()
If mbIsIdle Then
'log them off or whatever
End If
End Sub
Public Sub subDetectIdle()
Dim bIsIdle As Boolean
Dim tCurrentPos As POINTAPI
Dim lDiff As Integer
bIsIdle = True
tCurrentPos.X = CInt(Windows.Forms.Cursor.Position.X.ToString)
tCurrentPos.Y = CInt(Windows.Forms.Cursor.Position.Y.ToString)
'Mouse Moved?
If (MousePos.X <tCurrentPos.X) Or (MousePos.Y <>
tCurrentPos.Y) Then
bIsIdle = False
MousePos.X = tCurrentPos.X
MousePos.Y = tCurrentPos.Y
End If
If Not bIsIdle Then 'Not idle...
'Not idle... Update Current Time variable
mdtLastKBorMouseEvent = Now
'Make sure the module level var is set correctly
mbIsIdle = False
Else
'Currently Idle. See how long
If mbIsIdle = False Then
'Number of seconds elapsed?
lDiff =
DateDiff(Microsoft.VisualBasic.DateInterval.Second ,
mdtLastKBorMouseEvent, Now)
If lDiff >= sysLogOffSecs Then
mbIsIdle = True
End If
End If
End If
End Sub
On Wed, 8 Nov 2006 04:58:01 -0800, Nettan
<Ne****@discussions.microsoft.comwrote:
>Hi everyone
I want to now how long the computer is idle. Is there any easy way to do
this in vb.net 2005. Before (in VB6) I checked if the mousepointer hade been
moved.
Thanks
/Nettan