'sleep函数
Private Declare Sub Sleep Lib “kernel32” (ByVal dwMilliseconds As Long)
'获取鼠标坐标
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib “user32” (lpPoint As POINTAPI) As Long
'移动鼠标
Private Declare Function SetCursorPos Lib “user32” (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Sub mouse_event Lib “user32” (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Const MOUSEEVENTF_RIGHTDOWN = &H8
Private Const MOUSEEVENTF_RIGHTUP = &H10
Private Declare Function SetCapture Lib “user32” (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib “user32” () As Long
Private Declare Function PostMessage Lib “user32” Alias “PostMessageA” (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_MOUSEMOVE As Long = &H200 ’ 鼠标移动消息
Private Const WM_LBUTTONDOWN As Long = &H201 ’ 左键按下消息
Private Const WM_LBUTTONUP As Long = &H202 ’ 左键松开消息
Private Sub Command2_Click()
Dim i, j As String
i = Text2.Text
j = Text3.Text
SetCursorPos i, j
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 500
SetCursorPos i - 400, j ’ 向左移动鼠标到指定位置
Sleep 800
SetCursorPos i + 400, j ’ 向右移动鼠标到指定位置
Sleep 800
SetCursorPos i, j - 400 ' 向上移动鼠标到指定位置
Sleep 800
SetCursorPos i, j + 400 ' 向下移动鼠标到指定位置
Sleep 800
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Sleep 500
End Sub
Private Sub Command3_Click()
Dim i, j, k, l, m, n As String
i = Text2.Text
j = Text3.Text
k = Text5.Text
l = Text6.Text
m = Text1.Text
n = Text7.Text
For a = 0 To 3
SetCursorPos i, j
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 500
SetCursorPos i + 300, j ’ 向右移动鼠标到指定位置
Sleep 500
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Sleep 500
Next
End Sub
Private Sub Command6_Click()
Dim m, n As String
m = Text1.Text
n = Text7.Text
SetCursorPos m, n
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
Private Sub Command1_Click()
Dim i, j As String
i = Text2.Text
j = Text3.Text
SetCursorPos i, j
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 500
SetCursorPos i - 600, j ’ 向左移动鼠标到指定位置
Sleep 800
SetCursorPos i + 600, j ’ 向右移动鼠标到指定位置
Sleep 800
SetCursorPos i, j - 300 ' 向上移动鼠标到指定位置
Sleep 800
SetCursorPos i, j + 300 ' 向下移动鼠标到指定位置
Sleep 800
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Sleep 500
End Sub
Private Sub Command4_Click()
Dim k, l As String
k = Text5.Text
l = Text6.Text
SetCursorPos k, l
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
Sleep 500
SetCursorPos k, l - 500 ’ 向上移动鼠标到指定位置
Sleep 500
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Sleep 500
End Sub
Private Sub Timer1_Timer()
Dim POINT As POINTAPI
GetCursorPos POINT
Label1.Caption = “鼠标坐标:” & vbCrLf & vbCrLf & “鼠标横坐标为:” & POINT.X & vbCrLf & “鼠标纵坐标为:” & POINT.Y
End Sub