Skip to content

Instantly share code, notes, and snippets.

@v9n
Created December 9, 2022 17:55
Show Gist options
  • Save v9n/b1c14e4b210a87462df8d893635125f7 to your computer and use it in GitHub Desktop.
Save v9n/b1c14e4b210a87462df8d893635125f7 to your computer and use it in GitHub Desktop.
mouse_move
Public Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As LongPtr, ByVal y As LongPtr) As LongPtr
Public Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As LongPtr, ByVal dx As LongPtr, ByVal dy As LongPtr, ByVal cButtons As LongPtr, ByVal dwExtraInfo As LongPtr)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As LongPtr = &H8
Public Const MOUSEEVENTF_RIGHTUP As LongPtr = &H10
Sub DoNotSleepPlease()
Dim i As Integer
For i = 1 To 9999
'For Info, number of iteration
'Cells(1, 1) = i
If Cells(3, 5) = "" Then
SetCursorPos 200, 200 'x and y position
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
WaitPlease
SetCursorPos 300, 300 'x and y position
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
WaitPlease
SetCursorPos 400, 400 'x and y position
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
WaitPlease
SetCursorPos 500, 500 'x and y position
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
WaitPlease
Else
Exit For
End If
Next i
End Sub
Sub WaitPlease()
Dim sngWaitEnd As Single
sngWaitEnd = Timer + 5
Do
DoEvents
Cells(3, 3).Value = Timer
Loop Until Timer >= sngWaitEnd
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment