Alright Guys, so recently I was working on several mouse methods because I need to send a mouse click as fast as possible, move to another color and click it as fast as possible.
So The first method I'm going to be talking about is MMouse and Mouse ( Now these are two different methods but the difference between the two is about 3 milliseconds. So If we look at MMouse's code.
Simba Code:
procedure MMouse(x, y, rx, ry: integer);
var
cx, cy: integer;
randSpeed: Extended;
{$IFDEF UseLaptopMouse}
seg, e, f, g, nx, ny, hypo: Integer;
a, b, c: Extended;
Miss: Boolean;
{$ENDIF}
begin
GetMousePos(cx, cy);
{$IFDEF UseLaptopMouse}
miss := (Random(LMouse_MissChance) = 0);
e:= 0;
a:= x - cx;
b:= y - cy;
c:= Pow(a,2) + Pow(b,2)
hypo:= Round(Sqrt(c));
case hypo of
0: Exit;
1..225: seg:=1;
226..600: seg:= Random(2) + 1;
601..1800: seg:= random(3) + 2;
else seg := 5;
end;
f := Round( a / seg);
g := Round( b / seg);
repeat
Wait(30 + random(50));
{Begin: Modified from MMouse by Benland100}
randSpeed := (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
if randSpeed = 0.0 then
randSpeed := 0.1;
getMousePos(cx,cy);
nx:= (cx + (f * e)) + random(rx);
ny:= (cy + (g * e)) + random(ry);
{End: Modified from MMouse by Benland100}
if Miss then
begin
nx:= nx + RandomRange(rx, rx * 2);
ny:= ny + RandomRange(ry, ry * 2);
end;
WindMouse(cx,cy,nx,ny,11.0,8.0,10.0/randSpeed,12.0/randSpeed,10.0*randSpeed,10.0*randSpeed);
e:= e + 1;
until(e = seg);
GetMousePos(cx, cy);
if not PointInBox(Point(cx, cy), IntToBox(x, y, x + rx, y + ry)) then
begin
Wait(30 + random(30));
WindMouse(cx,cy,(x + random(rx)),(y + random(ry)),11.0,6.0,10.0/randSpeed,15.0/randSpeed,10.0*randSpeed,10.0*randSpeed);
end;
{$ELSE}
randSpeed:= (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
if randSpeed = 0.0 then
randSpeed := 0.1;
X := x + random(rx);
Y := y + random(ry);
WindMouse(cx,cy,x,y,9.0,3.0,10.0/randSpeed,15.0/randSpeed,10.0*randSpeed,10.0*randSpeed);
{$ENDIF}
end;
Now if you analyze that code, you see that it first has to calculate a random range, and passes that into WindMouse which does some more calculating on pushing the mouse on a spline.
So here is my result ( in milliseconds ).
Code:
421
375
452
359
405
374
406
374
422
390
405
390
390
375
421
374
405
390
359
405
390
406
390
405
390
374
437
406
375
452
390
390
As you can see at about 400 milliseconds a push at lets say 200 pushes can really slow down a program.
Now lets look at a direct call to Mouse.
A direct call to the MoveMouse method rather then the MMouse is a api call to Smart/The interpreter.
Code:
250
281
249
250
249
250
234
250
234
250
202
266
234
234
234
280
250
265
218
266
202
203
218
265
281
250
218
218
234
202
250
218
265
266
265
265
234
218
234
281
250
249
234
281
203
250
234
249
219
249
So you can do
Simba Code:
MoveMouse(X,Y);
ClickMouse2(1);
rather then
My Two Cents.