How can i get my my program to reset timer3 everytime a key or mouse button is pressed.
::Looks around for lean::
Printable View
How can i get my my program to reset timer3 everytime a key or mouse button is pressed.
::Looks around for lean::
In the Form KeyDown and MouseDown events, set the Timer.Enabled property to False, then back to True again.
I haven't tried this. Let me know if it works.
In the
Form_KeyDown
and
Form_MouseDown
events, add
Timer3.enabled = false
Timer3.enabled = true
That should do it.
Brucie has it spot on.
Though this will not work if a control has focus.
Set the forms KeyPreview property = True. This means the form intercepts all keys before the reach individual controls.
Not sure about the mouse. It sounds like you are timing inacivity though. You might want to use the forms mouse move event. Other wise if the user clicks on a control the forms mouse_down event will not fire.
You may have to code that into all of the controls on the forms mouse_move or mouse_down events.Code:Sub resetTimer()
Timer3.Enabled = False
Timer3.Enabled = True
End sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
resetTimer
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
resetTimer
End Sub
'or the move event.
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
resetTimer
End Sub
Later.
The form must be visible....I want them to be able to go do what they want and this function would work...for example if no mouse buttons or keys have been pushed in 15 minutes form1.visible = true........Its sort of a idle timer function.....Know what i mean?
Say oooooooooh, you don't want to measure idle time in your program, you want to measure idle time in Windows.
Well, that's easy with the mouse. Just use getcursor pos to find the coordinates of the mouse, and keep checking to see if it's in the same place. That would probably be a lot easier for you than checking to see if a button is pressed.
As far as the keyboard goes, it gets a lot more complicated, because basically you'd have to go through every possible key and check each one to see if any are pressed. See what I'm saying?
Not quite sure what you mean.
Here is an idea though.
Set the timer's interval to 1 minute, or whatever. Then use a counter to count the time elapsed. (this counter will have to be set to 0 when you reset the timer).
Code:Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 60000
End Sub
Private Sub Timer1_Timer()
'test for 15 minutes. I think thats right.
If iTimeElapsed >= (900000) Then
'15 minutes have elapsed
form1.Visible = True
'or what ever
form1.SetFocus
iTimeElapsed = 0
End If
iTimeElapsed = iTimeElapsed + Timer1.interval
End Sub
Hello, fallnwrld.
You said that you want it to be within 15 min. The Timer doesn't go up to 15 minutes. what you can do is use a Do..Loop statement and when a key is pressed, use the Exit Do Function to exit the loop. You can use a Variable add increases each time the Loop is executed, to keep track of the time.
I already know how to get the timer to hit the 15 mark........ My problem is....ok when they click "Begin" On form 1...they go to form2...form2 is a timer the size of a small label that counts down a 2 hour timer.... Now while that is going on....I want another timer that is going on in the back........that if there is no key pressing or movement...then to go back to form1... The ideas you guys game me...requires form2 to remain focus......i guess this will work if form 2 stayed on top of explorer and all the other programs however the zorder command only keeps the form on top of the other forms....
I was thinking of a easier way to do this....to put in the change caption of the label in form 2 that every 15 minutes bring form2 forward....and wait a few seconds for a keypress or a mouse movment...if not then put up idle message.....argh this is frustrating...do you guys see what im trying to do? Keep replying, don't give up on me now.
Which is your main form? We need to know the interactions.
My main form is form1, don't know how that makes a difference?
and form2, holds the timer and label
omg, I already said what this person is trying to do is see how long someone has been idle, NOT how long it's been since they touched the program.
Think of it as a screensaver. He needs the code of a keylogger basically, so he can see if anything has been typed or done within 15 minutes.