自定义鼠标点击器
自定义鼠标点击器
Private Type POINTAPI X As Long Y As Long End Type Private Declare Function GetCursorPos Lib "user32" (IpPoint As POINTAPI) As Long Option Explicit Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wflags As Long) As Long Private Const HWND_TOPMOST& = -1 Private Const SWP_NOMOVE = &H1 Private Const SWP_NOSIZE = &H2 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 Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Const MOUSEEVENTF_LEFTDOWN = &H2 Const MOUSEEVENTF_LEFTUP = &H4 Const MOUSEEVENTF_MOVE = &H1 Const MOUSEEVENTF_RIGHTDOWN = &H8 Const MOUSEEVENTF_RIGHTUP = &H10 Private Function getmouse_x_y() As POINTAPI GetCursorPos getmouse_x_y End Function '插入一个command一个timer两个label Private Sub Command1_Click() AutoPressMouse 1000, 530 Sleep 100 AutoPressMouse 1000, 530 Sleep 100 AutoPressMouse 630, 460 Sleep 100 AutoPressMouse 888, 675 Sleep 3000 AutoPressMouse 640, 470 Sleep 100 SetCursorPos 40, 50 RIGHTMOUSE End Sub Private Sub AutoPressMouse(X As Long, Y As Long) SetCursorPos X, Y mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 End Sub Private Sub RIGHTMOUSE() mouse_event MOUSEEVENTF_RIGHTDOWN Or MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 End Sub Private Sub Form_Load() SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Me.Left = 0 Me.Top = 0 Timer1.Enabled = True Timer1.Interval = 50 End Sub Private Sub Timer1_Timer() 'GetCursorPos position Label1.Caption = getmouse_x_y.X Label2.Caption = getmouse_x_y.Y End Sub