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:
[x,y]
coordinates on success, and False
on failure. Original search functions returned True/False
success status, while coordinate results were stored in external variables passed in by reference.desktopLeft
, desktopTop
, desktopRight
, desktopBottom
, desktopWidth
, and desktopHeight
.; 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])
I've put it up on GitHub.