|
-
Oct 7th, 2002, 11:29 PM
#1
Thread Starter
PowerPoster
Problems with a mouse API function...
I'm using this function I wrote:
VB Code:
Public Sub MoveMouse(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long)
'Rectangle
Dim mmRECT As RECT
'Y increment
Dim XInc As Double
Dim YInc As Double
XInc = ((X2 - X1) / 10000)
YInc = ((Y2 - Y1) / 10000)
'Set mouse cursor to hand
Screen.MousePointer = vbCustom
Screen.MouseIcon = LoadResPicture("POINT", vbResCursor)
'Move mouse
Dim i As Double
For i = 0 To 10000
mmRECT.Top = Y1 + (YInc * i)
mmRECT.Bottom = Y1 + (YInc * i) + 1
mmRECT.Left = X1 + (XInc * i)
mmRECT.Right = X1 + (XInc * i) + 1
ClipCursor mmRECT
PauseMe 250
Next
'Set cursor to default
Screen.MousePointer = vbDefault
'Release mouse
ClipCursor &H0
End Sub
'Pause system in a loop temporarily
Public Sub PauseMe(lngPauseDuration As Long)
Dim i As Long
Do Until i = lngPauseDuration
i = i + 1
DoEvents
Loop
End Sub
To force the mouse to move (in a straight line) between two points. The PauseMe function just holds up the processor for a tiny period of time so visual effects can actually be seen (they're too fast otherwise).
Anyway, this function works fine if the points are:
X1 = 0
Y1 = 0
X2 = 12000
Y2 = 12000
(topleft->bottom right)
but in reverse, nothing happens for awhile, and then some time later, the mouse moves as I want it to... it's really quite odd....
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 7th, 2002, 11:32 PM
#2
Thread Starter
PowerPoster
Hmmm more weirdness. In the first instance (top-left - bottom right), the cursor moves, but that loop isn't exited correctly... someone have a go and see what happens?
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 8th, 2002, 12:03 AM
#3
Thread Starter
PowerPoster
Bugger it, it's right now. 
Here's a working sub to move the cursor between two points if anyone wants it.
VB Code:
'Move mouse from x1/y1 to x2/y2
Public Sub MoveMouse(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long)
'Rectangle
Dim mmRECT As RECT
'Y increment
Dim XInc As Double
Dim YInc As Double
XInc = ((X2 - X1) / 1000)
YInc = ((Y2 - Y1) / 1000)
'Set mouse cursor to hand
Screen.MousePointer = vbCustom
Screen.MouseIcon = LoadResPicture("POINT", vbResCursor)
'Move mouse
Dim i As Double
Open "./test.txt" For Output As #1
For i = 0 To 1000
mmRECT.Top = Y1 + (YInc * i)
mmRECT.Bottom = Y1 + (YInc * i) + 1
mmRECT.Left = X1 + (XInc * i)
mmRECT.Right = X1 + (XInc * i) + 1
ClipCursor mmRECT
PauseMe 250
Next
'Set cursor to default
Screen.MousePointer = vbDefault
'Release mouse
ClipCursor &H0
End Sub
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
-
Oct 8th, 2002, 12:37 AM
#4
-= B u g S l a y e r =-
Thanks rjlohan
-
Oct 8th, 2002, 01:16 AM
#5
Thread Starter
PowerPoster
I'm sure you'll find a use for it somewhere.... 

Note: There is an API - SetCursorPos which can cut this code down considerably, but my way locks the mouse, so the user can't move it - much nicer visually.
-----------------------------------------
-RJ
[email protected]
-----------------------------------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|