Click to See Complete Forum and Search --> : Idle time detect
nilch
May 24th, 2001, 10:04 AM
How can I check if the application (VB App only) has been inactive for a certain time (more than 1 minute - because the timer control max value if just abouve i minute).
Is there any API call by which i can keep reading time for say more than 20 minutes and also find if there is no mouse movement for that time. Then i want to fire a idle time check and run a routine on it.
Please help.
Thanx in advance
Nilanjan
Clearcode
May 24th, 2001, 10:15 AM
You could download the EventVB.OCX control from http://www.merrioncomputing.com/Download/index.htm and drop it on to your application main form.
In the form load:
private Sub Form_Load()
VBEventWindow1.hWnd = me.hWnd
End Sub
and then in the events of that control:
private Sub VBEventWindow1_WindowMessageFired(byval msg as EventVB.WindowMessages, byval wParam as Long, byval lParam as Long, Cancel as Boolean, ProcRet as Long)
If msg = WM_ENTERIDLE then
'\\ Thread isn't doing anything...
End If
End Sub
You can then use this to tell you when your application is idle.
HTH,
Duncan
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
coolbiz
May 24th, 2001, 11:19 AM
Actually you can still work with the VB Timer like this:
option Explicit
dim nMaxIdle as Integer ' how long to wait before triggering the idle function
dim nCurIdle as Integer ' cur idle time
private Sub Form_Load()
' init idle counters
nMaxIdle = 20 '20 minutes
nCurIdle = 0 ' 0
' init timer
Timer1.Enabled = false
Timer1.Interval = 60 * 1000 ' 60secs = 1min
' start timer
Timer1.Enabled = true
End Sub
private Sub Timer1_Timer()
' increment timer
nCurIdle = nCurIdle + 1
if (nCurIdle = nMaxIdle) then
' idle time reached - stop timer
Timer1.Enabled = false
' trigger function
Call TriggerIdle()
nCurIdle = 0 ' reset counter
Timer1.Enabled = true ' re-enable timer
end if
End Sub
private Sub TriggerIdle()
' trigger the idle procedure
End Sub
private Sub ResetIdle()
' proc to reset the idle time
Timer1.Enabled = false
nCurIdle = 0
Timer1.Enabled = true
End Sub
private Sub Form_KeyPress(KeyAscii as Integer)
' whenever there is a keypress - reset idle counter
Call ResetIdle()
End Sub
private Sub ConnectToDB()
' disable timer
Timer1.Enabled = false
nCurIdle = 0
' do your processing here
...
' re-enable timer
Timer1.Enabled = true
End Sub
Of course, this will require you to reset the Idle Counter manually everytime you form is used. For example above, I trapped the KeyPress() event and call the ResetIdle() function to reset my idle time. Or you can follow the example in ConnectToDB() function which disable the Idle Timer until the funcion finishes.
The code above have not been tested (I used the same theory in my old program but don't have it handy, so I came up with the code above). You might wanna play with it more :)
-Cool Bizs
nilch
May 24th, 2001, 12:39 PM
Thankx guys. Both the posts were helpful.
Nilanjan
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.