Want to get up to speed on the latest Visual Basic programming? Includes Visual Basic 6 and Visual InterDev 6. Check out our training programs at http://www.codeoftheweek.com/vbtraining.html
If you would like to get paid for surfing the web, jump to http://www.codeoftheweek.com/paidsurf.html
This issue introduces a module and class combination which can monitor keyboard and mouse activity. It provides the last time the mouse or keyboard was moved or touched. Since you only need to understand how the class module works to use this source code that is all we will document in this issue (in order to keep the issue a reasonable length). Next week we will jump into the module and explain the API details.
The only limitation we are aware of with this class is that it can only monitor the keyboard and mouse activity within your application.
A good use of this routine is to log a user out of an application after a specified period of inactivity.
If you have any questions about using this module, let us know at firstname.lastname@example.org
Public InactivityDelay As Long
Number of seconds before an event will be raised to notify the programmer that inactivity has occurred.
Public InactivityInterval As Long
How often to check for inactivity in seconds. If the InactivityDelay is several minutes or longer we recommend setting this parameter to 5 or more seconds. A timer is used to periodically check to see if the inactivity event should be raised.
Public Event Inactivity()
Raised when application is inactive for the specified amount of time.
Public Property Get Active() As Boolean
True if this class is currently monitoring the activity of the keyboard and mouse.
Public Property Get LastKeyboardActivityTime() As Date
Last time keyboard activity has occurred.
Public Property Get LastMouseActivityTime() As Date
Last time mouse activity has occurred.
Public Property Get LastKeyboardActivitySeconds() As Long
Number of seconds since the last keyboard activity has occurred.
Public Property Get LastMouseActivitySeconds() As Long
Number of seconds since the last mouse activity has occurred.
Public Property Get LastActivitySeconds() As Long
Number of seconds since the last activity (either keyboard or mouse) has occurred.
Public Property Get LastActivityTime() As Date
Time since the last activity (either keyboard or mouse) has occurred.
Public Sub UserInactivity()
This routine is called when the application has been inactivated for InactivityDelay seconds. This routine simply raises an event.
Public Sub Activate()
This should be called to initiate the inactivity monitoring process.
Public Sub Inactivate()
This routine should be called to terminate the inactivity monitoring process.
See above descriptions.
The sample included at http://www.codeoftheweek.com/issues/issue102 shows how to use the above class. It provides a form that shows keyboard and mouse inactivity timers.
' See zip file at http://www.codeoftheweek.com/issues/issue102 for a detailed sample
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0102.html