Commands & Syntax > Commands > Display / Computer Screen >

Image FIND on SCREEN - < display_findimage >() ... [Pro]

www.perfectkeyboard.com

 

Display Image FIND on SCREEN
<display_findimage>("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) on computer screen. If the image is found on the screen 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:

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

Image file

Full path to the image file. This is a bitmap image that is captured using "Capture..." feature in the command editor. In addition, multiple image files are supported by wildcards (* and ?).

2

Start search X

X-coordinate where to start searching on the computer screen.

3

Start search Y

Y-coordinate where to start searching on the computer screen.

4

Variable for image found X

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

5

Variable for image found Y

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

6

Image match

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.

7

Search area width

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

8

Search area height

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

 

Example (Macro Steps):

 

1

<#> <#> This example shows how to find "Start" button on the screen and click on it

2

Macro execution: ONLY COMMANDS

3

Display Image FIND on SCREEN "C:\PicturesForMacros\StartButton.bmp" (Start search X = 0, Start search Y = 0, Variable for image found X = vStartButtonX, Variable for image found Y = vStartButtonY, Image match = 0, Search area width = , Search area height = )

4

IF %vStartButtonX% > -1

5

<#> <#> Start button found, move cursor on it...

6

Mouse MOVE position [ x=%vStartButtonX%, y=%vStartButtonY% ]

7

<#> <#> ...and click

8

Mouse BUTTON: LEFT button DOWN

9

Mouse BUTTON: LEFT button UP

10

ELSE activate

11

<#> <#> Start button not found, show message.

12

Message SHOW "Error" : "The Start button was not find on the screen. Possible reasons are: 1) The Task bar is hidden. 2) The Start button is overlapped by some window. 3) The StartButton.bmp file contains picture other than how Start button looks like." (other parameters: x = -100, y = -100, Window title = Message, Buttons = OK, Timeout (seconds) = 0, Always on top = ).

13

ENDIF

Example (Plain Text):

 

<#> This example shows how to find "Start" button on the screen and click on it

<cmds>

 

<display_findimage>("C:\PicturesForMacros\StartButton.bmp",0,0,vStartButtonX,vStartButtonY, 0)

 

<if>("%vStartButtonX% > -1")

 

   <#> Start button found, move cursor on it...

   <mm>(%vStartButtonX%,%vStartButtonY%)

 

   <#> ...and click

   <mlbd><mlbu>

 

<else>

 

<#> Start button not found, show message.

<msg>(-100,-100,"The Start button was not find on the screen. Possible reasons are:

 

1) The Task bar is hidden.

2) The Start button is overlapped by some window.

3) The StartButton.bmp file contains picture other than how Start button looks like.","Message",1,0,2)

 

<endif>