Untitled

mail@pastecode.io avatar
unknown
autohotkey
2 years ago
3.1 kB
22
Indexable
Never
CopyText()
{
    Clipboard := ""
    Send ^c
    ClipWait, 2
    if ErrorLevel
    {
        MsgBox, The attempt to copy text onto the clipboard failed.
        Reload
    }
}

PixelClick(ClickPos_X, ClickPos_Y, PixelColor, Ofset_X := "0", Ofset_Y := "0", Variation := "0", Search_Time_Sec := "2", ContinueScript := "0")
{
    Current_Time := A_TickCount
    Search_Time_Sec := Search_Time_Sec * 1000
    Not_Found := 1
    loop, 7000 {
        sleep, 20
        Time_Passed := A_TickCount - Current_Time
        if (Time_Passed >= Search_Time_Sec)
            break
        PixelSearch, Click_X, Click_Y, ClickPos_X, ClickPos_Y, ClickPos_X, ClickPos_Y, PixelColor, Variation, Fast
        if (ErrorLevel = 0) {
            BlockInput, MouseMove
            Not_Found := 0
            sleep, 200
            if (Ofset_X = "0" And Ofset_Y = "0")
            {
                MouseClick, Left, %ClickPos_X%, %ClickPos_Y%,,,D
                sleep, 50
                MouseClick,,,,,,U
            }
            else
            {
                MouseClick, Left, %Ofset_X%, %Ofset_Y%,,,D
                sleep, 50
                MouseClick,,,,,,U
            }
            BlockInput, MouseMoveOff
            break
        }
    }
    if Not_Found
    {
        if (ContinueScript = "0") {
            SoundBeep, 1000, 500
            MsgBox % "'" PixelColor "' not found. `nSearch time: " format("{1:0.1f}", Time_Passed/1000) " sec"
            Reload
        }
    }
    ClickPos_X := ""
    ClickPos_Y := ""
    PixelColor := ""
    return !Not_Found
}

ImageClick(UpLeft_X, UpLeft_Y, DownRight_X, DownRight_Y, ImageName ,Variation := "0", Search_Time_Sec := "4", ContinueScript := "0", OffsetX := "0", OffsetY := "0")
{
    Current_Time := A_TickCount
    Search_Time_Sec := Search_Time_Sec * 1000
    Not_Found := 1
    loop, 2000 {
        sleep, 20
        Time_Passed := A_TickCount - Current_Time
        if (Time_Passed >= Search_Time_Sec)
            break
        ImageSearch, outX, outY, UpLeft_X, UpLeft_Y, DownRight_X, DownRight_Y, *%Variation% %A_ScriptDir%\%ImageName%
        if (ErrorLevel = 0) {
            BlockInput, MouseMove
            global Click_Count := Click_Count + 1
            Not_Found := 0
            sleep, 200
            if (OffsetX = "0" And OffsetY = "0")
            {
                MouseClick, Left, %outX%, %outY%,,,D
                sleep, 50
                MouseClick,,,,,,U
            }
            else
            {
                MouseClick, Left, %OffsetX%, %OffsetY%,,,D
                sleep, 50
                MouseClick,,,,,,U
                ;MouseMove, %outX%, %outY%
            }
            BlockInput, MouseMoveOff
            break
        }
    }
    if Not_Found
    {
        if (ContinueScript = "0") {
            SoundBeep, 1000, 500
            MsgBox % "'" ImageName "' not found. `nSearch time: " format("{1:0.1f}", Time_Passed/1000) " sec"
            Reload
        }
    }
    UpLeft_X := ""
    UpLeft_Y := ""
    DownRight_X := ""
    DownRight_Y := ""
    ImageName := ""
}