Jump to content

HandleImgSearch (Image Search with ImageSearchDLL embedded)

Recommended Posts

Today, I will share my work with image search in inactive windows (windows that run in the background) with tolerances (variations).

After a long time of searching and using image search UDF on the internet. I combined all of that with my experienced and created a UDF name HandleImgSearch.

I have embedded the .dll file in this script so it doesn't need any external files, just include it and run. However, this UDF have a feature that will make it run slower is $MaxImg variable, this variable will allow you to return multiple positions of a finding image.

Some highlights:

  • Very fast with imagesearchdll embedded, no external files required.
  • Tolerances and Max Images are supported.
  • Optimized.
  • Use with handle or full screen easily.
  • Included global functions, so you can run multiple functions in one capture.
  • Examples used for testing included.


  • Image use for searching should be a "24-bit Bitmap" format.
  • I included $IsUser32 variable in some places like _GlobalImgInit, _HandleCapture. This variable allowed you to use DllCall with "PrintWindow" parameter instead of _WinAPI_BitBlt with $SRCCOPY. $IsUser32 = True is useful for window explorer handle, $IsUser32 = False is useful for the emulator handle (NoxPlayer handle example included).
  • If hwnd parameter equal "", it will use hold screen instead.


  • Global Functions: Run multiple functions with one capture.
    • _GlobalImgInit: Initialization variables.
    • _GlobalImgCapture: Capture the handle.
    • _GlobalGetBitmap: Get captured bitmap handle.
    • _GlobalImgSearch: This is the main function of this UDF.
    • _GlobalGetPixel: Get pixel color in captured image.
    • _GlobalPixelCompare: Compare pixel color with captured image pixel color.
  • Handle Functions: Capture every time.
    • _HandleImgSearch: This is the main function of this UDF. Search for images in the handle of the window with the tolerance and maximum image options.
    • _BmpImgSearch: Search picture in picture instead of handle.
    • _HandleGetPixel: Get pixel in handle image.
    • _HandlePixelCompare: Compare color with pixel color of handle image.
    • _HandleCapture: Capture handle screen.

Source code: https://github.com/ltnhanst94/HandleImgSearch

Thanks to:

  • ImageSearchDLL (Author: kangkeng 2008)
  • MemoryCall (Author: Joachim Bauch)
  • BinaryCall (Author: Ward)

GAMERS - Asking for help with ANY kind of game automation is against the forum rules. DON'T DO IT.



Edited by LTNhanSt94

Share this post

Link to post
Share on other sites
Posted (edited)

Sorry for bother

does any English ver. detail for function Description, Parameters and Return values (fully English ver.)

btw, _HandleImgSearch and _HandleImgWaitExist can search multiple img at same time (as A.png|B.png ... etc.)

thanks for au3 development, it's useful to me

thanks again !!


Edited by jimmy123j

Share this post

Link to post
Share on other sites
On 10/4/2020 at 9:45 AM, jimmy123j said:

does any English ver. detail for function Description, Parameters and Return values (fully English ver.)

I have no English version now. Sorry about that. I will add it later when I have free time and update on this thread.

Some default parameters (You can ask me here if you have another thing make you confused):

  • $hwnd: Handle of window you want to find in. If $Handle = "" then it will find images in your current screen.
  • $bmpLocal: Path of local image you want to find.
  • $x, $y, $iWidth, $iHeight: Area of $hwnd image you want to find in. Default values is full image.
  • $MaxImg: Max number of images you want to find (or return).
  • $Tolerance: (0 - 100) This is the variation of color you want to find. This parameter is helpfull when you want to share your app with your friend who use other devices.

Some default return values:

  • $aCords[0][0]: Total number of positions found.
  • $aCords[$i][0]: X coordinate of position $i.
  • $aCords[$i][1]: Y cooridinate of position $i.
  • $aCords[$i][2]: Bitmap width of position $i.
  • $aCords[$i][3]: Bitmap height of position $i.

The width and height of the bitmap are the same as your finding image.

On 10/4/2020 at 9:45 AM, jimmy123j said:

btw, _HandleImgSearch and _HandleImgWaitExist can search multiple img at same time (as A.png|B.png ... etc.)

No, it's now not support this. You can use this by add this a function like:

;~ I have not tested this code yet, but you can use something like this
Func _HandleMultiImgSearch($hwnd, $ImgsPath, $x = 0, $y = 0, $iWidth = -1, $iHeight = -1, $Tolerance = 15, $MaxImg = 1000)
    Local ImgsPathArray = StringSplit($ImgsPath, "|", 2) ;$ImgsPath = 'Path1|Path2|...|PathN'
    Local $Results
    For ImgPath in ImgsPathArray
        $Results = _ArrayAdd($Result, _HandleImgSearch($hwnd, $ImgPath, $x, $y, $iWidth, $iHeight, $Tolerance, $MaxImg))
    Return $Results

;~ Using this func
Local $ImgsPath = 'a.png|b.png|c.png'
Local $Results = _HandleMultiImgSearch($hwnd, $ImgsPath)
ConsoleWrite("> Total of finding images: " & Ubound($Results))
Local $count = 0
For $Coords in $Results
    ;~ An array of positions of each image
    $count += 1
    ConsoleWrite(">> Total of position found of image " & $count & " found: " & Ubound($Coords[0][0]))


Edited by LTNhanSt94

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By SolemnStrike
      I know the title sounds weird, but i couldn't find better words for it...
      I finally managed to have a working image search (yes yes i know image search is evil :p).
      I noticed that even if the script is compiled, the images have to be in my script folder.
      But i don't want that the images i'm searching for on the screen can be viewed, edited etc by every user.
      Is there a way to... uhm... put them in a file like .rar, but one that can't be easily opened? 🤔
      Edit: Now that i think of .rar, maybe using a .rar which is protected by a password... Can autoit search, open, extract, use and delete that? (I guess so, I didn't search for this yet, going to google that asap)
    • By lenclstr746
      Hi guys,
      Some functions of my script are running slowly. Very slow. What is the reason?
      My Code:
    • By Atoxis
      Howdy, I've gone through a lot of au3 forums, and I once had a working Imagesearch script that I got from here.  However, and i'm just totally not sure how but my imagesearch scripts aren't working anymore.
      I'm not new to au3 but i'm not the most experienced with it's syntax/commands.

      Anyways, I've looked over the big threads involving imagesearch.

      Does anyone have a working Imagesearch x64 for win10 that is currently working as of the date with the post.

      Dll's and what not is fine, just when I tell the script to run, I want to be able to find the image on the screen!
      Can't find a working copy so if anyone has one please send it my way lol.

      I've taken all the imagesearch downloads and what not and have played with them but I can't get any of them working on my end, despite others saying they're working.
    • By Ian_Mac
      Func dg_get_images() $x1=0 $y1=0 ;MsgBox(0,"start","start") do $result = _ImageSearch("C:\Users\Server\Desktop\my project\image.png",1,$x1,$y1,0) until $result = 1; if $result=1 Then MouseMove($x1,$y1,3) MouseClick("left", $x1,$y1, 1) WinWait("[Title:TightVNC File Transfer]", "", 10) EndIf  this code works when i search the image, but when i change the location of the desktop icon it can't find the desktop icon anymore.   i wanna try image search area. but i don't know how to use it because i cant understand the parameter for the image search area.  please help me how to solve it thank you in advance.
    • By knuxfighter
      Hello. I've been working with Imagesearch library lately and it did a good work, although I moved to a new PC and didn't copy the old files with me so I downloaded the Imagesearch from the following post
       hoping that it will work. It doesn't though. First time I when I use (run as subscript to my code) the Imagesearch.au3, Scite finds errors (missing spaces). Ctrl+T (scite tidy) fixes these missing spaces but the script returns the following error on every run after:
      _ImageSearch('search.bmp', 0, $x, $y, 0) outputs
      "C:\Users\Knuckles\Desktop\AutoIt\include\ImageSearch.au3" (44) : ==> Subscript used on non-accessible variable.: If $result[0] = "0" Then Return 0 If $result^ ERROR no matter if I put the searched bmp in the script folder or folder img in the script directory. Also, it doesn't matter if the searched image on screen or not, it returns the same.

      Can you provide me any help please? I remember having these problems 2 years ago when I first met the imagesearch library also (I fixed it somehow though in that time). Seems nothing changed.

      Using this version posted in the following post gives the same error:
      Also I run windows 10 64bit and I have no shell options for script editing, running as x86 or whatever as I used to have on windows xp/7. I went through some steps like deleting a key in registry and I even reinstalled autoit and scite but that only resulted to au3 as unrecognized file format and not in getting back the menus and the icon on au3 files. Any thoughts on this?

      Edit: Installing 64-bit AutoIt and using 64bit ImageSearch is no change.

      FOUND WORKING: http://www.codebot.de/index.php/Thread/12713-Imagesearch-au3-funktioniert-nicht/
       but why is this one working and the original aren't? :(
  • Create New...