Type POINTAPI ' This holds the logical cursor information
Dim x As Long
Dim y As Long
End Type
Public Declare Function GetCursorPos Lib "user32"(lpPoint As POINTAPI) As Long
Public Declare Function SetCursorPos Lib "user32"(Byval x as long, Byval y as long) As Long
Public Declare PtrSafe Sub Sleep Lib "kernel32"(ByValdwMilliseconds As LongLong)
private staticexternintmouse_event(int dwFlags,int dx,int dy,int cButtons,int dwExtraInfo);constint MOUSEEVENTF_LEFTDOWN =0x0002 ' 模拟鼠标左键按下
constint MOUSEEVENTF_LEFTUP =0x0004 ' 模拟鼠标左键抬起
'delay for1s,2s ....
'input:1,2,3.....
Sub Delay_Sec(Byval sec as Integer)
For i=1 to sec *10
DoEvents
Sleep 100
Next
End Sub
'sleep milliseconds
Sub Delay_MilliSec(Byval milli_sec as Integer)
For i=1 to milli_sec step 100
DoEvents
Sleep 100
Next
End Sub
Function Get_Rand()
Dim a as integer
Dim b as integer
a =Rnd()*100
b = b Mod 30
Get_Rand = b
End Function
Sub mouse_helper()
Dim i as integer
Dim cur_pos as POINTAPI
Dim rnd as integer
For i =1 to 10000
GetCursorPos cur_pos
SetCursorPos cur_pos.x +2, cur_pos.y +1
Delay_MilliSec 100 'sleep For 100ms
mouse_event MOUSEEVENTF_LEFTDOWN,0,0,0,0
Delay_MilliSec 500 'sleep For 500ms
mouse_event MOUSEEVENTF_LEFTUP,0,0,0,0
rnd = Get_Rand
Delay_Sec rnd
Debug.Print "delay For "& rnd &" seconds"
Next
End Sub