PDA

View Full Version : function ClickOnColorChange(P: TPoint): integer;



CynicRus
06-23-2012, 11:19 AM
Maybe this feature is already there, but I could not find it in the documentation - so I made ​​my version of this functional.

//Watching at point P, if color in p was changed - then right click to point
function ClickOnColorChange(P: TPoint; WaitTime: integer): boolean;
var
x,y: integer;
ecolor,tempcolor: integer;//base color
endtime: integer;
begin
x:=P.x;
y:=P.y;
ecolor:=GetColor(x,y);
endtime:=GetSystemTime + WaitTime;
//watching
while (endtime > GetSystemTime) do
begin
tempcolor:=GetColor(x,y);
if ecolor<>tempcolor then
begin
MoveMouse(x,y);
ClickMouse(x, y, mouse_Right);
result:=true;
exit;
end;
end;
end;
//Watching at point P, if color defined as BaseColor in p was changed - then right click to point
function ClickOnColorChangeEx(P: TPoint; BaseColor: integer;WaitTime: integer): boolean;
var
x,y: integer;
tempcolor: integer;
endtime: integer;
begin
x:=P.x;
y:=P.y;
endtime:=GetSystemTime + WaitTime;
//watching
while (endtime > GetSystemTime) do
begin
tempcolor:=GetColor(x,y);
if BaseColor<>tempcolor then
begin
MoveMouse(x,y);
ClickMouse(x, y, mouse_Right);
result:=true;
exit;
end;
end;
end;


UPD: Some code fix.

Kasi
06-23-2012, 11:36 AM
Avoid move mouse/click mouse. use Mouse() instead. and what if we never detect that the color has changed, what then?

Edit : Also if only returning 2 values, use boolean as the function type

CynicRus
06-25-2012, 07:29 AM
Fixed code, added while time to functions.

Joe
06-25-2012, 12:41 PM
At 16 posts and you're making SRL contributions? Well done!
At this rate you'll be an SRL Member by the end of the month...

[D]ude
06-25-2012, 09:04 PM
I'm gonna see if I can use this in a fighting script effectively