Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake an inactivity timer in Visual Basic 6
DescriptionThis example shows how to make an inactivity timer in Visual Basic 6.
Keywordsinactive, inactivity, user activity, time out, timeout
CategoriesWindows, Controls, ActiveX
 
The InactiveTimer ActiveX control raises its UserInactive event after the application has been idle for a certain length of time.

The control contains an embedded Timer control that fires every second when the control is enabled. When the Timer event fires, the control calls its ElapsedIdleTime function to see how long it has been since the user interacted with the program. If that time exceeds the InactiveInterval value, the control raises its UserInactive event. (The example program closes its form when this event occurs.)

Function ElapsedIdleTime uses the GetLastInputInfo API function to learn when the user last interacted with the program. It subtracts the current time returned by the GetTickCount API function and returns the result.

 
' See if the user has been idle for too long.
Private Sub tmrInactive_Timer()
    If Not UserControl.Ambient.UserMode Then Exit Sub

    If ElapsedIdleTime() > m_InactiveInterval Then _
        RaiseEvent UserInactive
End Sub

' Return the number of seconds
Private Function ElapsedIdleTime() As Long
Dim m_lii As LASTINPUTINFO

    m_lii.cbSize = Len(m_lii)

    If GetLastInputInfo(m_lii) = 0 Then
        Err.Raise vbObjectError + 1001, "InactiveTimer", _
            "Error getting last input information"
    End If

    ElapsedIdleTime = GetTickCount() - m_lii.dwTime
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated