Welcome Guest [Log In] [Register]
Welcome to the Flamefusion forums. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Being able to request Flamefusion software for free, and get it made entirely free, covering your needs!

Being able to submit bug-reports or feature requests to our staff!

Get free support for any computer related subjects, including programming, in all .NET based languages!

Meet other programmers, and team up!

Username:   Password:
Add Reply
Moving mouse in a line; semi-works
Topic Started: Jul 11 2009, 09:51 PM (33 Views)
[FF] Solidacid
Slave Of The Keyboard
hey there!
lately i have found myself needing to move the mouse in a line.
making the mouse move from one point to another is no problem at all, but i want to make the mouse move slowly in a straight line from one point to another.

i have been playing with this for a while and here is my code:
Quote:
 

Shadows Function MouseMove(ByVal X As Integer, ByVal Y As Integer, Optional ByVal speed As Integer = 0)
If speed > 10 Then speed = 10
If speed <= 0 Then
SetCursorPos(X, Y)
Else
Dim mousepos As Point = MouseGetPos()
Dim TempPosX, TempPosY As Double
TempPosX = mousepos.X
TempPosY = mousepos.Y
Dim distance As Double = Math.Sqrt(Math.Pow(Math.Abs(Math.Abs(X) - mousepos.X), 2)) + Math.Pow(Math.Abs(Math.Abs(Y) - mousepos.Y), 2)
Dim ratio As Double
Dim xdistance, ydistance As Double
'xdistance = (TempPosX - X)
'ydistance = (TempPosY - Y)
xdistance = (X - TempPosX)
ydistance = (Y - TempPosY)
If Math.Max(Math.Abs(xdistance), Math.Abs(ydistance)) = Math.Abs(xdistance) Then
ratio = xdistance / ydistance
Dim mousepoints(Math.Abs(xdistance)) As Point
If ydistance > 0 Then
If xdistance > 0 Then
For i = 0 To Math.Abs(xdistance)
'læg ratio til xpos og add 1 til ypos
mousepoints(i).X = TempPosX + ratio
mousepoints(i).Y = TempPosY + 1
TempPosX += ratio
TempPosY += 1
Next
ElseIf xdistance < 0 Then
For i = 0 To Math.Abs(xdistance)
'træk ratio fra xpos og add 1 til ypos
mousepoints(i).X = TempPosX - ratio
mousepoints(i).Y = TempPosY + 1
TempPosX += (ratio) '*-1?
TempPosY += 1
Next
End If
End If
If ydistance < 0 Then
If xdistance > 0 Then
For i = 0 To Math.Abs(xdistance)
'læg ratio til xpos og sub 1 til ypos
mousepoints(i).X = TempPosX + ratio
mousepoints(i).Y = TempPosY - 1
TempPosX += ratio
TempPosY += -1
Next
ElseIf xdistance < 0 Then
For i = 0 To Math.Abs(xdistance)
'træk ratio fra xpos og sub 1 til ypos
mousepoints(i).X = TempPosX - ratio
mousepoints(i).Y = TempPosY - 1
TempPosX += (ratio * -1)
TempPosY += -1
Next
End If
End If
For k = 0 To (mousepoints.Length - 1)
SetCursorPos(mousepoints(k).X, mousepoints(k).Y)
Label1.Text = MouseGetPos("x") & " y: " & MouseGetPos("y")
If MouseGetPos("x") = X And MouseGetPos("y") = Y Then k = (mousepoints.Length - 1)
Sleep(speed * 1.5)
Next
End If

If Math.Max(Math.Abs(xdistance), Math.Abs(ydistance)) = Math.Abs(ydistance) Then
ratio = ydistance / xdistance
Dim mousepoints(Math.Abs(ydistance)) As Point
If ydistance > 0 Then
If xdistance > 0 Then
For i = 0 To Math.Abs(ydistance)
'læg ratio til xpos og add 1 til ypos
mousepoints(i).X = TempPosX + 1
mousepoints(i).Y = TempPosY + ratio
TempPosX += 1
TempPosY += ratio
Next
ElseIf xdistance < 0 Then
For i = 0 To Math.Abs(ydistance)
'træk ratio fra xpos og add 1 til ypos
mousepoints(i).X = TempPosX - 1
mousepoints(i).Y = TempPosY + ratio
TempPosX += -1
TempPosY += ratio
Next
End If
End If
If ydistance < 0 Then
If xdistance > 0 Then
For i = 0 To Math.Abs(ydistance)
'læg ratio til xpos og sub 1 til ypos
mousepoints(i).X = TempPosX + 1
mousepoints(i).Y = TempPosY - ratio
TempPosX += 1
TempPosY += (ratio * -1)
Next
ElseIf xdistance < 0 Then
For i = 0 To Math.Abs(ydistance)
'træk ratio fra xpos og sub 1 til ypos
mousepoints(i).X = (TempPosX - mousepos.X) - 1
mousepoints(i).Y = (TempPosY - mousepos.Y) - ratio
TempPosX += -1
TempPosY += (ratio * -1)
Next
End If
End If
For k = 0 To (mousepoints.Length - 1)
SetCursorPos(mousepoints(k).X, mousepoints(k).Y)
Label1.Text = MouseGetPos("x") & " y: " & MouseGetPos("y")
If MouseGetPos("x") = X And MouseGetPos("y") = Y Then k = (mousepoints.Length - 1)
Sleep(speed * 1.5)
Next
End If


End If
End Function
if the mouse is above and to the left of the target position it works just fine, but if the target is below and/or to the left of the mouse, the mouse will move in strange directions.

any ideas on how i might be able to fix this?
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Get help · Next Topic »
Add Reply

Theme created by tiptopolive. Find more great themes and skins at the ZB Theme Zone.