Jump to content
Centrally

ImageSearch Usage Explanation

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?

Share this post


Link to post
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

Share this post


Link to post
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

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.
  :)

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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.
  :)

Share this post


Link to post
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
:)

Share this post


Link to post
Share on other sites

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.
  :)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

 

Share this post


Link to post
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

 

Share this post


Link to post
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

Share this post


Link to post
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)

Share this post


Link to post
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

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 zuladabef
      All my scripts were working fine and now I am getting this error.  How do I resolve it?  Which folder(s) do the DLLs need to be in?
      ! Dll not found or Call Dll error !  
    • By Synaps3
      I've recently been annoyed by how google images works. You can't click an image and see the full res image. You have to go to the website and find the image on the page and occasionally, it won't allow you to view the image easily. This script makes it easy to view any image in google images in full resolution immediately. You just press Ctrl + Q while hovering over the image you want and it'll open full res in a new tab. This is only tested in firefox, but it shouldn't be hard to modify for another browser.
      Here it is:
      #include <Misc.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <Clipboard.au3> #include <Array.au3> #include <String.au3> Local $clipB Local $urlArray Local $theLink HotKeySet("^q", "OpenImage") Func DecodeUrl($src) Local $i Local $ch Local $buff ;Init Counter $i = 1 While ($i <= StringLen($src)) $ch = StringMid($src, $i, 1) ;Correct spaces If ($ch = "+") Then $ch = " " EndIf ;Decode any hex values If ($ch = "%") Then $ch = Chr(Dec(StringMid($src, $i + 1, 2))) $i += 2 EndIf ;Build buffer $buff &= $ch ;Inc Counter $i += 1 WEnd Return $buff EndFunc ;==>DecodeUrl Func OpenImage() MouseClick($MOUSE_CLICK_RIGHT) Send("A") Sleep(100) $clipB = _ClipBoard_GetData($CF_TEXT) $theLink = DecodeUrl($clipB) $urlArray = _StringBetween($theLink, "=", "&") If StringInStr($urlArray[0], "?") <> 0 Then $urlArray = _StringBetween($theLink, "=", "?") EndIf ShellExecute($urlArray[0]) EndFunc While 1 Wend  
    • By Schuster
      Hey there,
      i need your help guys. I am working in the QA department of my company. A little part of or software produces hints (like little popups) which needs to be tested every release. I wrote scripts to trigger those hints and i also implemented the imagesearch.dll to find those hints on the screen. My goal now is it to let the machine work over night, so when i come back to work i only get a report which says 130/140 hints were found successfully. This already works, aslong as my pc is not locked, but i want/need to lock my pc because of security concerns.
      My general question. Is it possible to run my scripts on my locked PC and still find an image that i provide which will open sooner or later in the background?
       
      Thanks in advance
    • By kylejustknows
      The code is solid and simple, it can almost explain itself.
      This is the native autoit way to do the "imagesearch", no 3rd party .dll needed.
       
      It gets "your.bmp", and "screenshot.bmp" ----> Convert the  .bmp files into 2D-Arrays (Malkey's function)  ----> Compare the 2D-arrays, return the matched position.
       
      Tested on: Windows 7; Windows server 2008R2; Windows 10 1809.
       
      Pros:
      It is native. No extra .dll needed
      It is super robust. (I used to have lots of funny results using other imagesearch libs).
      It gets screenshot the same you get your screenshot crop, so it always gets a solid result, and 100% accurate.
      The code is very simple and friendly, all level users can understand and use it.
       
      Cons:
      It is slow to convert your.big.screen.bmp into a 2D-array, and may consume 200+MB of memory and may take 5 - 20 seconds to return the result. (the actual search in an array is fast, but the conversion from .bmp to array is slow. The speed depends on your CPU speed and your screen size).
      Correct: now optimized,  it's ~5 seconds and ~ 70MB ram usage.
      It is a pixel-by-pixel color-code strict comparison in the "array-in-array" search, so you have to use the 24-bit BMP file, no "Tolerance" allowed.
       
      2019-Jun-11: script update:
      Same day updated: Update example;  Optimize the algorithm for performance, now most computers can get the result in ~5 seconds, using ~70MB temporary memory, for the 1920x1080 resolution screen.
       
      2019-Jun-12 script update:
      It now uses "PrintScreen" hotkey to save the screenshot.bmp (restores the user's old clipboard content after it is done) ~This is the only way to make sure the screenshot matches exactly what the user is seeing, after doing dozens of harsh tests.
      The reason: The UDF "ScreenCapture" and "ImageSearch.dll"  are not reliable for an unknown reason. Some window/dialogue special drawings are "invisible" in their screenshots.
      But the "PrintScreen" key -> Clipboard -> screenshot.bmp, this method always catches exact things showing on the screen.
       
      #include <GDIPlus.au3> #include <ClipBoard.au3> ;Sinple Example.================== the 1.bmp is what you want to find on your screen $result = _ScreenSearchBmp("1.bmp") if $result[0] = 0 Then MsgBox(0,"","not found") Else MouseMove($result[0],$result[1],20) ;move mouse to the result EndIf ;Example End.================== You can "include" this file after you remove this "Example" part here. ;=============================================================================== ; ; Description: Main Function. Find the position of an image on the desktop ; Parameter(s): ; $center = 1 - Set where the returned x,y location of the image is. ; default 1 means center, 0 means top-left ; ; Return Value(s): On Success - Returns the array of matched position [x,y] on your screen. ; On Failure - Returns array [0,0] (BTW, there is no position 0,0 on a screen, so it means error) ; ; Note: Warning: The BMP file must be a 24-bit BMP (windows default) ; ;=============================================================================== Func _ScreenSearchBmp($file,$center=1) local $pixelarray,$screenarray ;get both your image.bmp and screenshot.bmp into pixel-by-pixel 2D arrays _FileImageToArray($file, $pixelarray) _Clip_screenshot(@TempDir & "\screenshot.bmp") _FileImageToArray(@TempDir & "\screenshot.bmp",$screenarray) FileDelete(@TempDir & "\screenshot.bmp") ;compare the 2 2D-arrays local $result = _2darray_in_2darray($screenarray,$pixelarray) ;result tidy up, for if $center=1, and for if not found. Local $aresult[2] $aresult[0] = $result[0] $aresult[1] = $result[1] if $aresult[0] = 0 then Return $aresult ;if not found , return 0 0 here if $center = 1 then $aresult[0] = $result[0]+ Round(UBound($pixelarray,1)/2) if $center = 1 then $aresult[1] = $result[1]+ Round(UBound($pixelarray,2)/2) Return $aresult ;if ALL GOOD, and $center=1 then return the center of the image here. EndFunc ;=============================================================================== ; Code by Malkey, converts .bmp into 2D array pixal by pixal. : thanks man! ;=============================================================================== Func _FileImageToArray($filename, ByRef $aArray) Local $Reslt, $stride, $format, $Scan0, $iW, $iH, $hImage Local $v_Buffer, $width, $height Local $i, $j _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($filename) $iW = _GDIPlus_ImageGetWidth($hImage) $iH = _GDIPlus_ImageGetHeight($hImage) $Reslt = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW, $iH, $GDIP_ILMREAD, $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits () $width = DllStructGetData($Reslt, "width") $height = DllStructGetData($Reslt, "height") $stride = DllStructGetData($Reslt, "stride") $format = DllStructGetData($Reslt, "format") $Scan0 = DllStructGetData($Reslt, "Scan0") Dim $aArray[$width][$height] For $i = 0 To $iW - 1 For $j = 0 To $iH - 1 $aArray[$i][$j] = DllStructGetData(DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4)), 1) Next Next _GDIPlus_BitmapUnlockBits($hImage, $Reslt) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Return EndFunc ;==>_FileImageToArray ;=============================================================================== ; ; Description: ; My code, search a 2D array inside another 2d array ; If found, return the positon of first element ; If error or not found, return array [0,0]. Because the very first match would be [1,1], "0" means something wrong. ; eg. search a 2d array ; [1,2,3,4] ; [5,6,7,8] ; [9,0,1,2] ; for: ; [7,8] ; [1,2] ; You will get result [2,3] (means, matched, first element position is row 2, colunm 3) ; ; Parameter(s): ; ; Return Value(s): On Success - Returns the array of matched [x,y], the top-left element position in the source. ; On Failure - Returns [0,0] ; ; ;=============================================================================== Func _2darray_in_2darray($source,$search) ;get the size of the both arrays local $sourcerow = UBound($source,1) Local $sourcecol = UBound($source,2) local $searchrow = UBound($search,1) Local $searchcol = UBound($search,2) ;error input cheching, if error return position 0,0 if $sourcerow = 0 or $sourcecol = 0 or $searchrow = 0 or $searchcol = 0 then Local $aPeople[2] $aPeople[0] = 0 $aPeople[1] = 0 Return $aPeople EndIf ; A crazy 4-for-loops, compare every x,y of search array in every x,y in source array for $ssr = 1 to $sourcerow - $searchrow +1 for $ssc = 1 to $sourcecol - $searchcol +1 for $sr = 1 to $searchrow for $sc = 1 to $searchcol ;if an element not match, go back, search for next if $search[$sr-1][$sc-1] <> $source[$ssr+$sr-2][$ssc+$sc-2] then ContinueLoop 3 Next Next ;if the loop passed all elements test, made it here, means the result is found! congress! lets return the result: Local $aPeople[2] $aPeople[0] = $ssr $aPeople[1] = $ssc Return $aPeople Next Next ;all the loops finished, no result found. return [0,0] Local $aPeople[2] $aPeople[0] = 0 $aPeople[1] = 0 Return $aPeople EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Clip_screenshot ; Description ...: This get a screenshot.bmp using "Print Screen" key, so the image is EXACT same image you use "Print Screen" key, to avoid funny results. ; Syntax ........: _Clip_screenshot($file) ; Parameters ....: $file - The location of the screen shot .bmp file you want it to save ; Return values .: None ; Author ........: Kyle ; =============================================================================================================================== Func _Clip_screenshot($file) local $tempdata = _ClipBoard_GetData() ;save current user's clipboard Send("{PRINTSCREEN}") sleep(200) If _ClipBoard_IsFormatAvailable($CF_BITMAP) Then _ClipBoard_Open(0) $hClipboardImage = _ClipBoard_GetDataEx($CF_BITMAP) _ClipBoard_Close() _GDIPlus_Startup() $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hClipboardImage) Local $iX = _GDIPlus_ImageGetWidth($hBitmap) Local $iY = _GDIPlus_ImageGetHeight($hBitmap) Local $hClone = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $iX, $iY, $GDIP_PXF24RGB) ;make sure its 24bit bmp _GDIPlus_ImageDispose($hBitmap) $hBitmap = $hClone $sCLSID = _GDIPlus_EncodersGetCLSID("BMP") _GDIPlus_ImageSaveToFileEx($hBitmap, $file, $sCLSID, 0) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndIf _ClipBoard_SetData($tempdata) ; restore user clipboard EndFunc Remove the "example" part then you can include this code as a file.
    • By kuhicop
      Hello, I need to find an image on screen and return it's position left, top, right, botton.
      I'm using the ImageSearch function but it only returns 1 or 0.
      Any ideas? Thanks!
×
×
  • Create New...