CattBoy

Understanding pixelsearch parameters and screen layout

5 posts in this topic

#1 ·  Posted

Hello!

 

Can someone help me understand the basics input parameters for PixelSearch.

Reading the help guide

Parameters

left left coordinate of rectangle.
top top coordinate of rectangle.
right right coordinate of rectangle.
bottom bottom coordinate of rectangle.
color Color value of pixel to find (in decimal or hex).
shade-variation [optional] A number between 0 and 255 to indicate the allowed number of shades of variation of the red, green, and blue components of the color. Default is 0 (exact match).
step [optional] Instead of searching each pixel use a value larger than 1 to skip pixels (for speed). E.g. A value of 2 will only check every other pixel. Default is 1. It is not recommended to use a step value greater than 1.
hwnd

[optional] Window handle to be used. Default is the desktop window

 

If I want to search a rectangle inside the center of my desktop, using the WindowInfo tool from auto it, read the x and y mouse coordinates and use those as the values for the parameters?

 

For this example lets say my screen resolution is 1920x1240.

Drawing a search rectangle inside, for easy math will say it's 3/4th of the size of the full desktop.

Now using the wininfo tool, I find the x and y of where I want the corner of the box to start. Mouse cords (480,930)

and using the wininfo tool ill find the x,y of the opposite corner I want the box to end. (1440,310)

The values of the pixelsearch function should be,  (searching on red)

Pixelseach

Local $aCoord = PixelSearch(480, 930, 1440, 310, 0xFF0000) 

Is that correct?

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

no, it's wrong.

 

it should be like :


 
Local $aCoord = PixelSearch(0, 0, 1, 1, 0xFF0000,0)

so ur box is from point 1 (x1 = 0 , y1 = 0) to point 2 (x2=1 , y2=1)

x1 should be <  x2 and y1 < y2

in ur case i think it should be like :

Local $aCoord = PixelSearch(480, 310, 1440, 930, 0xFF0000, 0)

also u can add color variation t\at the end like:

Local $aCoord = PixelSearch(0, 0, 1, 1, 0xFF0000, 10)

  (it will look for a similar shade to 0xFF0000, if u need exact color change 10 to 0

I hope this helps

 

Edited by toto22

Share this post


Link to post
Share on other sites

#3 ·  Posted

Understood, but doesn't that make the help document wrong or am I misunderstanding?  

You're saying the equation is 

Local $aCoord = PixelSearch(x1, y1, x2, y2, $sColor) 

effectively the bottom left point of the rectangle is x1,y1 and upper right corner is x2,y2.

But reading the help document it lists them as top left corner is x1,y1, button right corner is x2,y2.

I'm only asking for clarification since you've said "I think" and don't seem to confident.  

 

Testing with both of these are not producing the results I'm expecting.

 

Cheers

Share this post


Link to post
Share on other sites

#4 ·  Posted

CattBoy,

Quote

effectively the bottom left point of the rectangle is x1,y1 and upper right corner is x2,y2.

No, for various reasons computer display coordinates start at the top left corner, so your statement should read:

Quote

effectively the top left point of the rectangle is x1,y1 and bottom right corner is x2,y2

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

The following example shows three different search directions in the same rectangular search area.
The middle PixelSearch() is conventionally most commonly used . That is, left to right and top to bottom.

#cs ; From PixelSearch - Remarks in AutoIt help file:-

    The search direction varies as follows:
    Left-to-Right - left < right
    Right-to-Left - right < left
    Top-to-Bottom - top < bottom
    Bottom-to-Top - bottom < top
#ce
; Function -   PixelSearch(left, top, right, bottom, color)   (Parameters are "left", "top", "right", and, "bottom")
;                            |    |     |      |
Local $aCoord = PixelSearch(480, 930,  1440, 310   , 0xFF0000) ; Note: The desktop's top-left corner is (0, 0) as Melba23 inferred.
;  left parameter < right parameter. So search direction is from left to right; and,
;  bottom parameter < top parameter, so, search direction also travels from bottom to Top
; Meaning the search starts at the bottom left hand corner and finishes at the top right hand corner. (480, 930) to (1440, 310) corners of rectangular search area.

; If you want the search to start at the top left corner and finish at the bottom right corner use:-
Local $aCoord = PixelSearch(480, 310, 930, 1440, 0xFF0000) ; (480, 310) to (930, 1440) corners of rectangular search area.
; Search left to right because left parameter < right parameter, and, search top to bottom because top parameter < bottom parameter.


; If you want the search to start at the bottom right corner and finish at the top left corner use:-
Local $aCoord = PixelSearch(930, 1440, 480, 310, 0xFF0000) ; (930, 1440) to (480, 310) corners of rectangular search area.
; Search right to left because right parameter < left parameter, and, search bottom to top because bottom parameter < top parameter.

 

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