Skip to content

Instantly share code, notes, and snippets.

@hashtafak
Created September 30, 2020 00:11
Show Gist options
  • Save hashtafak/3fd69cbb144d837a291a90cdf9b56fe1 to your computer and use it in GitHub Desktop.
Save hashtafak/3fd69cbb144d837a291a90cdf9b56fe1 to your computer and use it in GitHub Desktop.
[AutoIt] Bezier Mouse Movement
;~ https://www.elitepvpers.com/forum/general-gaming-discussion/303245-autoit-bezier-mouse-movement.html
Dim $PtX[4]
Dim $PtY[4]
Dim $MaxPt = 3
Func Factorial($n)
$value = 1
For $i = 2 To $n
$value = $value * $i
Next
Return $value
EndFunc
Func Y($t)
$value = 0
For $i = 0 To $MaxPt
$value = $value + $PtY[$i] * Blend($i, $MaxPt, $t)
Next
Return $value
EndFunc
Func X($t)
$value = 0
For $i = 0 To $MaxPt
$value = $value + $PtX[$i] * Blend($i, $MaxPt, $t)
Next
Return $value
EndFunc
Func MouseClickEx($btn, $x, $y, $num)
MouseBezier($x, $y)
MouseClick($btn, $x, $y, $num)
EndFunc
Func MouseBezier($ex, $ey)
$pos = MouseGetPos()
If IsArray($pos) Then
If $pos[0] < $ex Then
$PtX[0] = $pos[0]
$PtX[1] = $pos[0] * Random(2, 3)
$PtX[2] = $PtX[1]
$PtX[3] = $ex
Else
$PtX[0] = $pos[0]
$PtX[1] = $pos[0] / Random(2, 3)
$PtX[2] = $PtX[1]
$PtX[3] = $ex
EndIf
If $pos[1] < $ey Then
$PtY[0] = $pos[1]
$PtY[1] = $pos[1]
$PtY[2] = $pos[1] * Random(2, 3)
$PtY[3] = $ey;
Else
$PtY[0] = $pos[1]
$PtY[1] = $pos[1]
$PtY[2] = $pos[1] / Random(2, 3)
$PtY[3] = $ey;
EndIf
MouseCurve(0, 1)
EndIf
EndFunc
Func MouseCurve($start_t, $stop_t)
$dt = 0.01
$t = $start_t + $dt
While $t < $stop_t
MouseMove(X($t), Y($t),1)
$t = $t + $dt
Wend
;MouseMove(X($start_t), Y($stop_t),1)
EndFunc
Func Blend($i, $n, $t)
Return Factorial($n) / Factorial($i) / Factorial($n - $i) * $t ^ $i * (1 - $t) ^ ($n - $i)
EndFunc
MouseBezier(640, 512)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment