imagesearch
Table of Contents
ImageSearch with AutoIt
Overview
I needed the ability for AutoIt to find something on the screen matching a reference image. Unfortunately, this is not an available built-in feature. There are functions available for checking individual pixels, but no way to match groups of pixels or images.
I found a solution in this thread. The key is the AutoHotkey ImageSearch function. Someone extracted the ImageSearch code from AutoHotkey, packed it up in to convenient DLLs, and put together a UDF library that acts as a wrapper.
I took the UDF library and made the following improvements to it:
- Updated relevant functions to return an array of
[x,y]
coordinates on success, andFalse
on failure. Original search functions returnedTrue/False
success status, while coordinate results were stored in external variables passed in by reference. - Updated relevant functions with an extra parameter for a window handle, making it possible to limit the search area to the boundaries of a specified window.
- Added the ability to handle multi-monitor desktops by re-defining desktop boundaries in to new global variables
desktopLeft
,desktopTop
,desktopRight
,desktopBottom
,desktopWidth
, anddesktopHeight
.
Example
; Include the ImageSearch library #include ".\ImageSearch\ImageSearch.au3" ; This will be the target image file to search for Local $target = "DemoTarget.png" ; Declare an init a variable to hold the search result Local $result = False ; Find the image across the entire desktop $result = _ImageSearch($target, 1) ; If found, move the mouse to it If IsArray($result) Then MouseMove($result[0], $result[1])
Download
I've put it up on GitHub.
imagesearch.txt · Last modified: 2018/05/10 15:09 by thekojukinator