Jump to content
Sign in to follow this  
stackover

keep function in loop when start other function

Recommended Posts

a guys made an script almost as I want.. look and help too plz

http://www.autoitscript.com/forum/index.php?showtopic=40209

you do realize that this script is nearly exactly what combining my two templates would be? Anyway, you almost have it right in the script you posted in post #3 in the other thread.

Global $CMD=0, $ACM=0
local $TimerStatus=0, $TimerValue
HotkeySet ("{F5}", "ClickMouseDireito")
HotkeySet ("{F7}", "AutoCleanMode1")

while 1
    if $CMD=1 then
        MouseClick("Left")
    endif

    if $ACM=1 then
        if TimerDiff($TimerValue)>20000 and $TimerStatus>0 Then
            Switch $TimerStatus
                case 1
                    MouseMove(400, 400)
                    MouseMove(420, 420)
                    $TimerStatus=2
                    $TimerValue=TimerInit()
                case 2
                    MouseMove(400, 400)
                    MouseMove(420, 420)
                    $TimerStatus=1
                    $TimerValue=TimerInit()
            EndSwitch
        ElseIf $TimerStatus=0 then
            $TimerStatus=1
            $TimerValue=TimerInit()
        EndIf
        endif

        sleep(50)
wend

Func ClickMouseDireito()
    $CMD-=1
    $CMD*=-1
EndFunc

Func AutoCleanMode1()
    $ACM-=1
    $ACM*=-1
EndFunc

Edit: fixed bug; changed else to elseif $timerstatus=0 then

Edited by improbability_paradox

Share this post


Link to post
Share on other sites

For the record, I put this together because I saw the effort you put into the script in the other thread. In the future you should know that making multiple threads to ask for the same thing is frowned upon, and will likely cause you to get no help at all. You could have put the above script together without asking again, if you had really tried to combine my two earlier templates. Doing it another way isn't a problem, so long as you show that you are trying to figure it out, not just asking someone else to write your script for you.

Also, the above script is untested, but should do exactly what you've asked for.

Edit: You do realize that both mousemoves are the same? You may want to edit the coordinates...

Edited by improbability_paradox

Share this post


Link to post
Share on other sites

I told you that it is untested, but the code IS sound... (barring that I didn't mis anything obvious, but the concept is right) you understand that, the way I have it configured, it will take 20 second before the F7 "function" begins to do anything? and, if you press f7 again during that time, it will abort? that is the way it is written.

Edit: I did make a stupid mistake! I will update the code momentarily

Edited by improbability_paradox

Share this post


Link to post
Share on other sites

Look it .. What im trying ... I think is that way

Here hotkeyset and variables


Func OnOff()
    
;-------------------------------------------------------------------------------------------
;--- Função p/ Click Direito do Mouse ------------------------------------------------------
;-------------------------------------------------------------------------------------------    
    If @HotKeyPressed = '{F5}' Then
        $ClickMouseDireito = True
        Call ( "RequestOff" )
    EndIf
    
;-------------------------------------------------------------------------------------------
;--- Função p/ Click Esquerdo do Mouse -----------------------------------------------------
;-------------------------------------------------------------------------------------------
    If @HotKeyPressed = '{F6}' Then
        $ClickMouseEsquerdo = True
        Call ( "RequestOff" )
    EndIf
    
    If @HotKeyPressed = '{F7}' Then
        If $AutoCleanMode1 = False Then
        $AutoCleanMode1 = True
        Else
        $AutoCleanMode1 = False
        $AutoCleanOnOff1 = False
        Endif
    EndIf
EndFunc
;-------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------
;----------------------------------- Manter o Bot ------------------------------------------
;-------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------
While 1
;-------------------------------------------------------------------------------------------
;--- Função p/ Click Direito do Mouse ------------------------------------------------------
;-------------------------------------------------------------------------------------------
    If $ClickMouseDireito Then

        MouseDown ("Right")
        Call ("Desfoque")
        Send (" ")
        MouseUp ("Right")
        Send (" ")
        Sleep(60)

    EndIf
;-------------------------------------------------------------------------------------------
;--- Função p/ Click Esquerdo do Mouse -----------------------------------------------------
;-------------------------------------------------------------------------------------------
    If $ClickMouseEsquerdo Then

        MouseDown ("Left")
        Call ("Desfoque")
        Send (" ")
        MouseUp ("Left")
        Send (" ")
        Sleep(60)

    EndIf

;-------------------------------------------------------------------------------------------
;--- Função p/ Auto Clean Modo 1 -----------------------------------------------------------
;-------------------------------------------------------------------------------------------
    
    If $AutoCleanMode1 Then
        If Not $AutoCleanOnOff Then
            $AutoCleanOnOff = true
            $TimerStatus = 1
            $ContAutoClean = TimerInit()
        ElseIf TimerDiff($ContAutoClean) >= 10000 Then
            Switch $TimerStatus
                case 1
                    MouseMove(400, 400)
                    MouseMove(420, 420)
                    $TimerStatus=2
                case 2
                    MouseMove(500, 400)
                    MouseMove(520, 420)
                    $TimerStatus=1
            EndSwitch
            $AutoCleanOnOff = false
        EndIf
    EndIf
WEnd
Edited by stackover

Share this post


Link to post
Share on other sites

Finally works.... Look code.

Func OnOff()
    
;-------------------------------------------------------------------------------------------
;--- Função p/ Click Direito do Mouse ------------------------------------------------------
;-------------------------------------------------------------------------------------------    
    If @HotKeyPressed = '{F5}' Then
        $ClickMouseDireito = True
        Call ( "RequestOff" )
    EndIf
    
;-------------------------------------------------------------------------------------------
;--- Função p/ Click Esquerdo do Mouse -----------------------------------------------------
;-------------------------------------------------------------------------------------------
    If @HotKeyPressed = '{F6}' Then
        $ClickMouseEsquerdo = True
        Call ( "RequestOff" )
    EndIf
    
    If @HotKeyPressed = '{F7}' Then
        If $AutoCleanMode1 = False Then
        $AutoCleanMode1 = True
        $TimerStatus = 1
        Else
        $AutoCleanMode1 = False
        $AutoCleanOnOff1 = False
        Endif
    EndIf
EndFunc
;-------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------
;----------------------------------- Manter o Bot ------------------------------------------
;-------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------
;-------------------------------------------------------------------------------------------
While 1
;-------------------------------------------------------------------------------------------
;--- Função p/ Click Direito do Mouse ------------------------------------------------------
;-------------------------------------------------------------------------------------------
    If $ClickMouseDireito Then

        MouseDown ("Right")
        Call ("Desfoque")
        Send (" ")
        MouseUp ("Right")
        Send (" ")
        Sleep(60)

    EndIf
;-------------------------------------------------------------------------------------------
;--- Função p/ Click Esquerdo do Mouse -----------------------------------------------------
;-------------------------------------------------------------------------------------------
    If $ClickMouseEsquerdo Then

        MouseDown ("Left")
        Call ("Desfoque")
        Send (" ")
        MouseUp ("Left")
        Send (" ")
        Sleep(60)

    EndIf

;-------------------------------------------------------------------------------------------
;--- Função p/ Auto Clean Modo 1 -----------------------------------------------------------
;-------------------------------------------------------------------------------------------
    
    If $AutoCleanMode1 Then
        If Not $AutoCleanOnOff Then
            $AutoCleanOnOff = true
            $ContAutoClean = TimerInit()
        ElseIf TimerDiff($ContAutoClean) >= 10000 Then
            Switch $TimerStatus
                case 1
                    MouseMove(400, 400)
                    MouseMove(420, 420)
                    $TimerStatus=2
                case 2
                    MouseMove(100, 400)
                    MouseMove(100, 420)
                    $TimerStatus=1
            EndSwitch
            $AutoCleanOnOff = false
        EndIf
    EndIf
WEnd

Share this post


Link to post
Share on other sites

Glad you got it working! One suggestion: move the sleep(60) from inside the if-then statements to outside, so that the script will sleep whether or not it is clicking one of the mouse buttons. You will lower your CPU usage that way, but other than that it really shouldn't affect the script.

;-------------------------------------------------------------------------------------------
;--- Função p/ Click Direito do Mouse ------------------------------------------------------
;-------------------------------------------------------------------------------------------
    If $ClickMouseDireito Then

        MouseDown ("Right")
        Call ("Desfoque")
        Send (" ")
        MouseUp ("Right")
        Send (" ")
        ;Sleep(60)

    EndIf
;-------------------------------------------------------------------------------------------
;--- Função p/ Click Esquerdo do Mouse -----------------------------------------------------
;-------------------------------------------------------------------------------------------
    If $ClickMouseEsquerdo Then

        MouseDown ("Left")
        Call ("Desfoque")
        Send (" ")
        MouseUp ("Left")
        Send (" ")
        ;Sleep(60)

    EndIf

sleep(60)
Edited by improbability_paradox

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
Sign in to follow this  

×
×
  • Create New...