By using listi.net you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes
listi.net
SingleClick, RightClick, DoubleClick - Clicks the mouse somewhere
' (Declarations) needed Public Const MOUSEEVENTF_LEFTDOWN As Long = &H2 Public Const MOUSEEVENTF_LEFTUP As Long = &H4 Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8 Public Const MOUSEEVENTF_RIGHTUP As Long = &H10 #if Win64 Then Public Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long Public Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, dy As Long, ByVa cButtons As Long, ByVal dwExtraInfo As Long)
#Else Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
#End If
#If Win64 Then Public Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long #Else Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long #End If
' Creaet custom variable that holds two integers Type POINTAPI Xcoord As Long Ycoord As Long End Type
sub SingleClick(Optional xoffset, Optional yoffset) If IsMissing(xoffset) Then xoffset = [=randbetween(0,500)] yoffset = [=randbetween(0,500)] else debug.print "click " & xoffset, yoffset SetCursorPos 1369 + xoffset, 100 + yoffset End If
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 End Sub
Sub RightClick() mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0 mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 End Sub
Sub DoubleClick() mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 mouse_event MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0 mouse_event MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 End Sub
sub dragmouse(fromx as long, fromY as Long, toX as long, toY as Long) setCursorPos fromX, fromY mouse_event MOUSEEVENTF_LEFTDOWN, fromX, fromY, 0, 0 setCursorPos toX, toY delay 1 Sendkeys "^c", false End Sub
sub gcp() GetCursorPosDemo End Sub
Sub GetCursorPosDemo() dim llCoord As POINTAPI GetCursorPos llCoord Clipboard_SetData llCoord.Xcoord & "," & llCoord.Ycoord debug.print ; llCoord.Xcoord & "," & llCoord.Ycoord