Home All Groups Group Topic Archive Search About
Author
8 Nov 2006 12:58 PM
Nettan
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

Author
8 Nov 2006 12:58 PM
Kevin
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
<Net***@discussions.microsoft.com> wrote:

Show quoteHide quote
>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
Author
8 Nov 2006 1:11 PM
Kevin
I forgot to add this to the declarations:

Private Structure POINTAPI
     Dim X As Integer
     Dim Y As Integer
End Structure


On Wed, 08 Nov 2006 07:58:55 -0500, Kevin <kmaho***@fireacademy.org>
wrote:

Show quoteHide quote
>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
><Net***@discussions.microsoft.com> wrote:
>
>>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
Author
8 Nov 2006 9:08 PM
iwdu15
couple of problems with that....one is it only detects mouse movements and
two its only checking your app. so if someone used ALT + TAB to change out of
ur app, your app wont receive mouse moves. also, if theyre typing, it wont
recognize that. you can use a Mouse Hook and check the length of time between
the callbacks of that, or u can check the APIs. there was a post around here
a long while back that had that, but it seems to have been deleted....
--
-iwdu15
Author
10 Nov 2006 11:48 PM
Kevin
No, it doesn't matter if the program is minimized, it will detect
mouse movement on the computer, not just the program.
You'll have to use APIs to detect key presses.


On Wed, 8 Nov 2006 13:08:02 -0800, iwdu15 <jmmgoalsteratyahoodotcom>
wrote:

Show quoteHide quote
>couple of problems with that....one is it only detects mouse movements and
>two its only checking your app. so if someone used ALT + TAB to change out of
>ur app, your app wont receive mouse moves. also, if theyre typing, it wont
>recognize that. you can use a Mouse Hook and check the length of time between
>the callbacks of that, or u can check the APIs. there was a post around here
>a long while back that had that, but it seems to have been deleted....
Author
9 Nov 2006 5:25 AM
Cor Ligthert [MVP]
Nettan,

I think that you first have to tell, what you call Idle, by instance the
garbage collector is busy in program Idle time, so the computer is than not
in Idle state.

Cor


Show quoteHide quote
"Nettan" <Net***@discussions.microsoft.com> schreef in bericht
news:0D514B93-9043-4291-9AB1-8FB07D4598F9@microsoft.com...
> 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
Author
10 Nov 2006 7:52 AM
Nettan
Hi

What I meen with idle is that no person is using the computer. What i'm
planning to do is to write a program to log how much time my kids is spending
at the computer.

/Nettan

Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> Nettan,
>
> I think that you first have to tell, what you call Idle, by instance the
> garbage collector is busy in program Idle time, so the computer is than not
> in Idle state.
>
> Cor
>
>
> "Nettan" <Net***@discussions.microsoft.com> schreef in bericht
> news:0D514B93-9043-4291-9AB1-8FB07D4598F9@microsoft.com...
> > 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
>
>
>
Author
11 Nov 2006 5:06 AM
Cor Ligthert [MVP]
Nettan,

Maybe can you search in this newsgroup yourself for that, you are certainly
not the first one who is asking this.

http://groups.google.com/group/microsoft.public.dotnet.languages.vb?hl=en&lr=&ie=UTF-8

Cor

Show quoteHide quote
"Nettan" <Net***@discussions.microsoft.com> schreef in bericht
news:A5FB94B9-EC6D-4643-8DE4-DC21E2E4730B@microsoft.com...
> Hi
>
> What I meen with idle is that no person is using the computer. What i'm
> planning to do is to write a program to log how much time my kids is
> spending
> at the computer.
>
> /Nettan
>
> "Cor Ligthert [MVP]" wrote:
>
>> Nettan,
>>
>> I think that you first have to tell, what you call Idle, by instance the
>> garbage collector is busy in program Idle time, so the computer is than
>> not
>> in Idle state.
>>
>> Cor
>>
>>
>> "Nettan" <Net***@discussions.microsoft.com> schreef in bericht
>> news:0D514B93-9043-4291-9AB1-8FB07D4598F9@microsoft.com...
>> > 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
>>
>>
>>