Jump to content

Do MouseClick Until see image


Recommended Posts

Hello.

I have a problem. I want to create a script that click on screen until it see image. I use image search, and create gui.

Code that i have

#include <GUIConstantsEx.au3>
#include <ImageSearch2015.au3>

$menu = "menu.PNG"
$znszanse = "znszanse.PNG"
$oreklame = "oreklame.PNG"
$back = "back.PNG"
$krec = "krec.PNG"
$liczbaklikniec = 0
$x1 = 0
$y1 = 0

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 300, 200)

    ; Create a button control.
    Local $500 = GUICtrlCreateButton("500", 120, 170, 85, 25)
    Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    Local $iPID = 0

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                ExitLoop

            Case $500
                ; Run Notepad with the window maximized.
                ConsoleWrite('klikna500')
                While 1
                    botzyc()
                    Sleep(2000)
                WEnd
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)

    ; Close the Notepad process using the PID returned by Run.
    If $iPID Then ProcessClose($iPID)
EndFunc   ;==>Example

Func botzyc()
    $counter = 0
    While $counter <= 5

        menu()
        
        ZNszanse()

        Oreklame()

        powrot()
        
    WEnd

EndFunc   ;==>botzyc

Func Cofnij()

    $result2 = _ImageSearch($back, 1, $x1, $y1, 0, 0)
    ConsoleWrite($result2)
    $result3 = _ImageSearch($krec, 1, $x1, $y1, 0, 0)
    ConsoleWrite($result3)
    Do
        Sleep(6000)
        MouseClick('primary', $x1, $y1, 1)
    Until $result3 = 1

EndFunc   ;==>Cofnij

Func menu()

    $result2 = _ImageSearch($menu, 1, $x1, $y1, 0, 0)
    ConsoleWrite($result2)

    If $result2 = 1 Then
        MouseClick('primary', $x1, $y1, 1)
    Else
        ConsoleWrite('nie widze menu')
    EndIf
EndFunc   ;==>menu

Func ZNszanse()

    $result2 = _ImageSearch($znszanse, 1, $x1, $y1, 0, 0)
    ConsoleWrite($result2)

    If $result2 = 1 Then
        MouseClick('primary', $x1, $y1, 1)
    Else
        ConsoleWrite('nie widze szansy')
    EndIf

EndFunc   ;==>ZNszanse

Func Oreklame()

    $result2 = _ImageSearch($oreklame, 1, $x1, $y1, 0, 0)
    ConsoleWrite($result2)

    If $result2 = 1 Then
        MouseClick('primary', $x1, $y1, 1)
        Sleep(1000)
        $liczbaklikniec = $liczbaklikniec + 1
    Else
        ConsoleWrite('nie widze reklamy')
    EndIf

EndFunc   ;==>Oreklame

Func powrot()
    $result2 = _ImageSearch($menu, 1, $x1, $y1, 0, 0)
    ConsoleWrite($result2)

    If $liczbaklikniec = 1 Then
        Do
            MouseClick('primary', 1269, 699, 1)
            Sleep(6000)
        Until $result2 = 1
        MouseClick('primary', $x1, $y1, 1)
        $liczbaklikniec = $liczbaklikniec - 1

    Else
    EndIf

EndFunc   ;==>powrot

the problem is when shoud stop cliks it still does that. Please help

Edited by Melba23
Added code tags
Link to post
Share on other sites
  • Moderators

pawelliz,

Welcome to the AutoIt forums.

When you post code please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags.

But please pay attention to where you post - the "AutoIt Projects and Collaboration" section where you started this thread is not for general support questions.  I have moved it for you, but would ask you to be more careful in future.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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