Automatic timeout

musson
09-10-2003, 09:17 AM
Hi,

I need an automatic timeout for my program. No matter in what form the user is if he is inactive for more than my timeout he should not be able to continue.

If (timedout) then
enter password again OR log out.
endif

when the user do anything Move mouse, klick bytton or menu the timer should be restarted.

Thanks for help.

Aspen2K
09-10-2003, 09:36 AM
Hmm, In the forms mouse move event, set a condition to 0 iMouseMoved = 0 lets say. Then in a timer, set it the interval to 1000ms, then use iMouseMoved = iMouseMoved +1. If iMouseMoved is over biger then how many ever seconds, then they have been inactive for X long.

Make sense ?

Dim iMouseMoved As Integer

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'set the counter back to zero b/c the mouse moved.
iMouseMoved = 0
End Sub

Private Sub Timer1_Timer()
iMouseMoved = iMouseMoved + 1

If iMouseMoved > 60 Then
'log out code or whatever here

'make sure when ever they log back on
'to set iMouseMoved back to 0
End If

End Sub

Aspen2K

excaliber
09-10-2003, 09:41 AM
Well, you could keep track of mouse movement. If the mouse doesnt move in x amount of time, display the password thing.

Try this link:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=823&lngWId=1

or

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=8776&lngWId=1


Not sure how they do it, but you could implement the GetCursorPos api to see if the mouse has moved in last x seconds/minutes

Also, make sure you check for keyboard events too.

musson
09-10-2003, 11:48 PM
Hi Aspen,

As i understand your solution it would work for the form in focus. But I have several forms in the application and if a user leave the PC with any form in focus there has to be a timeout.

Would you suggest that i implement the timeout for all forms? I must then check for both mouse movements and keyboard activity all the time.

To check for mousemovement i tried this and it works. BUT only for this form. I want something that takes care of all forms or the application in all.

Any idea?


Private timStart, timInactive As Date


Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If (Timer < timStart + timInactive) Then
timStart = Timer
Else
'enter password or logout code goes in here
End If
End Sub

If i do this for all forms i also have to check for keypresses. HOW?
i tried Form_KeyDown and Form_KeyPress but they are never called.

BRg
/Musson


Hmm, In the forms mouse move event, set a condition to 0 iMouseMoved = 0 lets say. Then in a timer, set it the interval to 1000ms, then use iMouseMoved = iMouseMoved +1. If iMouseMoved is over biger then how many ever seconds, then they have been inactive for X long.

Make sense ?

Dim iMouseMoved As Integer

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'set the counter back to zero b/c the mouse moved.
iMouseMoved = 0
End Sub

Private Sub Timer1_Timer()
iMouseMoved = iMouseMoved + 1

If iMouseMoved > 60 Then
'log out code or whatever here

'make sure when ever they log back on
'to set iMouseMoved back to 0
End If

End Sub

Aspen2K

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum