Lore

If it's worth remembering, it's worth writing down, if I find the time, and remember...

User Tools

Site Tools


imagesearch

This is an old revision of the document!


Image Search with AutoIt

Overview

I came across the need to be able to find something on the screen based on a reference image in my AutoIt scripts. However, this is not an available feature of AutoIt. There are functions available for checking individual pixels, but not 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, put together a UDF 1) library that acts as a wrapper.

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 my updated package. It includes the original ImageSearch and MSVC DLLs, along with the updated ImageSearch.au3 library.

1)
User Defined Functions in AutoIt, usually collected in to a .au3 library.
imagesearch.1522950264.txt.gz · Last modified: 2018/04/05 13:44 by thekojukinator