Visual Basic 6 Help

Eleron

Member
Aug 9, 2001
40
0
0
I need to be able to measure system inactivity so that I can send the program back to the main page if a user does not use the program for a set amount of time. Suggestions??
 

DT4K

Diamond Member
Jan 21, 2002
6,944
3
81
You could use a timer control and reset it using KeyPress and MouseMove events.
Edit:
Declare a global date variable called gdtLastUsed.
Add a timer control to the form and set the interval for 60000 (that's 60 seconds) and set enabled to true.
Add a Timer event for the timer control that compares the current time to gdtLastUsed. This event will get fired every 60 seconds. If the datediff between current time and gdtLastUsed is more than however many minutes, execute code to go back to the other form.
Put in KeyPress and MouseMove events for your form that reset gdtLastUsed to the current time.
This way as long as keys are being pressed and the mouse is being moved, gdtLastUsed will keep getting updated and the code to switch forms won't get executed. But if the system isn't used for however many minutes you decide, when the timer event is fired the form will be switched.

The only thing I'm not sure of, is whether or not pressing keys while in a text box fires a key press event for the form or just for that particular textbox. If it's only for the textbox, you may have to add keypress events for all the text boxes on your form.