Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 152
  • Last Modified:

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

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
pmelkebeke
Asked:
pmelkebeke
  • 2
  • 2
1 Solution
 
samopalCommented:
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
 
DrDelphiCommented:
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
 
pmelkebekeAuthor Commented:
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
 
DrDelphiCommented:
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
 
pmelkebekeAuthor Commented:
I hoped there would be a more easier way to do this, but seems not.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now