Solved

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

Posted on 2000-02-21
5
142 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

16 Experts available now in Live!

Get 1:1 Help Now