Solved

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

Posted on 2000-02-21
5
148 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

691 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