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
 
 
 
 
 
TitleSee if the mouse is moving even when it is not over the program
DescriptionThis example shows how to see if the mouse is moving even when it is not over the program in Visual Basic 6. The program uses a Timer to periodically use the API function to see if the mouse has moved.
Keywordsmouse, cursor, CursorPos
CategoriesTips and Tricks, API
 
Use a Timer to periodically check the mouse's position using the GetCursorPos API function.
 
' Get the mouse's current position and see if it
' has moved since last time.
Private Sub tmrCheckMouse_Timer()
Static done_before As Boolean
Static last_point As POINTAPI

Dim cur_point As POINTAPI

    ' If we have done this before, compare the
    ' current mouse position to the previous one.
    If done_before Then
        GetCursorPos cur_point
        If (cur_point.x <> last_point.x) Or _
           (cur_point.y <> last_point.y) _
        Then
            lblMoving.Caption = "Moving"
        Else
            lblMoving.Caption = "Stationary"
        End If
        
        ' Record the cursor position.
        last_point = cur_point
    Else
        done_before = True
        
        ' Just record the cursor position.
        GetCursorPos last_point
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated