Find pixel of a specific color

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Find pixel of a specific color

Post by JRL » Thu Jun 04, 2009 2:59 pm

This script will move the mouse recursively to each pixel of a specified color. What the mouse does once it gets there is up to you.

Code: Select all

//This color is part of my firefox icon.
//It may not be part of yours.
Let>ColorToFind=1134801

GoSub>DrawLine,0,1,ColorToFind,0,0,1,1
ScreenCapture>0,0,1,1,%temp_dir%\Color_%colorToFind%.bmp
FindImagePos>%temp_dir%\Color_%colorToFind%.bmp,SCREEN,1,1,x_pos,y_pos,num_found

Sub>num_found,1
If>num_found<1
  MDL>Color %ColorToFind% not found.
Else
  Let>kk=0
  Repeat>kk
    Add>kk,1
    Let>curX=x_pos_%kk%
    Let>curY=y_pos_%kk%
    MouseMove>CurX,curY
    Wait>0.01
    //Start: Do Something at Pixel Location
    Message>Mouse moved to screen position %CurX%,%CurY%
    Wait>2
    //End: Do Something at Pixel Location
  Until>kk,%num_found%
EndIf

//GoSub>DrawLine,WindowHandle,PenSize,PenColor,XStart,YStart,XEnd,YEnd
SRT>DrawLine
  LibFunc>user32,GetDC,HDC,%DrawLine_var_1%
  LibFunc>gdi32,CreatePen,Penres,0,%DrawLine_var_2%,%DrawLine_var_3%
  LibFunc>gdi32,SelectObject,SOPres,hdc,Penres
  Libfunc>gdi32,MoveToEx,mtres,HDC,%DrawLine_var_4%,%DrawLine_var_5%,0
  LibFunc>gdi32,LineTo,ltres,hdc,%DrawLine_var_6%,%DrawLine_var_7%
  LibFunc>gdi32,DeleteObject,DOres,Penres
  LibFunc>user32,ReleaseDC,RDCres,HDC_1,HDC
END>DrawLine

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts