greeting,
how EXE can close by itself , if no activity on a certain period of time.
thnks
cyrus
Printable View
greeting,
how EXE can close by itself , if no activity on a certain period of time.
thnks
cyrus
To close it, obviously use Unload Me for each form, but to test for inactivity, that is where the fun comes in.
You must have a Timer on your form, testing a Boolean variable. Then, for each control on your form, you have to set that variable to True / False whenever any event happens. Here is a very basic example :
It may not be 100% correct, but it should give you a good start.Code:Option Explicit
Private blnActive As Boolean
Private Sub Command1_Click()
blnActive = True
End Sub
Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
blnActive = True
End Sub
Private Sub Command1_KeyPress(KeyAscii As Integer)
blnActive = True
End Sub
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnActive = True
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnActive = True
End Sub
Private Sub Form_Click()
blnActive = True
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
blnActive = True
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
blnActive = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnActive = True
End Sub
Private Sub Text1_Change()
blnActive = True
End Sub
Private Sub Text1_Click()
blnActive = True
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
blnActive = True
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
blnActive = True
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnActive = True
End Sub
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnActive = True
End Sub
Private Sub Timer1_Timer()
Static intCount As Integer
If Not blnActive Then
intCount = intCount + 1
Label1.Caption = intCount
If intCount >= 20 Then
Unload Me
End If
Else
intCount = 0
Label1.Caption = intCount
End If
End Sub
In addition to HanneSThEGreaT, you can reference How to Make a Program close itself if it has been inactive for long time also.
Hello,
Would it really be a bad idea using the GetInputState function of user32 ?
It :
It needs then a timer and a static variable (to retrieve the time T1 each time there is an activity). You decide to close if The Time T2 - Time T1 >= accepted delay.Quote:
determines whether there are mouse-button or keyboard messages in the calling thread's message queue.
You would that way save to attach code to every control ...
Not bad, but seems tricky, to me.
You'd have to interrogate GetInputState() very often because messages are consumed very fast, so you might miss the time, them being in the message queue, thinking there was no activity and closing.
I suppose you might have to subclass the window, so as every message is running over your own WindowProc where you can always reset the timeout-counter.