How Can I Tell If My Program Is Idling ?
Printable View
How Can I Tell If My Program Is Idling ?
Please be more clear.
Ingrid.
Its only idle when waiting for events after processing any called functions etc
You should know what functions you have called. If you need to know that a function has finished set a global flag.
eg.
gvfunc_finished=true
Here is I deal with that: ( I have to make my projects password-protected after it went to Idle)
Public IdleCount as Integer
'In frmMain
Timer1.Interval = 60000 ' About a minute
'In Timer1
Sub Timer1_timer()
IdleCount=IdleCount+1
if IdelCount>=10 then ' I send my APP in Idel Mode after 10 min
call IdelMode()
End If
Edn Sub
'But in each and every Active event you must zero IdleCounter = 0 ( every clicks, gotFocus, MouseMove)
My method is far away from a piece of art, but it works.
i think u should better use an API Callback, because the SUB TIMER1 will only be executed if you're programm is not idle.....
I think it depends on how you are defining "idle". If you mean that the user hasn't touched it for a while, then you can simply monitor keyboard and mouse events associated with your program using APIs or probably even VB's keypress and mousemove events. If there has been no activity for a certain period, then initiate your password form.
You can do this with a timer and a global variable that tracks the last time the user pressed a key or moved the mouse on your form. To use this sample, create a form with a timer control (Timer1). Then add the following code to the form's code module.
I hope that at least gives you an idea of one way to approach the problem.Code:Option Explicit
Private Const MaxSeconds As Single = 10 'Number of seconds allowed for inactivity
Private LastUse As Single 'Variable stores time prog was last used
Private Sub Form_Load()
Timer1.Interval = 100
LastUse = Timer
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
LastUse = Timer
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
LastUse = Timer
End Sub
Private Sub Timer1_Timer()
'Here you check to see if the user hasn't used your program for
'a certain time. If the number of seconds specified in the constant
'MaxSeconds has elapsed since the user touched your program, then
'the password box comes up. Don't forget to reset x here, too!
If Timer > LastUse + MaxSeconds Then
InputBox "Enter Password:"
LastUse = Timer
End If
End Sub
Good luck,
~seaweed
[This message has been edited by seaweed (edited 02-18-2000).]
Seaweed!
Your idea is just great, I gonna dupm mine.
The only thing, You realy don't need a Timer,
This will do:
'In any Active event
if Now()> LastUse + MaxSeconds then
'Ask for password
else
'Reset LastUse
LastUse=Now()
end if
Don't you think so"
And you should not use timer()
as soon as it resets to 0 at midnight.