This is an old revision of the document!
Table of Contents
Image Search with AutoIt
Overview
For years, I've been using AutoIt to accomplish all sorts of automation, and it has proven to be a very capable tool. However, one feature it is missing, which I recently found necessary, is image search. Essentially, I wanted to be able to look for something on the screen that matched an image, and, if possible, with tolerance for imperfect matches.
After some time searching around, I ran in to this thread, which pretty much took me 95% of the way to my desired solution. The key is the AutoHotkey ImageSearch function. Someone capable extracted the ImageSearch function from the AutoHotkey and packed it up in to convenient DLLs, this started the ball rolling. With the contributions of various forum users, a UDF 1) library was put together that acts as a wrapper for the ImageSearch function, which was then packaged with all the necessary DLLs for convenience.
Missing from the functions was the ability to search within a specific window. Instead, the choices were to search the entire desktop or a specified area. I modified the code and added an optional parameter for a window handle, which will supply coordinates and dimensions for the search area. I also made the tolerance parameter optional, defaulting to exact match if omitted.
Syntax
Coming soon™…
I started working on the syntax section, and decided to build a script with some examples, and then got carried away with improving the library. As it came, the functions returned coordinates by using pre-defined global variables that they took by reference and updated. I thought this was silly, so I adjusted them to properly return two-coordinate arrays on success. Also, while experimenting I realized that AutoIt doesn't have built-in macros or constants for the virtual desktop area of multiple monitors, so I figured out how to deal with that.
I need to polish things up, create the example script, re-upload the package, and then update this page.
Download
ImageSearch is the package with the original DLLs, and my modified ImageSearch.au3 include library.