#Include RandomBezier.ahk
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
/* Copyright (C) 2012,2013 Antonio França This script is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This script is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this script. If not, see <http://www.gnu.org/licenses/>. */ ;======================================================================== ; ; Function: RandomBezier ; Description: Moves the mouse through a random Bézier path ; URL (+info): -------------------- ; ; Last Update: 30/May/2013 03:00h BRT ; ; Created by MasterFocus ; - https://github.com/MasterFocus ; - http://masterfocus.ahk4.net ; - http://autohotkey.com/community/viewtopic.php?f=2&t=88198 ; ;======================================================================== RandomBezier( X0, Y0, Xf, Yf, O="" ) { Time := RegExMatch(O,"i)T(\d+)",M)&&(M1>0)? M1: 200 RO := InStr(O,"RO",0) , RD := InStr(O,"RD",0) N:=!RegExMatch(O,"i)P(\d+)(-(\d+))?",M)||(M1<2)? 2: (M1>19)? 19: M1 If ((M:=(M3!="")? ((M3<2)? 2: ((M3>19)? 19: M3)): ((M1=="")? 5: ""))!="") Random, N, %N%, %M% OfT:=RegExMatch(O,"i)OT(-?\d+)",M)? M1: 100, OfB:=RegExMatch(O,"i)OB(-?\d+)",M)? M1: 100 OfL:=RegExMatch(O,"i)OL(-?\d+)",M)? M1: 100, OfR:=RegExMatch(O,"i)OR(-?\d+)",M)? M1: 100 MouseGetPos, XM, YM If ( RO ) X0 += XM, Y0 += YM If ( RD ) Xf += XM, Yf += YM If ( X0 < Xf ) sX := X0-OfL, bX := Xf+OfR Else sX := Xf-OfL, bX := X0+OfR If ( Y0 < Yf ) sY := Y0-OfT, bY := Yf+OfB Else sY := Yf-OfT, bY := Y0+OfB Loop, % (--N)-1 { Random, X%A_Index%, %sX%, %bX% Random, Y%A_Index%, %sY%, %bY% } X%N% := Xf, Y%N% := Yf, E := ( I := A_TickCount ) + Time While ( A_TickCount < E ) { U := 1 - (T := (A_TickCount-I)/Time) Loop, % N + 1 + (X := Y := 0) { Loop, % Idx := A_Index - (F1 := F2 := F3 := 1) F2 *= A_Index, F1 *= A_Index Loop, % D := N-Idx F3 *= A_Index, F1 *= A_Index+Idx M:=(F1/(F2*F3))*((T+0.000001)**Idx)*((U-0.000001)**D), X+=M*X%Idx%, Y+=M*Y%Idx% } MouseMove, %X%, %Y%, 0 Sleep, 1 } MouseMove, X%N%, Y%N%, 0 Return N+1 } |
Example of use.
1 2 3 4 5 6 7 8 9 10 |
; 30/May/2013 03:00h BRT #Include RandomBezier.ahk F5:: ToolTip, % "Points: " RandomBezier( 0, 0, 400, 400, "T500 RO RD OT0 OB0 OL0 OR0 P4-20" ) F6:: ToolTip, % "Points: " RandomBezier( 0, 0, 200, 200, "T1000 RO RD") F7:: ToolTip, % "Points: " RandomBezier( 0, 0, 150, 150, "T1500 RO RD OT150 OB150 OL150 OR150 P6-4" ) F8:: ToolTip, % "Points: " RandomBezier( 0, 0, 200, 0, "T1200 RO RD OT100 OB-100 OL0 OR0 P4-3" ) F9:: ToolTip, % "Points: " RandomBezier( 0, 0, 400, 300, "T1000 RO P5" ) F10:: ToolTip, % "Points: " RandomBezier( 400, 300, 0, 0, "T1000 RD" ) F12::RELOAD ESC::EXITAPP |
Useage.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
======================================================================== X0, Y0, Xf, Yf [, O] + Required parameters: - X0 and Y0 The initial coordinates of the mouse movement - Xf and Yf The final coordinates of the mouse movement + Optional parameters: - O Options string, see remarks below (default: blank) It is possible to specify multiple (case insensitive) options: # "Tx" (where x is a positive number) > The time of the mouse movement, in miliseconds > Defaults to 200 if not present # "RO" > Consider the origin coordinates (X0,Y0) as relative > Defaults to "not relative" if not present # "RD" > Consider the destination coordinates (Xf,Yf) as relative > Defaults to "not relative" if not present # "Px" or "Py-z" (where x, y and z are positive numbers) > "Px" uses exactly 'x' control points > "Py-z" uses a random number of points (from 'y' to 'z', inclusive) > Specifying 1 anywhere will be replaced by 2 instead > Specifying a number greater than 19 anywhere will be replaced by 19 > Defaults to "P2-5" # "OTx" (where x is a number) means Offset Top # "OBx" (where x is a number) means Offset Bottom # "OLx" (where x is a number) means Offset Left # "ORx" (where x is a number) means Offset Right > These offsets, specified in pixels, are actually boundaries that apply to the [X0,Y0,Xf,Yf] rectangle, making it wider or narrower > It is possible to use multiple offsets at the same time > When not specified, an offset defaults to 100 - This means that, if none are specified, the random Bézier control points will be generated within a box that is wider by 100 pixels in all directions, and the trajectory will never go beyond that ======================================================================== |