Sign in to follow this  
Followers 0
MarioTester

Pixel search and Mouseclicking

4 posts in this topic

Hey AutoIt Forum, this is my first post!

This is the first language I'm learning, and I've been learning a lot in this forum, however, there's one particular thing I could not find anywhere, well, let me explain.

My problem is the following: Suppose I had to create a script that would:

1) Check the pixel color in x = 100,y = 200 to see if it's white.

2) Now, if it is, click it, otherwise, ignore it.

3) Check the pixel color in x = 140, y = 200 to see if it's white

4)If it is, click it, otherwise, ignore it.

5)Check the pixel color in x = 180, y = 240 to see if it's white

6)...

Ok, so, in short this is the basic idea. I found a way to do it with rudimentary things I know, and it works fairly well, however, the script is massive and slow. I would like to know if there's a way of using other tools and operators I don't know about to speed up the whole thing.

While 1
$quad11 = PixelSearch(182, 445, 183, 446,0xFFFDFF, 5)
$Quad12 = PixelSearch(222 ,445 ,223 ,446,0xFFFDFF, 5)
$Quad13 = PixelSearch(262 ,445 ,263 ,446,0xFFFDFF, 5)
$Quad14 = PixelSearch(302 ,445 ,303 ,446,0xFFFDFF, 5)
$Quad15 = PixelSearch(342 ,445 ,343 ,446,0xFFFDFF, 5)
$Quad16 = PixelSearch(382 ,445 ,383 ,446,0xFFFDFF, 5)
$Quad17 = PixelSearch(422 ,445 ,423 ,446,0xFFFDFF, 5)
$Quad18 = PixelSearch(462 ,445 ,463 ,446,0xFFFDFF, 5)
$Quad19 = PixelSearch(502 ,445 ,503 ,446,0xFFFDFF, 5)
$Quad20 = PixelSearch(542 ,445 ,543 ,446,0xFFFDFF, 5)
$Quad21 = PixelSearch(582 ,445 ,583 ,446,0xFFFDFF, 5)
$Quad22 = PixelSearch(622 ,445 ,623 ,446,0xFFFDFF, 5)
$Quad23 = PixelSearch(662 ,445 ,663 ,446,0xFFFDFF, 5)
$Quad24 = PixelSearch(222 ,485 ,223 ,486,0xFFFDFF, 5)
$Quad25 = PixelSearch(262 ,485 ,263 ,486,0xFFFDFF, 5)
$Quad26 = PixelSearch(302 ,485 ,303 ,486,0xFFFDFF, 5)
$Quad27 = PixelSearch(342 ,485 ,343 ,486,0xFFFDFF, 5)
$Quad28 = PixelSearch(382 ,485 ,383 ,486,0xFFFDFF, 5)
$Quad29 = PixelSearch(422 ,485 ,423 ,486,0xFFFDFF, 5)
$Quad30 = PixelSearch(462 ,485 ,463 ,486,0xFFFDFF, 5)
$Quad31 = PixelSearch(502 ,485 ,503 ,486,0xFFFDFF, 5)
$Quad32 = PixelSearch(542 ,485 ,543 ,486,0xFFFDFF, 5)
$Quad33 = PixelSearch(582 ,485 ,583 ,486,0xFFFDFF, 5)
$Quad34 = PixelSearch(622 ,485 ,623 ,486,0xFFFDFF, 5)
$Quad35 = PixelSearch(662 ,485 ,663 ,486,0xFFFDFF, 5)
If IsArray($quad11) = 1 Then
MouseClick('left', $quad11[0], $quad11[1], 1, 0)
EndIf
If IsArray($quad12) = 1 Then
MouseClick('left', $quad12[0],$quad12[1], 1, 0)
EndIf
If IsArray($quad13) = 1 Then
MouseClick('left', $quad13[0],$quad13[1], 1, 0)
EndIf
If IsArray($quad14) = 1 Then
MouseClick('left', $quad14[0],$quad14[1], 1, 0)
EndIf
If IsArray($quad15) = 1 Then
MouseClick('left', $quad15[0],$quad15[1], 1, 0)
EndIf
If IsArray($quad16) = 1 Then
MouseClick('left', $quad16[0],$quad16[1], 1, 0)
EndIf
If IsArray($quad17) = 1 Then
MouseClick('left', $quad17[0],$quad17[1], 1, 0)
EndIf
If IsArray($quad18) = 1 Then
MouseClick('left', $quad18[0],$quad18[1], 1, 0)
EndIf
If IsArray($quad19) = 1 Then
MouseClick('left', $quad19[0],$quad19[1], 1, 0)
EndIf
If IsArray($quad20) = 1 Then
MouseClick('left', $quad20[0],$quad20[1], 1, 0)
EndIf
If IsArray($quad21) = 1 Then
MouseClick('left', $quad21[0],$quad21[1], 1, 0)
EndIf
If IsArray($quad22) = 1 Then
MouseClick('left', $quad22[0],$quad22[1], 1, 0)
EndIf
If IsArray($quad23) = 1 Then
MouseClick('left', $quad23[0],$quad23[1], 1, 0)
EndIf
If IsArray($quad24) = 1 Then
MouseClick('left', $quad24[0],$quad24[1], 1, 0)
EndIf
If IsArray($quad25) = 1 Then
MouseClick('left', $quad25[0],$quad25[1], 1, 0)
EndIf
If IsArray($quad26) = 1 Then
MouseClick('left', $quad26[0],$quad26[1], 1, 0)
EndIf
If IsArray($quad27) = 1 Then
MouseClick('left', $quad27[0],$quad27[1], 1, 0)
EndIf
If IsArray($quad28) = 1 Then
MouseClick('left', $quad28[0],$quad28[1], 1, 0)
EndIf
If IsArray($quad29) = 1 Then
MouseClick('left', $quad29[0],$quad29[1], 1, 0)
EndIf
If IsArray($quad30) = 1 Then
MouseClick('left', $quad30[0],$quad30[1], 1, 0)
EndIf
If IsArray($quad31) = 1 Then
MouseClick('left', $quad31[0],$quad31[1], 1, 0)
EndIf
If IsArray($quad32) = 1 Then
MouseClick('left', $quad32[0],$quad32[1], 1, 0)
EndIF
If IsArray($quad33) = 1 Then
MouseClick('left', $quad33[0],$quad33[1], 1, 0)
EndIf
If IsArray($quad34) = 1 Then
MouseClick('left', $quad34[0],$quad34[1], 1, 0)
EndIf
If IsArray($quad35) = 1 Then
MouseClick('left', $quad35[0],$quad35[1], 1, 0)
EndIf
WEnd

Now, just a few observation:

I'm only displaying the first 24, instead of 72, because there's no need to put the full script here when it's obvious that there will only be repetitions;

Since I just needed one pixel, and not the "pixel retangle" I used its coordinates as (x, y, x+1, y+1), I couldn't find a better way to do that.

OBS: One extra thing, in SciTE is there anyway of making hotkeys global so I could stop scripts without having to bring SciTE to front?

Thanks in advance!


TL;DR I'm new to autoit or any programming language whatsoever.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

here is a shorter version of your script, using PixelGetColor() and two loops and you can search the scite help for HotKey usage

$xStart=182
$yStart=445
$xStep=40
$yStep=40
$xStepNo=10
$yStepNo=10

For $i=0 to $yStepNo
$y=$yStart+$yStep*$i
$j=0
Do
  $x=$xStart+$xStep*$j
  $pc=PixelGetColor($x,$y)
  If hex($pc,6)="FFFDFF" Then MouseClick("left",$x,$y)
  $j=$j+1
Until $j=$xStepNo+1
Next
MsgBox(0,"","Script ended succesfuly")

HotKey example

HotKeySet("{Esc}","_Quit")
While 1
Sleep(100)
WEnd
Func _Quit()
Exit
EndFunc

and this is for non sistematic coords

Global $c[101]
For $i=1 to 100
$c[$i]=""
Next
$c[1]="125,234"
$c[2]="123,274"
;.....................
$c[100]="400,400"
For $i=1 To 100
If $c[$i]<>"" Then
$coord=StringSplit($c[$i],",")
$pc=PixelGetColor($coord[1],$coord[2])
If Hex($pc,6)="FFFDFF" Then MouseClick("left",$coord[1],$coord[2],1,0)
EndIf
Next
MsgBox(0,"","Script ended succesfuly",3)

hope this helps!

Edited by Blinky

Share this post


Link to post
Share on other sites

Wow. Man, thanks a lot, thats PERFECT! I learned a lot of new tools from your scripts, seriously, thanks a lot.


TL;DR I'm new to autoit or any programming language whatsoever.

Share this post


Link to post
Share on other sites

your welome!

you can also view my other scripts. u could find something useful :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0