Commands & Syntax > Commands > Window Manipulation >

www.perfectkeyboard.com

 

Image FIND in WINDOW - < win_findimage >() ... [Pro]

 

Window Image FIND in WINDOW
<win_findimage>("Window",Match,"Image file",Start search X,Start search Y,Variable for image found X,Variable for image found Y,Image match,Search area width,Search area height)
Available in: Professional edition

This command searches for defined image(s) within the given window. If the image is found in the window the command sets supplied coordinate variables. If multiple image files are defined using wildcards then [x,y] position variables for each image are created for each image file. For example, if image files are defined using "c:\find_images\*.bmp" and there are "Button.bmp" and "Title.bmp" image files in the "c:\find_images" folder then variables "button.bmp_x" and "button.bmp_y" variables that defines position of the "Button.bmp" image on the screen is created. The same for "title.bmp" file there are "title.bmp_x" and "title.bmp_y" variable created. Using such variables it is possible to determine what images were found and what are their position on the screen. Image file names are always converted to lowercase.

Important:

It is application specific how the window content is drawn within its window and in some cases what is visible on the computer screen as a one image is actually composed by multiple pieces. For this reason, use <display_findimage> command if this command is not working with a particular application.

The bitmap file the command is finding must be captured with the same DPI (or zoom in web browser) as the content presented on the screen. These are typical problems why the command fails:
1. The bitmap file is captured on a monitor with higher/lower DPI than the monitor where the command is finding the image. To prevent this problem always capture the image on the same monitor where the command is executed.

2. The bitmap file is captured in web browser with different zoom setting than the current zoom. To prevent this use the same web browser and the same zoom setings when capturing image and running the macro.

 

#

Parameter name

Parameter description

1

Window

Window Identification Path or HWND of the window where the image is to be searched in. HWND is a unique handle Windows internally uses to identify each window. The HWND can be retrieved by some commands (, ) or is provided by some system variables (_vKeybdFocusWindow_HWND, _vActiveWindow_HWND, _vActiveWindowPrev_HWND).

2

Match

Takes effect only if a window title is used as WinTitleOrHWND parameter. Can be one of these values:
0 - WinTitle can be substring of a window title
1 - WinTitle must exactly match a window title

3

Image file

(Full) path to the image file. This is a bitmap image that is captured using "Capture..." feature in the "win_findimage" command editor. Multiple image files are supported using wildcards (* or ?).

4

Start search X

X-coordinate where to start searching in the window.

5

Start search Y

Y-coordinate where to start searching in the window.

6

Variable for image found X

It is possible to scope searching to an area smaller than the whole window. This attribute specifies the width of the searching area. If this parameter is set to "0" then the whole window width is being searched.

7

Variable for image found Y

It is possible to scope searching to an area smaller than the whole window. This attribute specifies the height of the searching area. If this parameter is set to "0" then the whole window height is being searched.

8

Image match

Name of the variable that receives X-coordinate of the position of the image in the window. If the image is not found then the variable receives "-1".

9

Search area width

Name of the variable that receives Y-coordinate of the position of the image in the window. If the image is not found then the variable receives "-1".

10

Search area height

If 0 then the image does not has to exactly match, a certain level of tolerance is allowed.
If 1 then the image has to exactly match.

 

Example (Macro Steps):

 

1

<#> <#> This macro finds a "sin" button in Calculator window and clicks on it

2

Key Enter

3

Macro execution: ONLY COMMANDS

4

Window Image FIND in WINDOW "[Calculator|CalcFrame|#25|#543]" (Match = Partial, Image file = C:\Temp\sin.bmp, Start search X = 0, Start search Y = 0, Variable for image found X = vSinBtnX, Variable for image found Y = vSinBtnY, Image match = Tolerant, Search area width = 0, Search area height = 0)

5

IF vSinBtnX > -1

6

Window ACTIVATE bring "[Calculator|CalcFrame|#0|#0]" window to top (other parameters: Match = Partial, Window state = Normal, %p4_name = no)

7

Mouse COORDINATES are now RELATIVE to active WINDOW

8

Mouse MOVE position [ x=vSinBtnX, y=vSinBtnY ]

9

Mouse BUTTON: LEFT button DOWN

10

Mouse BUTTON: LEFT button UP

11

ENDIF

Example (Plain Text):

 

<#> This macro finds a "sin" button in Calculator window and clicks on it

<#>

 

<cmds>

 

<win_findimage>("[Calculator|CalcFrame|#25|#543]",0,"C:\Temp\sin.bmp",0,0,vSinBtnX,vSinBtnY,0,0,0)

 

<if>("vSinBtnX > -1")

 

   <actwin>("[Calculator|CalcFrame|#0|#0]",0,0,"no")

   <mousemove_relative_win>

   <mm>(vSinBtnX,vSinBtnY)<mlbd><mlbu>

 

<endif>