Create a new project, put a button command1, put a clock timer1, copy the following code to run, press the button will find the mouse randomly move, hit the border will bounce, and then press the button (or enter) will stop.
' ***************************** Copy the following code *****************************************
PrivateType Pointapi x as Longy as LongEndTypePrivate Declare FunctionGetCursorPosLib "User32"(Lppoint asPOINTAPI) as LongPrivate Declare FunctionSetcursorposLib "User32"(ByValX as Long,ByValY as Long) as LongDimRndx as Integer, Rndy as Integer 'define the random direction and rate of movementPrivate SubCommand1_Click ()IfRndx <>0 andRndy <>0 ThenRndx=0Rndy=0 Exit Sub End If whileRndx =0Rndx=Rnd* --TenWend whileRndy =0Rndy=Rnd* --TenWendEnd SubPrivate SubForm_Load () timer1.interval=TenEnd SubPrivate SubTimer1_timer ()DimPos asPOINTAPI, X as LongY as Long IfRndx =0 andRndy =0 Then Rnd Exit Sub End Ifgetcursorpos POS x= Pos.x +Rndx y= Pos.y +RndyIfX < - Thenx= -Rndx= Rndx * (-1) End If IfX >= screen.width/ the- - Thenx= Screen.width/ the- -Rndx= Rndx * (-1) End If IfY < - Theny= -Rndy= Rndy * (-1) End If IfY >= screen.height/ the- - Theny= Screen.height/ the- -Rndy= Rndy * (-1) End Ifsetcursorpos x, yEnd Sub
Transferred from: http://bbs.bccn.net/thread-407793-1-1.html
VB Random Mobile Mouse