Jump to content

1 Screenshot

About This File

Use MouseClick()  need:

#RequireAdmin

 

Dll is already integrated in UDF !

; #INDEX# ===============================================================
; Title .........: ImageSearch
; AutoIt Version : 3.x
; Language ......: English
; Description ...: Check image Appears or Not and Return the position of an image on the desktop
; Author(s) .....: Dao Van Trong - TRONG.LIVE
; =======================================================================

; #CURRENT# =============================================================
; _ImageSearch
; _ImageSearch_Area
; _ImageSearch_Wait
; _ImageSearch_WaitArea
; ========================================================================

;=========================================================================
;
; Author:...........: AutoIT VietNam : Dao Van Trong - TRONG.LIVE
; Description:......: Check image Appears or Not
;                     Find and return the position of an image on the desktop
; Syntax:........... _ImageSearch_Area, _ImageSearch
; Parameter(s):..... $_ImagePath:       The image to locate on the desktop
;                                       May be a list of image by delimited by "|"
;                                       i.e: $_ImagePath = "image1.bmp|image2.bmp|image3.bmp"
; $P_x1 $P_y1:                      Position of 1st point
; $P_x2 $P_y2:                      Position of 2nd point - Default is last botton right of desktop
; $_Tolerance:                      0 for no tolerance (0-255). Needed when colors of image differ from desktop. e.g GIF
;                   $_CenterPos:                        boolen. True will return $array[1] x $array[2] is center of image found.
;                                                           False will return top-left position
; Return Value(s):.. Return an array has 3 item
;                    On Success:                    $array[0] 1
; On Failure:                   $array[0] 0
;                    DLL not found or other error:  $array[0] -1
;                    $array[1] x $array[2]:             position of image what found on desktop
;
; Note:............. Use _ImageSearch to search the entire desktop
;                    _ImageSearch_Area to specify a desktop region to search
;                    $_ImagePath with more item need more time appear on screen before function can detect.
;                    Decrease sleep time in the loop to detect faster. But less performance. I.e CPULoad increased
;
;========================================================================

EG 1:

;~ Opt("MustDeclareVars", 1)
;~ #AutoIt3Wrapper_UseX64=y
;~ #AutoIt3Wrapper_Change2CUI=y
#RequireAdmin

#include "_ImageSearch_UDF.au3"

HotKeySet("{Esc}", "_Exit") ; Press ESC for exit
Func _Exit()
    Exit 0
EndFunc   ;==>_Exit

Global Const $Ask_On_Found = 0
Global Const $Mouse_Move_On_Found = 1
Global Const $Mouse_Click_On_Found = 0

Global Const $iSleep_Time=500

Global $sCount = 0, $_Image_1 = @ScriptDir & "\example.bmp"

; First, use this function to create a file bmp, maybe a desktop icon for example')
MsgBox(64 + 262144, 'ImageSearch', 'At first, create a file bmp,' & @CRLF & 'photos that will search on the screen!')
_ImageSearch_Create_BMP($_Image_1)

ConsoleWrite("! Search for images: " & $_Image_1 & @CRLF & '! Searching on the screen ...' & @CRLF)

While 1
    ToolTip('(Press ESC for EXIT) Searching ...', 1, 1)
    Sleep($iSleep_Time)
    $sCount += 1
    Local $return = _ImageSearch($_Image_1)
    If $return[0] = 1 Then
        ConsoleWrite('- [' & $sCount & '] Image found:' & " X=" & $return[1] & " Y=" & $return[2] & @CRLF)
        If $Mouse_Move_On_Found Then
            MouseMove($return[1], $return[2])
            Sleep($iSleep_Time)
        EndIf
        If $Mouse_Click_On_Found Then MouseClick("left", $return[1], $return[2])
        ToolTip('(Press ESC for EXIT) - [' & $sCount & "] Image found:" &  " X=" & $return[1] & " Y=" & $return[2], 1, 1)
        If $Ask_On_Found Then
            Local $ask = MsgBox(6 + 262144, 'Success [' & $sCount & ']', 'Image found:' & " X=" & $return[1] & " Y=" & $return[2])
            If $ask = 2 Or $ask = 3 Or $ask = 5 Or $ask = 7 Then Exit ;No, Abort, Cancel, and Ignore
            If $ask = 10 Then _ImageSearch_Create_BMP($_Image_1) ; Continue       ;Try Again
        EndIf
    EndIf
    Sleep(200)
WEnd

 

Video demo:

 

 

[+] When any problem or error occurs, please make sure that:
- Downloaded and used the latest version.
- Set screen Screen Scale and layout = 100%
- Installed display driver.
- Tried turning off the antivirus
- Full installation: Microsoft Visual C++ Redistributable  2005->2022

[+] You can download the AIO version of the Visual C++ Redistributable here: 

-> https://www.mediafire.com/file/0ak8dcj9mdn7nyq/VisualCppRedist_AIO_2005-2022_x86_x64_%5Btrong.live%5D.zip/file

-> FOR Windows XP: https://www.mediafire.com/file/5m5lnr1kfg73tc9/VisualCppRedist_AIO_2005-2019_x86_XP_%5Btrong.live%5D.zip/file

<!> Password for Extract: trong.live

 

[+] The last full version of SCITE4AutoIT supports windows XP:

https://www.autoitscript.com/autoit3/scite/download/archive/v19.1127.1402.0-SciTE4AutoIt3.exe

 

Edited by VIP
link Visual C++ Redistributable


What's New in Version 2021.8.30.2

Released

Fixed variable error.


User Feedback

Recommended Comments

Works nicely. Never got it to work in vmware for some reason. Wrote my script on my own machine which worked fine. As soon as I try it on vmware workstation 15, I just get "! Dll not found or Call Dll error !".

I've verified the location of the dll. Also tried compiling as a x86 exe to try that dll. Strange. Guess it checks video memory or something which differs from a physical computer.

Adding a consolewrite on @error after the dllcall just gives me code 1, which according to dllcall help is

  1 = unable to use the DLL file,
Edited by Turranius
Link to comment
Share on other sites

On 1/30/2020 at 1:29 AM, Turranius said:

Works nicely. Never got it to work in vmware for some reason. Wrote my script on my own machine which worked fine. As soon as I try it on vmware workstation 15, I just get "! Dll not found or Call Dll error !".

I've verified the location of the dll. Also tried compiling as a x86 exe to try that dll. Strange. Guess it checks video memory or something which differs from a physical computer.

Adding a consolewrite on @error after the dllcall just gives me code 1, which according to dllcall help is

  1 = unable to use the DLL file,

- The problem has been corrected!

Link to comment
Share on other sites

Same issue with error but only on a fresh Win10 machine.

! Dll not found or Call Dll error !

The script works just fine on an existing Win10 computer but if you run this on a fresh installed Win10 machine 32 or 64bit this is the error you get.  Same script, same files, same locations.  There is clearly some kind of pre-requisite to use the DLL Call.  If there is any debug method I can provide this information.

Edited by vulcan4d
Link to comment
Share on other sites

Same issue with vulcan4d

Tried these things below

  • Make sure you use my UDF and dll. => Using version updated January 31, 2020
  • Have you tried disabling your antivirus before running? => Yes
  • Did you test the example script? => Testing "_ImageSearch_Sample.au3"
  • Have you set Screen Scale and layout = 100%? => Yes, scale 100% at 1920*1080
  • Have you installed the display driver? => Yes, using latest driver for rx570

 

Image capture and save successfully then failed at function  DllCall(), result return = 0

Below is console log

>"D:\auto\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "D:\auto\AutoIT_ImageSearch\_ImageSearch_Sample.au3"    
--\\ ImageSearch by TRONG.LIVE //--  OSArch : X64 // AutoIT ver: 3.3.14.5 x86
-- WorkingDir      : D:\auto\AutoIT_ImageSearch
-- ScriptFullPath  : D:\auto\AutoIT_ImageSearch\_ImageSearch_Sample.au3
-- ImageSearchDLL  : D:\auto\AutoIT_ImageSearch\_ImageSearch_DLL\_ImageSearch.dll (17kb)
-- ScreenCapture   : X1=1042 Y1=342 X2=1095 Y2=383
! Search for images: D:\auto\AutoIT_ImageSearch\example.bmp
! Searching on the screen ...
! Dll not found or Call Dll error !
! Dll not found or Call Dll error !
! Dll not found or Call Dll error !
! Dll not found or Call Dll error !
! Dll not found or Call Dll error !
! Dll not found or Call Dll error !

>Process failed to respond; forcing abrupt termination...
>Exit code: 1    Time: 8.064

 

Please ask if you need further information.

 

========

Edit: VIP helped me figure out that VC++ is required for using ImageSearch.dll

make sure you have it or install with link below
https://www.techpowerup.com/download/visual-c-redistributable-runtime-package-all-in-one/

Edited by nklight
Link to comment
Share on other sites

when i add

#include <GuiListView.au3> 

i get error as so i have to use GuiListView.au3 but cant so have to delete from #include one of them to run script, any solve for this one? thank you.

C:\Program Files (x86)\AutoIt3\Include\SecurityConstants.au3"(63,30) : error: $TOKENPRIMARY previously declared as a 'Const'

 

Edited by tellme
Link to comment
Share on other sites

Hello, I have position (X,Y) already, I dont want to use mouse click to take ScreenCapture. How to do that ? 

 Could you give me some Example ? 

Link to comment
Share on other sites

16 hours ago, kctvt said:

Hello, I have position (X,Y) already, I dont want to use mouse click to take ScreenCapture. How to do that ? 

 Could you give me some Example ? 

Script yourself to take pictures at that coordinate with your dimensions and store them for use with Image Search UDF

Link to comment
Share on other sites

I'm testing this now in mid 2023 on Windows 11, and the script partially works. It appears as though it's finding the correct image location on screen, but what's actually happening is that the image that's being saved is offset, usually by ~100px in the y direction, and then it finds that location and re-applies the offset, so the cursor goes to the correct location but the image it's searching for is really the wrong image. This causes some other issues as you might imagine, when attempting to build programs, so I'm wondering if I'm missing some obvious fix or if anyone else has encountered this behaviour? Still, pretty amazing code, but I'd love to figure out this offset issue. Thanks!

Link to comment
Share on other sites

×
×
  • Create New...