Solved

Catching an interval of non-activity on computer...

Posted on 2000-02-21
5
143 Views
Last Modified: 2010-05-02
I would like to know how to catch a time period of say 2 minutes or 20 seconds or half an hour of inactivity in an event or a method so i can start a screensaver myself, or I can automatically log-out the user that is looged in.

Please help.  I reward !!
0
Comment
Question by:pmelkebeke
  • 2
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
samopal earned 220 total points
ID: 2542935
You can check a mouse activity in Timer event

In Module

Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Public Type POINTAPI
    X As Long
    Y As Long
End Type

       
Public Sub GetMousePos(GetX As Long, GetY As Long)
    Dim n As POINTAPI
    GetCursorPos n
    GetX = n.X
    GetY = n.Y
End Sub

In Form
'add TextBox and Timer on the form
'Text1.value - number of seconds
'Timer1.Interval=1000 (1sec)

Private Sub Timer1_Timer()
   static aX as long, aY as long
   static TimSec as long
   Dim x as long, y as long
   
   GetMousePos x,y
   if x=aX and y=aY then
      TimSec=TimSec+1
      if TimSec > Text1.Value Then
         Timer1.enabled=false
' do what you want to do
          Timer1.enabled=True
          TimSec=0
      end if
   else
      aX=x
      aY=y
      TimSec=0
   end if
End Sub

HTH
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2542946
Here's one way:


Dim SecsElapsed As Integer

Private Sub Form_Load()
SecsElapsed = 0
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Call Reset_Timer
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
Call Reset_Timer
End Sub

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Call Reset_Timer
End Sub

Private Sub Timer1_Timer()
SecsElapsed = SecsElapsed + 1
If SecsElapsed = 5 Then
   MsgBox ("Times up")
   SecsElapsed = 0
End If
DoEvents
Form1.Caption = SecsElapsed
End Sub

Private Sub Reset_Timer()
SecsElapsed = 0

End Sub
0
 

Author Comment

by:pmelkebeke
ID: 2545118
So I would have to write a keydown, keypress and mousemove evnt for every form and every control on that form.  Come on, there has got to be a more easier way, I hope.
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2545137
WELL, NO ACTUALLY IF YOU SET THE FORM'S kEYPREVIEW TO TRUE, YOU CAN CUT OUT ALL THE KEYDOWNS AND USE THE KEYDOWN OF THE FORM.AND THE MOUSEMOVE OF THE FORM WILL CATCH MOST OF THE OTHER ACTIVITY, MAKING THE PLACES THAT YOU WILL NEED TO ADD THIS CALL TO RESET_TIMER ONLY THE MOUSEMOVES OF TEXTBOXES, ETC... AND YOU WILL PROBABLY HAVE KEYBOARD ACTIVITY THERE ANYWAY (AFTER ALL, THEY ARE TEXTBOXES! ) <G>

GOOD LUCK!!

PS.. SORRY ABOUT THE CAPS... MY KEYBOARD GOT STUCK!
0
 

Author Comment

by:pmelkebeke
ID: 2545228
I hoped there would be a more easier way to do this, but seems not.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now