Advertisement
WarPie90

Angle mouse

May 2nd, 2022 (edited)
1,512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.97 KB | None | 0 0
  1. function AngleLine(src, dst: TPoint; stepfactor:Double): TPointArray;
  2. var
  3.   i,steps: Int32;
  4.   delta: TPoint;
  5.   x,y,xstep,ystep: Double;
  6. begin
  7.   delta.x := dst.x-src.x;
  8.   delta.y := dst.y-src.y;
  9.  
  10.   if delta.y > 180  then delta.y -= 360;
  11.   if delta.y < -180 then delta.y += 360;
  12.  
  13.   steps := Trunc(Sqrt(Sqr(delta.x) - Sqr(delta.y)) * stepfactor);
  14.  
  15.   if steps = 0 then Exit([dst]);
  16.  
  17.   xstep := delta.x / steps;
  18.   ystep := delta.y / steps;
  19.   SetLength(Result, steps);
  20.   for i:=0 to steps-1 do
  21.   begin
  22.     x += xstep;
  23.     y += ystep;
  24.     Result[i] := [Round(src.x+x), Round(src.y+y)];
  25.   end;
  26. end;
  27.  
  28. procedure SlideMouse(Pt: TPoint; InverseSpeed: Int32=1; stepfactor: Double=0.1);
  29. var
  30.   i: Int32;
  31.   p,q: TPoint;
  32.   TPA: TPointArray;
  33. begin
  34.   GetMousePos(p.x,p.y);
  35.   TPA := AngleLine(p,q, stepfactor);
  36.  
  37.   for i:=0 to High(TPA) do
  38.   begin
  39.     MoveMouse(TPA[i].x, TPA[i].y);
  40.     Sleep(InverseSpeed);
  41.   end;
  42. end;
  43.  
  44.  
  45. begin
  46.   SlideMouse([100,100],1,0.1);
  47. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement