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/05/10 14:41] 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:
  
-  * 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.+  * 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.
   * 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.   * 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//.+  * 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''
 + 
 +===== Example ===== 
 + 
 +<code autoit> 
 +; 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]) 
 +</code>
  
 ===== Download ===== ===== Download =====
imagesearch.1525977677.txt.gz · Last modified: 2018/05/10 14:41 by thekojukinator