|
|
Title | See if the mouse is moving even when it is not over the program |
Description | This 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. |
Keywords | mouse, cursor, CursorPos |
Categories | Tips 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
|
|
|
|
|
|