Jump to content
cypher

mouse over colour click it

Recommended Posts

I was browsing thrue the forum and found some scripts that click when a colour apears at a specific spot on the screen. What I would like is a code where when i move my mouse cursor over a colour it clicks it.

 

Found this script in a previous post

program New;

const
ColorCheck = 17840,206784,245821,12583814,8652036,986097,1671065;
CheckX = 200;
CheckY = 250;
ClickX = 1200;
ClickY = 900;
Check_Wait = 250;

begin
repeat
if(1 <> 2)then
begin
Wait(Check_Wait)
if (GetColor(CheckX, CheckY) = ColorCheck) then
begin
ClickMouse(ClickX, ClickY, True);
end;
end;
until(1 = 2);
end.

 

But thats not what I need, I want to move my mouse and when it goes over colours 17840,206784,245821,12583814,8652036,986097,1671065 I want it to click... Any help woud be greatly appreciated :)

Link to comment
Share on other sites

You can use the FindColor tool, you just use FindColor(x,y,Color,xs,ys,xe,ye)

x and y will be the coordinates of the place where your color will be detected, xs and ys will be the coordinates of the left top of the area which you want to scan and xe, ye will be the bottom right corner.

 

Then you just use ClickMouse(x,y,True) or if you want a realistic mouse and movement, you can use:

 

MoveWindMouse(x,y,rx,ry); //rx and ry are the number of pixels the mouse can be offset from the real location
GetMousePos(x,y);
ClickMouse(x,y,True);

Link to comment
Share on other sites

Whats the proper way to give my variable Color a list of values ?

 

Color = 17840,206784,245821,12583814,8652036,986097,1671065; with ( ) or [ ] gives me syntax error...

Just make multiple variables, Color1, Color2,...

I guess there's a way to make an array of Integers but I always use 1 variable for 1 Integer.

Link to comment
Share on other sites

const
CheckX = 200;
CheckY = 250;
ClickX = 1200;
ClickY = 900;
Check_Wait = 250;

var
 Colors: TIntegerArray;
 I, H: Integer;

begin
 Colors := [17840, 206784, 245821, 12583814, 8652036, 986097, 1671065];
 H := High(Colors);
 for I := 0 to H do
   if (GetColor(CheckX, CheckY) = Colors[i]) then
   begin
     ClickMouse(ClickX, ClickY, True);
     Break;
   end
   else
     Wait(Check_Wait);
end.

Link to comment
Share on other sites

I choose a different approach, plus I thought he wanted to check color under mouse cursor as the mouse roams around?

 

program New;

const
 WaitTime = 25;

var
 X, Y, Color: Integer;
 SearchColors: TIntArray;

begin
 ClearDebug;

 // Colors to search for
 SearchColors := [17840, 206784, 245821, 12583814, 8652036, 986097, 1671065];

 // Repeat until user presses ESC key
 repeat
   // Get color at/under mouse
   GetMousePos(X, Y);
   Color := GetColor(X, Y);

   // If color matches our search colors, then click mouse
   if TIAContains(SearchColors, Color) then
   begin
     writeln('Color ' + IntToStr(Color) + ' found at position (' + IntToStr(X) + ',' + IntToStr(Y) + ')');
     ClickMouse(X, Y, TRUE);
   end;

   // Small wait to reduce lag
   Wait(WaitTime);

 until IsKeyDown(VK_ESCAPE);
end.

Link to comment
Share on other sites

Yes what I want is to move my mouse around and when the colour is under the cursor I want it to click. I'll try the codes out, thanks for your help ;)

 

---

 

Gives me error at line 23 Unknown identifier "TIAContains"

Edited by Freddy
Link to comment
Share on other sites

I'm using v3.28 beta of SCAR. Never occurred to me you might be using 3.27 (which I'm guessing does not contain that function).

 

Try this function to do your compare instead of TIAContains. Ripped this off quickly has no bounds checking at all.

function IntInArray(const Value: Integer; const IntArray: TIntArray): Boolean;
var
 I: Integer;
begin
 for I := 0 to High(IntArray) do
 begin
   Result := (Value = IntArray[i]);
   if Result then
     Exit;
 end;
end;

And this line

if TIAContains(SearchColors, Color) then

would now be

if IntInArray(Color, SearchColors) then

Edited by Bixby Sayz
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...