Jump to content

ImageSearch Usage Explanation


Centrally
 Share

Recommended Posts

ok I got to the bottom of my issue, turns out the problem was my dll, I was using the 32 bit, which Im running windows 8.1 which is 64 bit.  So the version (32 bit) didnt work, I used the 64 bit and now I have a problem with buffer overruns, access violations etc.  I read in the thread I should compile and run as 32 bit, but I and testing by running from SciTE. how can I force it to use the 32 bit while it runs by pressing f5?

Link to comment
Share on other sites

Ok well.... this is what I have done and it works:

I made a PNG of my image to search

I downloaded and used the x64 version of the DLL

I placed the DLL in the program directory WITH the autoit exe, as this is the first place a program looks for DLLs, confirmed with Procmon from sys internals.

and I used #AutoIt3Wrapper_UseX64=Y

No more errors, thank you.... PS would still be interested to know if there are more recent version of the DLL... I have one that was created on Jan 24 2010 and is 82KB.

Thanks

Link to comment
Share on other sites

  • 2 months later...

Ok well.... this is what I have done and it works:

I made a PNG of my image to search

I downloaded and used the x64 version of the DLL

I placed the DLL in the program directory WITH the autoit exe, as this is the first place a program looks for DLLs, confirmed with Procmon from sys internals.

and I used #AutoIt3Wrapper_UseX64=Y

No more errors, thank you.... PS would still be interested to know if there are more recent version of the DLL... I have one that was created on Jan 24 2010 and is 82KB.

Thanks

Thank You Very much I already downloaded ImageSearch 64bit , everything  now is working very well,  but i must Compile  Script As 64Bit to Run it without Any Problems.

Link to comment
Share on other sites

  • 3 weeks later...

Can this script be bade to work from the editor ? Or do i have to compile it to work first ?

Kinda difficult to work with when unable to test on the fly.

thanks !

Edited by tonycst
Link to comment
Share on other sites

  • 2 weeks later...

Can this script be bade to work from the editor ? Or do i have to compile it to work first ?

Kinda difficult to work with when unable to test on the fly.

thanks !

Hi, i am also with this problem

The ImageSearch dont work from the SciTE Editor, but works running with "Run Script x64" in windows explorer.

I also tried "#AutoIt3Wrapper_UseX64=Y", but no success.

Can anyone help?

Thanks in advance

Link to comment
Share on other sites

  • Developers

You have the full version of SciTE4AutoIt3 installed? Show me the SciTE Console output when running the script with that Directive in it.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hello,
When running my script I have the following error (see picture).


This error occurs after the execution by Debugger AutoIt v0.47.0.0.

Error.thumb.png.11e1a08cfccf9cbe731565a6
The version of AutoIt and SciTE4AutoIt3 are the last, I've downloaded and installed yesterday.
My CPU is a Windows 8.1 x64, but because the script is for another CPU, I installed AutoIt selecting the x86 version.


About ImageSearch DLL, I am using the corresponding x64. With version x86 I had the same error that had previously commented Technokrat and ShadowEagle.
 

Forgive mistakes, English is not my language.
Thank You.

Edited by dangelx
Link to comment
Share on other sites

 

[Español:Spanish]

Hola,

Ha sido muy duro llegar a que funcione este script, pero aqui teneis una prueba del resultado.

 

[Ingles:English]

Hi,

It has been very hard to get to run this script, but here you have a test of result.

 

[Code:Codigo]

 

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <GDIPlus.au3>
#include <Misc.au3>

Global $sIM_Path = "G:\Juegos\FindImagen\ImageMagick"
Global $sEjecutable = "compare.exe"
Global $sCaptura = "capture.png"
Global $sDiferencia = "difference.txt"

Global $hImage, $Bmp
Global $sFile, $sTitle, $nHwnd, $nPosX, $nPosY, $nPosW, $nPosH
Global $sLstatus = "Inicializando"
Global $sDstatus = "@DAX"
Global $GUI

; Windows 8.1 x64
If Not IsAdmin() Then
    MsgBox($MB_SYSTEMMODAL, "ERROR", "Son necesarios privilegios administrativos para la ejecución de la aplicación." & @LF & _
    "Administrative privileges are required for running the application.")
    Exit
Endif

If _Check_Path(@ScriptDir) = 0 Then
    MsgBox($MB_SYSTEMMODAL, "ERROR", "La aplicación no admite su ejecución en una ruta que incluyan espacios." & @LF & _
    "The application does not support execution on a route that includes spaces.")
    Exit
EndIf

; Initialize GDI+ library
_GDIPlus_Startup()

#Region
$GUI = GUICreate("Find Image", 653, 501, 267, 126)
$idMenu1 = GUICtrlCreateMenu("&Parameters")
$idSubMenu1 = GUICtrlCreateMenuItem("&Image", $idMenu1)
$idSubMenu2 = GUICtrlCreateMenuItem("&Search", $idMenu1)
GUICtrlSetState(-1, $GUI_DISABLE)
$idSubMenu3 = GUICtrlCreateMenuItem("&Exit", $idMenu1)
GUISetBkColor(0xF4F7FC)

$Label1 = GUICtrlCreateLabel("Fichero Imagen: ", 8, 36, 112, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$Pic1 = GUICtrlCreatePic("", 8, 64, 537, 313, BitOR($GUI_SS_DEFAULT_PIC, $WS_BORDER))
$Label3 = GUICtrlCreateLabel("X:", 424, 396, 17, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$Label4 = GUICtrlCreateLabel("Y:", 488, 396, 16, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$Label5 = GUICtrlCreateLabel("W:", 424, 427, 21, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$Label6 = GUICtrlCreateLabel("H:", 488, 427, 17, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$Label11 = GUICtrlCreateLabel("Search: ", 8, 396, 57, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$Label13 = GUICtrlCreateLabel("Handle:", 8, 427, 53, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")

$idStatus = _GUICtrlStatusBar_Create($GUI)

Dim $idStatus_PartsWidth[2] = [500, -1]
_GUICtrlStatusBar_SetParts($idStatus, $idStatus_PartsWidth)
_GUICtrlStatusBar_SetText($idStatus, $sLstatus, 0)
_GUICtrlStatusBar_SetText($idStatus, $sDstatus, 1)
_GUICtrlStatusBar_SetMinHeight($idStatus, 25)

$GUIsFile = GUICtrlCreateInput("", 120, 32, 425, 24)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
$GUIsTitle = GUICtrlCreateInput("", 72, 392, 337, 24)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
$GUInHwnd = GUICtrlCreateInput("", 72, 423, 121, 24)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
$GUInPosX = GUICtrlCreateInput("0", 448, 392, 33, 24)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
$GUInPosY = GUICtrlCreateInput("0", 505, 392, 33, 24)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
$GUInPosW = GUICtrlCreateInput("0", 446, 423, 33, 24)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
$GUInPosH = GUICtrlCreateInput("0", 503, 423, 33, 24)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")

GUISetState(@SW_SHOW)
#EndRegion

$sLstatus = "Selected image to find"
_GUICtrlStatusBar_SetText($IdStatus, $sLstatus , 0)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $idSubMenu1
            $sFile = FileOpenDialog("Open Image", @DesktopCommonDir & "\", "Image files (*.png)", 1)
            If @error Then
                MsgBox($MB_SYSTEMMODAL, "Error", "El fichero no ha podido ser cargado." & @LF & _
                "The file could not be loaded.")
            Else
                If _Check_Path($sFile) Then
                    _LoadPicture($sFile)
                    GUICtrlSetData($GUIsFile, $sFile)
                    GUICtrlSetData($GUInPosW, $nPosW)
                    GUICtrlSetData($GUInPosH, $nPosH)
                    GUICtrlSetState($idSubMenu2, $GUI_ENABLE)
                    $sLstatus = "Selected window into searchs"
                    _GUICtrlStatusBar_SetText($IdStatus, $sLstatus , 0)
                Else
                    MsgBox($MB_SYSTEMMODAL, "ERROR", "La aplicación no admite nombres de ficheros o rutas que incluyan espacios." & @LF & _
                    "The application does not support filenames or paths that include spaces.")
                EndIf
            EndIf
        Case $idSubMenu2
            _Get_Pantalla()
            GUICtrlSetData($GUIsTitle, $sTitle)
            GUICtrlSetData($GUInHwnd, $nHwnd)
            $sLstatus = "Processing. Searching image"
            _GUICtrlStatusBar_SetText($IdStatus, $sLstatus , 0)
            If Not _Get_Diferencia() Then
                MsgBox($MB_SYSTEMMODAL, "Error", "Error cálculando las diferencias." & @LF & _
                "Error calculating the differences")
                ExitLoop
            EndIf
            GUICtrlSetData($GUInPosX, $nPosX)
            GUICtrlSetData($GUInPosY, $nPosY)
            $sLstatus = "Finish"
            _GUICtrlStatusBar_SetText($IdStatus, $sLstatus , 0)
        Case $idSubMenu3, $GUI_EVENT_CLOSE
            $sLstatus = "Close application"
            _GUICtrlStatusBar_SetText($IdStatus, $sLstatus , 0)
            If $hImage <> 0 Then _GDIPlus_BitmapDispose($Bmp)
            _GDIPlus_Shutdown()
            ExitLoop
    EndSwitch
WEnd

GUIDelete()
Exit

Func _LoadPicture($sFile)
    Local $IMAGE_BITMAP = 0
    Local $STM_SETIMAGE = 0x0172

    ; Load image
    $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    $Bmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

    ; Refresh screen GUI
    $nPosW = _GDIPlus_ImageGetWidth($hImage)
    $nPosH = _GDIPlus_ImageGetHeight($hImage)

    _WinAPI_DeleteObject(GUICtrlSendMsg($Pic1, $STM_SETIMAGE, $IMAGE_BITMAP, $Bmp))
    _WinAPI_DeleteObject($Bmp)
EndFunc   ;==>_LoadPicture

Func _Get_Pantalla()
    MsgBox($MB_SYSTEMMODAL, "Message", "Seleccionar con el ratón la ventana en la que buscar la imagen." & @LF & _
    "Select with the mouse the window in which a picture.")
    Local $hDLL = DllOpen("user32.dll")
    While 1
        If _IsPressed("01", $hDLL) Then
            _Get_Raton()
            Sleep(100)
            ExitLoop
        ElseIf _IsPressed("1B", $hDLL) Then
            ExitLoop
        EndIf
    WEnd
    DllClose($hDLL)
    WinActivate($GUI)
EndFunc   ;==>_Get_Pantalla

Func _Get_Raton()
    $a_mpos = MouseGetPos()
    $avWin = DllCall("user32.dll", "hwnd", "WindowFromPoint", "int", $a_mpos[0], "int", $a_mpos[1])
    $nHwnd = $avWin[0]
    $sTitle = WinGetTitle($nHwnd)
EndFunc   ;==>_Get_Raton

Func _Get_Diferencia()
    Local $nRes = 0
    If FileExists($sDiferencia) Then FileDelete($sDiferencia)
    If Not FileExists($sIM_Path & "\" & $sEjecutable) Then
        MsgBox($MB_SYSTEMMODAL, "ERROR", "No se ha podido acceder al programa Compare.exe de la aplicación IMAGEMAGIC." & @LF & _
        "It has not been able to access the application Compare.exe of IMAGEMAGIC program.")
    Else
        If _CaptureScreen($sCaptura) Then
            _Get_Difference()
            If FileExists($sDiferencia) Then
                Local $aCoordenadas = _Get_Coordenadas()
                If $aCoordenadas[0] = 1 Then
                    $nPosX = $aCoordenadas[1]
                    $nPosY = $aCoordenadas[2]
                    $nRes = 1
                EndIf
            Else
                MsgBox($MB_SYSTEMMODAL, "ERROR", "No se ha podido generar un fichero de diferencias." & @LF & _
                "Unable to generate a differences file.")
            EndIf
        EndIf
    EndIf
    If FileExists($sCaptura) Then FileDelete($sCaptura)
    If FileExists($sDiferencia) Then FileDelete($sDiferencia)
    Return $nRes
EndFunc   ;==>_Get_Diferencia

Func _CaptureScreen($sCaptura)
    If FileExists(@ScriptDir & '\' & $sCaptura) Then FileDelete(@ScriptDir & '\' & $sCaptura)
    Local $aWin = WinGetPos($nHwnd)
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "ERROR", "No ha podido establecerse el area de busqueda en la ventana." & @LF & _
        "It has not been able to establish the search area in the window.")
        Return 0
    EndIf
    $WinPic = _ScreenCapture_CaptureWnd("", $nHwnd, $aWin[0], $aWin[1], ($aWin[2] + $aWin[0]), ($aWin[3] + $aWin[2]), False)
    _ScreenCapture_SaveImage(@ScriptDir & '\' & $sCaptura, $WinPic)
    WinActivate($GUI)
    Return 1
EndFunc   ;==>_CaptureScreen

Func _Check_Path($sRuta)
    Local $nRes = 0
    If StringInStr($sRuta, " ") = 0 Then
        $nRes = 1
    EndIf
    Return $nRes
EndFunc   ;==>_Check_Path

Func _Get_Coordenadas()
    Local $aRes = [0, 0, 0]
    If FileExists($sDiferencia) Then
        Local $hFile = FileOpen($sDiferencia, $FO_READ)
        If $hFile <> -1 Then
            Local $sValor = FileReadLine($hFile, 1)
            Local $aPartes = StringSplit($sValor, " ")
            If $aPartes[0] = 3 Then
                Local $aPosicion = StringSplit($aPartes[3], ",")
                If $aPosicion[0] = 2 Then
                    ; Posición 0 del array es si ha sido correcto
                    $aRes[0] = 1
                    $aRes[1] = $aPosicion[1]
                    $aRes[2] = $aPosicion[2]
                EndIf
            EndIf
        EndIf
    EndIf
    Return $aRes
EndFunc   ;==>_Get_Difference

Func _Get_Difference()
    Run("cmd.exe")
    Local $hWinCmd = WinWait("[CLASS:ConsoleWindowClass]","",50)
    SendKeepActive($hWinCmd)
    Send("cd " & $sIM_Path & "{Enter}")
    Send(StringLeft($sIM_Path, 2) & "{Enter}")
    Send($sEjecutable & " -subimage-search -metric AE -similarity-threshold 1.0 " & " " & @ScriptDir & "\" & $sCaptura & " " & $sFile & " null:  2>" & @ScriptDir & "\" & $sDiferencia)
    Send("{Enter}")
    Send("Exit{Enter}")
    While (WinExists($hWinCmd) <> 0)
        Sleep(200)
    WEnd
    SendKeepActive("")
EndFunc   ;==>_Get_Coordenadas

 

 

[Español:Spanish]

Existe un problema con la ejecucion de CMD.EXE cuando se realiza con la instrucción RunWait y ShellExecuteWait, pero actualmente no voy a tratar de resolverlo.:sweating:
Estoy algo cansado de tratar de que funcionen correctamente las llamadas al shell requeridas por ImageMagick y estoy pensando en tratar de crear la librería en .Net para evitarme problemas y quebraderos de cabeza.:angry:
Si conoceis alguna solucion a este problema, os agradecería que la comentaseis para poder aplicarla al script actual.

Saludos

[Ingles:English]

There is a problem with the execution of CMD.EXE when done with the command: RunWait or ShellExecuteWait, but currently will not try to solve it..:sweating:
I'm a little tired of trying to work correctly calls to the shell required by ImageMagick and I'm thinking about trying to create the library in .Net, I think I would avoid problems and headaches.:angry:
If anyone knows a solution to this problem, I appreciate the comment to apply to the current script.


Bye

And again: Forgive my incorrect syntax. The English is not my language.

 

 

Error.png

SciTe.png

Edited by dangelx
Link to comment
Share on other sites

  • Developers

So, let's start with you posting all the text (not image) of the output made when you do a compile, so I can see what your setup is.
I am also not so sure what problem you have as there are many word but not much information, and pretty confusing for me at the moment. :)

Jos
 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi Jos,

The image of this post is an error that occurs with the execution of the library that I downloaded from this post (ImageSearch.dll).. It has nothing to do with Scite or Debugger, both applications run me great once I solved the problem I had during installation with the SciTE environment variable (thank you very much for them).

I have not published the entire text of the script because this script is supplied with the library, but also post it again (sorry, I'm newbie :>). I should have said it was the script of example.

When I run the example commands with the library, after correcting the problem ByRef indicating Fir3man in the previous post, Debugger shows me the error of the image.
As I assumed requeririais more information on my computer, I indicated in my post the versions that I have installed both AutoIt and Scite as well as the library ImageSearch.

Sorry if I said incorrectly, I try to give more details.

Thank You
:)

Link to comment
Share on other sites

  • Developers

My question was related to you stating you were using

I also tried "#AutoIt3Wrapper_UseX64=Y", but no success.


So yes, there is a reason for me asking the question, but your choice to answer it or not. ;)

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

hi,
I'm sorry, I do not question your reasons for asking. It was just that I did not understand the reason for the question.

I tried various examples of the same script, and try to explain the changes made and the results I have obtained.

My PC is Windows 8.1 x64, AutoIt x86 (for compatibility) and SciTE4AutoIt3 (25-7-2015). I've two monitors.

The example script:

#AutoIt3Wrapper_UseX64=Y        ; i don't know if this is correct here
#include <ImageSearch.au3>

HotKeySet("p", "checkForImage")

Global $y = 0, $x = 0

Func checkForImage()
    Local $search = _ImageSearch('checkImage.bmp', 0, $x, $y, 0)
    If $search = 1 Then
        MouseMove($x, $y, 10)
    EndIf
EndFunc   ;==>checkForImage

While 1
    Sleep(200)
WEnd

I've corrected the problem ByRef indicating Fir3man in ImageSearch.au3.

Area of searching: My Windows Desktop

For x86 First execution with SciTe:

SciTe.thumb.png.eb2ae00aa1af5a6dfe194af4

Error : I do not see that the script does nothing. Only blocks the use of the letter "p" and appears on the icons of execution as show in the picture: I have restart with Ctrl+Alt+Break but hotkey don't work.

For x86 Second execution with Run AutoIt x86:

Error : (no Administrator) I do not see that the script does nothing, but not in the icons of execution.

(Administrator) same result as above

For x86 Thrid execution with Debugger:

Error : (Administrator and no Administrator)

Error.thumb.png.a0e1e167f9e78bf30f7b3776

Well, It is 1 am and I work early morning, so I leave here today and tomorrow by continuing with the rest.

Bye

Pd: I've corrected the language in the previous post. Sorry, I don't realize I wrote everything in Spanish.

 

Edited by dangelx
Link to comment
Share on other sites

  • Developers

@dangelx, Seeing your Scriptname I think you really need to read our forum rules especially about Game automation.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 2 weeks later...

I just got it to work!

I was having much trouble, reading all the threads and posts related to ImageSearch, and I'd like to help others now.

Now got it to work as a x64 and also as a x32 script using both DLLs accordingly (on a Windows 8.1 x64 PC)

One of the steps I took in debugging was putting this into (the top of) my script:

$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.
ConsoleWrite("$sOSArch=" & $sOSArch & @CR)
$sAutoItX64 = @AutoItX64 ;Check if using x64 AutoIt ;@AutoItX64 Returns 1 if the script is running under the native x64 version of AutoIt.
ConsoleWrite("$sAutoItX64=" & $sAutoItX64 & @CR)

In any case you want to be consistent about 32bit or 64bit usage, and use the right DLL etc.

What also really helped was putting in lots of debugging and error handling to zoom in on whatever specific part isn't working and why.

Credits to Centrally (very helpful usage explanation and re-uploading the files) and kangkeng for making this possible in AutoIt, as well Miguel7 from the AutoHotKey forum who also posted some helpful advice.

I've attached a zipped folder containing all of the needed Dlls and my customised Library, which also contains an example and some debugging: ImageSearch2015.zip

55c5a345e8d04.png

Take a look inside ImageSearch2015.au3 here if you like:

#AutoIt3Wrapper_UseX64=y ; Set to Y or N depending on your situation/preference!!
#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

#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

Local $h_ImageSearchDLL = -1; Will become Handle returned by DllOpen() that will be referenced in the _ImageSearchRegion() function

#Region TESTING/Example
Local $bTesting = True; 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 ImageSearch UDF;slightly modified
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with Image Search
;                 Require that the ImageSearchDLL.dll be loadable
;
; ------------------------------------------------------------------------------
;===============================================================================
;
; Description:      Find the position of an image on the desktop
; Syntax:           _ImageSearchArea, _ImageSearch
; Parameter(s):
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;                   $transparency - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
;                                  the color to be used as transparency; can be omitted if
;                                  not needed
;
; Return Value(s):  On Success - Returns True
;                   On Failure - Returns False
;
; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
;       a desktop region to search
;
;===============================================================================
Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
    Return _ImageSearchArea($findImage, $resultPosition, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $tolerance, $transparency)
EndFunc   ;==>_ImageSearch

Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance = 0, $transparency = 0);Credits to Sven for the Transparency addition
    If Not FileExists($findImage) Then Return "Image File not found"
    If $tolerance < 0 Or $tolerance > 255 Then $tolerance = 0
    If $h_ImageSearchDLL = -1 Then _ImageSearchStartup()

    If $transparency <> 0 Then $findImage = "*" & $transparency & " " & $findImage
    If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage
    $result = DllCall($h_ImageSearchDLL, "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage)
    If @error Then Return "DllCall Error=" & @error
    If $result = "0" Or Not IsArray($result) Or $result[0] = "0" Then Return False

    $array = StringSplit($result[0], "|")
    If (UBound($array) >= 4) Then
        $x = Int(Number($array[2])); Get the x,y location of the match
        $y = Int(Number($array[3]))
        If $resultPosition = 1 Then
            $x = $x + Int(Number($array[4]) / 2); Account for the size of the image to compute the centre of search
            $y = $y + Int(Number($array[5]) / 2)
        EndIf
        Return True
    EndIf
EndFunc   ;==>_ImageSearchArea

;===============================================================================
;
; Description:      Wait for a specified number of seconds for an image to appear
;
; Syntax:           _WaitForImageSearch, _WaitForImagesSearch
; Parameter(s):
;                   $waitSecs  - seconds to try and find the image
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;                   $transparency - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
;                                  the color to be used as transparency can be omitted if
;                                  not needed
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImageSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
    $waitSecs = $waitSecs * 1000
    $startTime = TimerInit()
    While TimerDiff($startTime) < $waitSecs
        Sleep(100)
        If _ImageSearch($findImage, $resultPosition, $x, $y, $tolerance, $transparency) Then
            Return True
        EndIf
    WEnd
    Return False
EndFunc   ;==>_WaitForImageSearch

;===============================================================================
;
; Description:      Wait for a specified number of seconds for any of a set of
;                   images to appear
;
; Syntax:           _WaitForImagesSearch
; Parameter(s):
;                   $waitSecs  - seconds to try and find the image
;                   $findImage - the ARRAY of images to locate on the desktop
;                              - ARRAY[0] is set to the number of images to loop through
;                                ARRAY[1] is the first image
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;                   $transparent - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
;                                  the color to be used as transparent; can be omitted if
;                                  not needed
;
; Return Value(s):  On Success - Returns the index of the successful find
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImagesSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
    $waitSecs = $waitSecs * 1000
    $startTime = TimerInit()
    While TimerDiff($startTime) < $waitSecs
        For $i = 1 To $findImage[0]
            Sleep(100)
            If _ImageSearch($findImage[$i], $resultPosition, $x, $y, $tolerance, $transparency) Then
                Return $i
            EndIf
        Next
    WEnd
    Return False
EndFunc   ;==>_WaitForImagesSearch
#EndRegion ImageSearch UDF;slightly modified

#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

If it's all in the same folder and you set #AutoIt3Wrapper_UseX64= appropriately the example should work for you!

Edit: also uploaded "ImageSearch15.au3", a version of "my" ImageSearch Library without the built-in Example and Debugging
(will require the Dlls in the .zip file though): ImageSearch15.au3

#AutoIt3Wrapper_UseX64=n ; Set to Y or N depending on your situation/preference!!
#include-once
#include <WinAPIFiles.au3> ; for _WinAPI_Wow64EnableWow64FsRedirection

#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

Local $h_ImageSearchDLL = -1; Will become Handle returned by DllOpen() that will be referenced in the _ImageSearchRegion() function

#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
        $h_ImageSearchDLL = DllOpen("ImageSearchDLLx32.dll")
        If $h_ImageSearchDLL = -1 Then Return "DllOpen failure"
    ElseIf $sOSArch = "X64" And $sAutoItX64 = 1 Then
        $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)
    Return True
EndFunc   ;==>_ImageSearchShutdown
#EndRegion ImageSearch Startup/Shutdown

#Region ImageSearch UDF;slightly modified
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with Image Search
;                 Require that the ImageSearchDLL.dll be loadable
;
; ------------------------------------------------------------------------------
;===============================================================================
;
; Description:      Find the position of an image on the desktop
; Syntax:           _ImageSearchArea, _ImageSearch
; Parameter(s):
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;                   $transparency - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
;                                  the color to be used as transparency; can be omitted if
;                                  not needed
;
; Return Value(s):  On Success - Returns True
;                   On Failure - Returns False
;
; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
;       a desktop region to search
;
;===============================================================================
Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
    Return _ImageSearchArea($findImage, $resultPosition, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $tolerance, $transparency)
EndFunc   ;==>_ImageSearch

Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance = 0, $transparency = 0);Credits to Sven for the Transparency addition
    If Not FileExists($findImage) Then Return "Image File not found"
    If $tolerance < 0 Or $tolerance > 255 Then $tolerance = 0
    If $h_ImageSearchDLL = -1 Then _ImageSearchStartup()

    If $transparency <> 0 Then $findImage = "*" & $transparency & " " & $findImage
    If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage
    $result = DllCall($h_ImageSearchDLL, "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage)
    If @error Then Return "DllCall Error=" & @error
    If $result = "0" Or Not IsArray($result) Or $result[0] = "0" Then Return False

    $array = StringSplit($result[0], "|")
    If (UBound($array) >= 4) Then
        $x = Int(Number($array[2])); Get the x,y location of the match
        $y = Int(Number($array[3]))
        If $resultPosition = 1 Then
            $x = $x + Int(Number($array[4]) / 2); Account for the size of the image to compute the centre of search
            $y = $y + Int(Number($array[5]) / 2)
        EndIf
        Return True
    EndIf
EndFunc   ;==>_ImageSearchArea

;===============================================================================
;
; Description:      Wait for a specified number of seconds for an image to appear
;
; Syntax:           _WaitForImageSearch, _WaitForImagesSearch
; Parameter(s):
;                   $waitSecs  - seconds to try and find the image
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;                   $transparency - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
;                                  the color to be used as transparency can be omitted if
;                                  not needed
;
; Return Value(s):  On Success - Returns 1
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImageSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
    $waitSecs = $waitSecs * 1000
    $startTime = TimerInit()
    While TimerDiff($startTime) < $waitSecs
        Sleep(100)
        If _ImageSearch($findImage, $resultPosition, $x, $y, $tolerance, $transparency) Then
            Return True
        EndIf
    WEnd
    Return False
EndFunc   ;==>_WaitForImageSearch

;===============================================================================
;
; Description:      Wait for a specified number of seconds for any of a set of
;                   images to appear
;
; Syntax:           _WaitForImagesSearch
; Parameter(s):
;                   $waitSecs  - seconds to try and find the image
;                   $findImage - the ARRAY of images to locate on the desktop
;                              - ARRAY[0] is set to the number of images to loop through
;                                ARRAY[1] is the first image
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                                image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;                   $transparent - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
;                                  the color to be used as transparent; can be omitted if
;                                  not needed
;
; Return Value(s):  On Success - Returns the index of the successful find
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImagesSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
    $waitSecs = $waitSecs * 1000
    $startTime = TimerInit()
    While TimerDiff($startTime) < $waitSecs
        For $i = 1 To $findImage[0]
            Sleep(100)
            If _ImageSearch($findImage[$i], $resultPosition, $x, $y, $tolerance, $transparency) Then
                Return $i
            EndIf
        Next
    WEnd
    Return False
EndFunc   ;==>_WaitForImagesSearch
#EndRegion ImageSearch UDF;slightly modified

I hope this helps somebody! Let me know any feedback/issues.

Edited by guestscripter
credits
Link to comment
Share on other sites

Alright so i have finally got his working but i have a question how do i make this  code loop/repeat and keep searching for the picture?

am still working on the code but i can't seem to understand how i make the script loop/repeat plz help

 

#include <ImageSearch.au3>

HotKeySet("s", "checkForImage")
HotKeySet("c", "close")

global $y = 0, $x = 0

Func checkForImage()
Local $search = _ImageSearch('fish.bmp', 0, $x, $y, 0)
If $search = 1 Then
MouseMove($x, $y, 10)
EndIf
EndFunc

Func close()
   Exit
EndFunc

while 1
sleep(200)
WEnd

 

Link to comment
Share on other sites

Alright so i have finally got his working but i have a question how do i make this  code loop/repeat and keep searching for the picture?

am still working on the code but i can't seem to understand how i make the script loop/repeat plz help

Depends what you intend to achieve. 

Maybe something in this direction?

#include <ImageSearch.au3>

HotKeySet("s", "StartFishing")
HotKeySet("c", "close")

Global $y = 0, $x = 0

While 1
    Sleep(200)
WEnd

Func StartFishing();Keep checking for the fish until we find it, give up after 5 seconds if not yet found
    Local $timer = TimerInit()
    While Not checkForTheFish() And TimerDiff($timer) < (5 * 1000)
        Sleep(100)
    WEnd
EndFunc   ;==>StartFishing

Func checkForTheFish()
    Local $search = _ImageSearch('fish.bmp', 0, $x, $y, 0)
    If $search = 1 Then
        MouseMove($x, $y, 10)
        Return True;Found the fish!
    Else
        Return False;Didn't find the fish yet...
    EndIf
EndFunc   ;==>checkForTheFish

Func close()
    Exit
EndFunc   ;==>close

 

Link to comment
Share on other sites

Depends what you intend to achieve. 

Maybe something in this direction?

#include <ImageSearch.au3>

HotKeySet("s", "StartFishing")
HotKeySet("c", "close")

Global $y = 0, $x = 0

While 1
    Sleep(200)
WEnd

Func StartFishing();Keep checking for the fish until we find it, give up after 5 seconds if not yet found
    Local $timer = TimerInit()
    While Not checkForTheFish() And TimerDiff($timer) < (5 * 1000)
        Sleep(100)
    WEnd
EndFunc   ;==>StartFishing

Func checkForTheFish()
    Local $search = _ImageSearch('fish.bmp', 0, $x, $y, 0)
    If $search = 1 Then
        MouseMove($x, $y, 10)
        Return True;Found the fish!
    Else
        Return False;Didn't find the fish yet...
    EndIf
EndFunc   ;==>checkForTheFish

Func close()
    Exit
EndFunc   ;==>close

Yeah something like this and if i understand right this will stop looking for the fish/image if it dosent find it in 5 sec? tho i never want it to stop till i tell it to stop

 

Edited by Gwaren
Link to comment
Share on other sites

i never want it to stop till i tell it to stop

Func StartFishing();Keep checking for the fish until we find it, never give up
   Do
        Sleep(100)
   Until checkForTheFish() = True
EndFunc   ;==>StartFishing

Seems you need to catch up on some basics. Start with some really simple scripts and examples from the helpfile like everybody did.

Most days most people on the forums won't help you very much if you seem like you haven't properly tried doing your homework.

Good luck!

(oh, and take a look at my ImageSearch15.au3 version of the UDF that I uploaded one post before yours, I added _ImageSearchStartup() and _ImageSearchShutdown() functions, so that the Dll is opened once and not every time, which can make a script much faster. And I "fixed" some things I thought would make it more stable and reliable)

Link to comment
Share on other sites

Func StartFishing();Keep checking for the fish until we find it, never give up
   Do
        Sleep(100)
   Until checkForTheFish() = True
EndFunc   ;==>StartFishing

Seems you need to catch up on some basics. Start with some really simple scripts and examples from the helpfile like everybody did.

Most days most people on the forums won't help you very much if you seem like you haven't properly tried doing your homework.

Good luck!

(oh, and take a look at my ImageSearch15.au3 version of the UDF that I uploaded one post before yours, I added _ImageSearchStartup() and _ImageSearchShutdown() functions, so that the Dll is opened once and not every time, which can make a script much faster. And I "fixed" some things I thought would make it more stable and reliable)

Alright thanks for helping me out much appreciated yeah im going to start to read the help files and get used to this program more and more just that i had worked on this then i put it all down and wanted help quick and there you where, so thanks alot for the help :)

 

And ill look at the imagesearch you have posted in here

Edited by Gwaren
Link to comment
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
 Share

×
×
  • Create New...