|
-
May 30th, 2000, 10:52 PM
#1
Thread Starter
Hyperactive Member
How can i get my my program to reset timer3 everytime a key or mouse button is pressed.
::Looks around for lean::
-RaY
VB .Net 2010 (Ultimate)
-
May 30th, 2000, 10:59 PM
#2
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.
"It's cold gin time again ..."
Check out my website here.
-
May 30th, 2000, 11:01 PM
#3
Addicted Member
In the
Form_KeyDown
and
Form_MouseDown
events, add
Timer3.enabled = false
Timer3.enabled = true
That should do it.
-
May 30th, 2000, 11:09 PM
#4
Fanatic Member
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.
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
You may have to code that into all of the controls on the forms mouse_move or mouse_down events.
Later.
Iain, thats with an i by the way!
-
May 30th, 2000, 11:13 PM
#5
Thread Starter
Hyperactive Member
That would work but
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?
-RaY
VB .Net 2010 (Ultimate)
-
May 30th, 2000, 11:26 PM
#6
Addicted Member
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?
-
May 30th, 2000, 11:27 PM
#7
Fanatic Member
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
Iain, thats with an i by the way!
-
May 31st, 2000, 02:54 AM
#8
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.
-
Jun 1st, 2000, 08:12 PM
#9
Thread Starter
Hyperactive Member
Thats not the prob
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.
-RaY
VB .Net 2010 (Ultimate)
-
Jun 1st, 2000, 08:39 PM
#10
Fanatic Member
Which is your main form? We need to know the interactions.
Iain, thats with an i by the way!
-
Jun 1st, 2000, 09:58 PM
#11
Thread Starter
Hyperactive Member
lain
My main form is form1, don't know how that makes a difference?
and form2, holds the timer and label
-RaY
VB .Net 2010 (Ultimate)
-
Jun 2nd, 2000, 12:32 AM
#12
Addicted Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|