Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Type POINTAPI
x As Long
y As Long
End Type
Public z As POINTAPI
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, _
ByVal dX As Long, _
ByVal dY As Long, _
ByVal dwData As Long, _
ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
' Flags used with mouse_event
Private Const MOUSEEVENTF_ABSOLUTE = &H8000& ' absolute move
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Private Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move
Private Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Private Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
Private Const MOUSEEVENTF_WHEEL = &H800 ' wheel button rolled
Public Sub leftClick()
' Click the mouse, with delay to simulate human timing.
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 20
mouse_event MOUSEEVENTF_LEFTUP, 0, xpt, 0, ypt
End Sub
Sub GetMousePosition()
GetCursorPos z
End Sub
Sub SetMousePosition()
If x < 0 Or x > 1024 Or y < 0 Or y > 768 Then Exit Sub
SetCursorPos z.x, z.y
End Sub