Jump to content

Recommended Posts

Hello. Is there a possibility to use ImageSearch many times in a row when there will be multiple founds?

Basically what I want to do is make a function which will search and click every target which is found by ImageSearch. 

Storyline:

Func search()

- search for desired image

      -  MouseMove($return[1], $return[2])
      -  MouseClick("left", 217, $return[2])

-> Make this for every found image in the screen.

EndFunc

Then

- MsgBox(48, 'Scanning', 'Screen scan done, moving to next',5)

- Move mouse cursor center of the screen

- MouseWheel($MOUSE_WHEEL_DOWN, 30)

Then loop Func search() until I exit the program. 

 

Here is the code which I have now. It will find the picture and make mouseclick where I want to. But how to continue when there are multiple objects and also mousewheel is needed?

 

#include <GuiConstants.au3>;Functions needed for most GUI Code
#include <Constants.au3>
#include "_ImageSearch_UDF.au3"
#include "_ImageSearch_Tool.au3"


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

 ;Search all objects


Local $hGUI = GuiCreate("Automatisation", 430, 400);Create GUI Window
Local $idPic = GUICtrlCreatePic("logo.bmp", 10, 15, 200, 50) ; logo
$Button_1 = GuiCtrlCreateButton("Exit", 280, 20, 130, 50);Button_1 is the Exit Button
$Button_2 = GuiCtrlCreateButton("Search", 10, 80, 300, 50); Button_2 is the Execute Script
GuiSetState()

While 1;your LOOP
    $msg = GuiGetMsg();retrieves the button or control that was pressed
    Select; starts a case statement
    Case $msg = $GUI_EVENT_CLOSE;case statement, its like an if statement but better when you have alot of statements
    ExitLoop; If the program is exited it will exit the loop.
Case $msg = $Button_1
    ExitLoop;Exits the Loop
Case $msg = $Button_2
    Haku1(); Search

 EndSelect; ends the case statements
WEnd

;-----------------------------------------------------------------------

Func Haku1();Search

Opt("WinTitleMatchMode", 2)
Local $hWnd = WinGetHandle("Auto")
ConsoleWrite ($hWnd & @CRLF)
WinActivate($hWnd)
WinWaitActive($hWnd)


    Local $_Image_1 = @ScriptDir & "\PS.bmp"

    Local $find_ListImage = $_Image_1

    Local $return = _ImageSearch($_Image_1, 200, False)
    If $return[0] = 1 Then
            ConsoleWrite('- Image found:' & " X=" & $return[1] & " Y=" & $return[2] & @CRLF)
        MouseMove($return[1], $return[2])
        MouseClick("left", 217, $return[2])

    Else
        MsgBox(48, 'Scan', 'No founds')
        Exit
     EndIf

EndFunc

 

Link to post
Share on other sites

Are you sure you need to be using ImageSearch? This would probably be a lot easier with Controls or even UI Automation

As for using _ImageSearch multiple times, I'm sure you can, but I'm unsure which ImageSearch UDF you're using. Change the parameters of the image search so you're avoiding the section of screen you've already searched. You'll need to know how your image search works (top to bottom, left to right, etc) to be able to cut out sections.

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

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.

×
×
  • Create New...