Jump to content
Sign in to follow this  

ImageSearch Until. (Operator Question)

Recommended Posts



so after searching the Forums, Google, YouTube and Other Forums, I found ImageSearch!

AnyBody Not Shure what ImageSearch is, it is a pixelsearch that looks for a image file in the ImageSearch.au3 directory and then Looks for it on the Screen :)

Great Stuff !

Here is a Little Example where i Search for a .png

#include <ImageSearch.au3>
$x = 0
$y = 0
$res = _imagesearcharea("GreenYellow.png",1,340,150,940,512,$x,$y,100)
If $res = 1 Then
MsgBox(0,"404","Not Found")

Just a quick explain on what happens in the function _imagesearcharea:


_imagesearcharea("image_name" , a*,b*,b*,b*,b*,c*,c*,d*)

a* = Chooses the Return Value for C*. 0 = top x,y Pixel 1 = Center of the Found image.

b* = Coordinates for the Search Window(Top,Left,Right,Bottom)

c* = The Return Variables (See a*)

d* = Variaton between Image and Search.

I'm not sure if the explanation was needed, i just like pretty Topics :D

My actual problem :

I want to make a do_until loop that keeps doing _Imagesearcharea until i drag the desktop icon in the circa Area.

I could do this by just specifying the Search window. But that would be way to Easy :)

Instead i want the Loop to Run until the icon is dragged "near" a predefined spot on one axis using one of the Variables from _Imagesearcharea.

So lets say i want to ImageSearch until i drag it near the middle of the Screen Seen from the X axis.

Until $x = 640

But that is not "Near" ! That is exact ! I want it to Do_Until it is "close" to 640, so it should also stop searching when it is +20 or -20 from 640.

I think i will do this with some advanced Operators ? Math has never been my Strength...

Please Help ;)

Share this post

Link to post
Share on other sites

Hi, Schoening. How about using the Random operator? It allows you to generate a min and a max, so:

Until $x = Rand(625, 640, 1)

Edit: Scratch that, I reread your post after hitting enter. You want it to watch for any number within a certain range of 640...

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post

Link to post
Share on other sites
Until ($x > 620) And ($x <660) Something like that might work, untested. Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post

Link to post
Share on other sites

(Had to Charge my Mp4 ^^ had time) Works ! Thx:D

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

Sign in to follow this  

  • Similar Content

    • Miliardsto
      By Miliardsto
      Hello im using Imagesearc function and almost always it works great but i have seen on 2 computers this function not works. I dont know why and cant figure out whats going on.
      So there are windows 8 64bit and 10 64bit.
      I use script like below so in program folder I got there 4 files
      ImageSearchDLLx32 ImageSearchDLLx64 msvcr110 msvcr110d And it should work I think, it would chose proper file to windows and use it.
      Should I copy Imagesearch to windows directory or system32 directory too or if it is on program folder it is enough?
      I have tried other imagesearch dll and with no success.
      Tried change resolution, colors, some graphic settings etc and no effect
      Maybe someone know what can causing problem with functionality imagesearch function?
      And where I should finally put imagesearch dll file to be sure it would be loaded correctly?
      There are these 4 files
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=x64.Exe #AutoIt3Wrapper_Outfile_x64=x32.Exe #AutoIt3Wrapper_Compile_Both=y #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include-once #include <WinAPIFiles.au3> ; for _WinAPI_Wow64EnableWow64FsRedirection #include <ScreenCapture.au3> ;_ScreenCapture_CaptureWnd etc. ;using this in the example to create a test image, otherwise not neccessary here #include <ButtonConstants.au3> #include <MsgBoxConstants.au3> Local $h_ImageSearchDLL = -1; Will become Handle returned by DllOpen() that will be referenced in the _ImageSearchRegion() function #include <ImageSearchUDF.au3> #Region When running compiled script, Install needed DLLs if they don't exist yet If Not FileExists("ImageSearchDLLx32.dll") Then FileInstall("ImageSearchDLLx32.dll", "ImageSearchDLLx32.dll", 1);FileInstall ( "source", "dest" [, flag = 0] ) If Not FileExists("ImageSearchDLLx64.dll") Then FileInstall("ImageSearchDLLx64.dll", "ImageSearchDLLx64.dll", 1) If Not FileExists("msvcr110d.dll") Then FileInstall("msvcr110d.dll", "msvcr110d.dll", 1);Microsoft Visual C++ Redistributable dll x64 If Not FileExists("msvcr110.dll") Then FileInstall("msvcr110.dll", "msvcr110.dll", 1);Microsoft Visual C++ Redistributable dll x32 #EndRegion HotKeySet("h", "search") Global $x = 0, $y = 0 Func search() Local $img = _ImageSearch('img.bmp', 0, $x, $y, 0) If $img = 1 Then MsgBox("", "", "FOUND IMAGE") Else MsgBox("", "", "NOT FOUND IMAGE") EndIf EndFunc While 1 sleep(200) WEnd #Region TESTING/Example Local $bTesting = False; Change to TRUE to turn on testing/example If $bTesting Then cr(">" & "_ImageSearchStartup()=" & _ImageSearchStartup(), 2) OnAutoItExitRegister(_ImageSearchShutdown) cr("!Testing...") ;using Notepad as a simple example #Region Notepad Snapshot Creation $hWin = WinGetHandle("[CLASS:Notepad]") If Not IsHWnd($hWin) Then If Run("notepad.exe") = 0 Then cr("Couldn't run notepad.exe") Local $hWin = WinWait("[CLASS:Notepad]", "", 10) If $hWin = 0 Then cr("Notepad WinWait Timeout!") EndIf WinSetState($hWin, "", @SW_RESTORE) WinSetState($hWin, "", @SW_SHOW) WinActivate($hWin) Local $testimage = "24bit.bmp" _ScreenCapture_CaptureWnd($testimage, $hWin, 0, 0, -1, -1, False);_ScreenCapture_CaptureWnd ( $sFileName, $hWnd [, $iLeft = 0 [, $iTop = 0 [, $iRight = -1 [, $iBottom = -1 [, $bCursor = True]]]]] ) cr("made Notepad Window screenshot") #EndRegion Notepad Snapshot Creation #Region Test if application appeared Local $y = 0, $x = 0, $result $result = _ImageSearch($testimage, 1, $x, $y, 0, 0);_ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0) If $result = 1 Then cr("! $result=" & $result, 1) MouseMove($x, $y, 0) cr("+" & "recognised notepad! moved mouse to center of notepad!") Else cr("! $result=" & $result, 1) Exit EndIf #EndRegion Test if application appeared #Region Test if application vanished WinSetState($hWin, "", @SW_MINIMIZE) Local $y = 0, $x = 0, $result $result = _ImageSearch($testimage, 1, $x, $y, 0, 0);_ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0) If $result = 1 Then cr("! $result=" & $result, 1) Exit Else cr("! $result=" & $result, 1) cr("+" & "notepad dissapeared!") EndIf #EndRegion Test if application vanished cr() cr("!Test finished") EndIf Exit #EndRegion TESTING/Example #Region ImageSearch Startup/Shutdown Func _ImageSearchStartup() _WinAPI_Wow64EnableWow64FsRedirection(True) $sOSArch = @OSArch ;Check if running on x64 or x32 Windows ;@OSArch Returns one of the following: "X86", "IA64", "X64" - this is the architecture type of the currently running operating system. $sAutoItX64 = @AutoItX64 ;Check if using x64 AutoIt ;@AutoItX64 Returns 1 if the script is running under the native x64 version of AutoIt. If $sOSArch = "X86" Or $sAutoItX64 = 0 Then cr("+>" & "@OSArch=" & $sOSArch & @TAB & "@AutoItX64=" & $sAutoItX64 & @TAB & "therefore using x32 ImageSearch DLL") $h_ImageSearchDLL = DllOpen("ImageSearchDLLx32.dll") If $h_ImageSearchDLL = -1 Then Return "DllOpen failure" ElseIf $sOSArch = "X64" And $sAutoItX64 = 1 Then cr("+>" & "@OSArch=" & $sOSArch & @TAB & "@AutoItX64=" & $sAutoItX64 & @TAB & "therefore using x64 ImageSearch DLL") $h_ImageSearchDLL = DllOpen("ImageSearchDLLx64.dll") If $h_ImageSearchDLL = -1 Then Return "DllOpen failure" Else Return "Inconsistent or incompatible Script/Windows/CPU Architecture" EndIf Return True EndFunc ;==>_ImageSearchStartup Func _ImageSearchShutdown() DllClose($h_ImageSearchDLL) _WinAPI_Wow64EnableWow64FsRedirection(False) cr(">" & "_ImageSearchShutdown() completed") Return True EndFunc ;==>_ImageSearchShutdown #EndRegion ImageSearch Startup/Shutdown #Region My Custom ConsoleWrite/debug Function Func cr($text = "", $addCR = 1, $printTime = False) ;Print to console Static $sToolTip If Not @Compiled Then If $printTime Then ConsoleWrite(@HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " ") ConsoleWrite($text) If $addCR >= 1 Then ConsoleWrite(@CR) If $addCR = 2 Then ConsoleWrite(@CR) Else If $printTime Then $sToolTip &= @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC & " " $sToolTip &= $text If $addCR >= 1 Then $sToolTip &= @CR If $addCR = 2 Then $sToolTip &= @CR ToolTip($sToolTip) EndIf Return $text EndFunc ;==>cr #EndRegion My Custom ConsoleWrite/debug Function  
    • KING_NK
      By KING_NK
      Added Image...I am trying to work out Imagesearch but Its not working perfectly.After pressing Hotkey,Mouse not moving to targeted picture.I tried so hard but still not working.So i post here,need help

    • DeathChicken
      By DeathChicken
      If possible please add or edit the comments to explain how this works.
      ;includes functions from other things
      #include <GDIPlus.au3>
      #include <ScreenCapture.au3>
      HotKeySet("{ESC}", _exit)
      HotKeySet("{F1}", _scan)
      ;global variables
      Global $win_title                    ;name of the window
      Global $area_x                        ;
      Global $area_y                        ;
      Global $area_w                       ;
      Global $area_h                        ;
      Global $cursor                         ;
      Global $rect_file                      ;
      Global $hbmpscreen              ;
      Global $i=  1043                      ;moves the rect
      Global $ii=    378                      ;moves the rect
      Global $x=1044                        ;inner rect offset
      Global $y=501                          ;inner rect offset
      Global $hbmprect                    ;image inside rect
      Global $hscreen                        ;image whole screen
      _GDIPlus_Startup()                    ;?
      ;display hotkeys on screen
      ToolTip("Press F1 to scan | Press ESC to Exit",0,0)
                                          ;infinite loop to keep prog running
      While 1
      Func _scan()
      ;~ reads your screen area:
      ;~ converts screen captured into bmp
      ;~ .  Loads converted bmp to be read
      ;~ compares the bmp of your scanned screen to the actual screen that is being displayed
                                          ;reads screen
      Func _read()
          $hscreen = _ScreenCapture_CaptureWnd("", WinGetHandle($win_title), $area_x, $area_y, $area_x + $area_w, $area_y + $area_h, $cursor)
                                          ;converts screen into bmp
      Func _convert()
                                          ;loads converted screen
      Func _loadBMP()
                                          ;compares savedBMP to current screen
      Func _compare()
      ;If(                              below code                                     ) = (                   below code           ) Then
      If _GDIPlus_BitmapGetPixel($hbmpscreen, ($i + $x) - $area_x, ($ii + $y) - $area_y) = _GDIPlus_BitmapGetPixel($hbmprect, $x, $y) Then
      ;display message box titled found with a message of found
      ;if above is not correct then
                                          ;exit func
      Func _exit()
    • magmet00
      By magmet00
      Do you have a working imagesearch.au3 with working dll?
      and how can i gethandle and send keyboard/mouse commands to hidden d3d window?
      i have tried imagesearch2015 but im getting dll error every time and tried older imagesearchs too in forum what i found.
      i have tried many things to send commands to hidden/background d3dwindow still nothing works.
      Can you help me please?
    • knuxfighter
      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? :(

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.