Lore

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

User Tools

Site Tools


imagesearch

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
imagesearch [2018/04/05 13:45] – [Overview] thekojukinatorimagesearch [2018/05/10 15:09] (current) thekojukinator
Line 1: Line 1:
-====== Image Search with AutoIt ======+====== ImageSearch with AutoIt ======
  
 ===== Overview ===== ===== Overview =====
  
-came across the need to be able to find something on the screen based on a reference image in my [[https://www.autoitscript.com|AutoIt]] scriptsHowever, this is not an available feature of //AutoIt//. There are functions available for checking individual pixels, but not images.+needed the ability for [[https://www.autoitscript.com|AutoIt]] to find something on the screen matching a reference imageUnfortunately, 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 [[https://www.autoitscript.com/forum/topic/148005-imagesearch-usage-explanation/?page=4|this thread]]. The key is the [[https://www.autohotkey.com/docs/commands/ImageSearch.htm|AutoHotkey ImageSearch]] function. Someone extracted the //ImageSearch// code from //AutoHotkey//, packed it up in to convenient DLLs, and put together a //UDF// ((//User Defined Functions// in AutoIt, usually collected in to a .au3 library.)) library that acts as a wrapper.+I found a solution in [[https://www.autoitscript.com/forum/topic/148005-imagesearch-usage-explanation/?page=4|this thread]]. The key is the [[https://www.autohotkey.com/docs/commands/ImageSearch.htm|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:+I took the **UDF** library and made the following improvements to it:
  
-  * Unordered List Item +  * Updated relevant functions to return an array of ''[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. 
-===== Syntax =====+  * 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'', and ''desktopHeight''.
  
-Coming soon™...+===== Example =====
  
-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 updatedI 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 monitorsso I figured out how to deal with that. +<code autoit> 
- +; Include the ImageSearch library 
-I need to polish things upcreate the example scriptre-upload the package, and then update this page.+#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($target1) 
 +; If foundmove the mouse to it 
 +If IsArray($result) Then MouseMove($result[0]$result[1]) 
 +</code>
  
 ===== Download ===== ===== Download =====
  
-{{:imagesearch.7z|ImageSearch}} is my updated package. It includes the original //ImageSearch// and //MSVC// DLLs, along with the updated //ImageSearch.au3// library.+I've put it up on [[https://github.com/TheKojukinator/ImageSearch|GitHub]].
  
 {{tag>computing scripting autoit}} {{tag>computing scripting autoit}}
imagesearch.1522950357.txt.gz · Last modified: 2018/04/05 13:45 by thekojukinator