Jump to content
Sign in to follow this  
blackeagle93

checkbox interrupting loop

Recommended Posts

blackeagle93

Hello, I want to make a GUI to my script but I cannot figure out how to make checkboxes interrupt a function.

Here is a part of my script:

#include <GUIConstantsEx.au3>
#Include <GuiListView.au3>
#Include <Date.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiScrollBars.au3>
#NoTrayIcon

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)

$Form1 = GUICreate("asd", 280, 280, 193, 90)
$ButtonSeg = GUICtrlCreateCheckbox("", 220, 215, 55, 20)
$cfko = 1
$hwnd = 0

TraySetState()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ButtonSeg
        _SEG()
    EndSwitch
WEnd

Func _SEG()

If (GUICtrlRead($ButtonSeg) = 1) Then
    $ClientName = GUICtrlRead(GUICtrlRead($listviewCLIENT))
    $FixSeg = StringRegExpReplace($ClientName, "[|]", "")
    $hwnd = WinGetHandle($FixSeg)

If @Error Then
    MsgBox(0, "Error", "Sorry, the handle could not be found.")
    Exit
EndIf

AdlibRegister("curse",13500)
AdlibRegister("skill2",500)
AdlibRegister("skill3",500)
AdlibRegister("skill4",500)
AdlibRegister("manapot",50000)

While 2
If $cfko = 1 Then
    AdlibUnRegister("skill2")
    AdlibUnRegister("skill3")
    AdlibUnRegister("skill4")
    Sleep(500)
    Adlibregister("CFspam",500) ; 9x Curse Field again (for sure cast)
    Sleep(4510)
    AdlibUnregister("CFspam")
    Sleep(500)
    ControlSend($hwnd, "", "", "{1}") ; Heal
    Sleep(1000)
    AdlibRegister("skill2",500)
    AdlibRegister("skill3",500)
    AdlibRegister("skill4",500)
    $cfko = 0
EndIf
WEnd

ElseIf (GUICtrlRead($ButtonSeg) = 0) Then

    $cfko = 0
    AdlibUnregister("curse")
    AdlibUnregister("skill2")
    AdlibUnregister("skill3")
    AdlibUnregister("skill4")
    AdlibUnRegister("manapot")

EndIf
EndFunc

Func curse()
    ControlSend($hwnd, "", "", "{3}") ; Curse Field
    $cfko = 1
EndFunc

Func CFspam()
    ControlSend($hwnd, "", "", "{3}")
EndFunc

Func skill2()
    ControlSend($hwnd, "", "", "{4}") ; AOE 1
EndFunc

Func skill3()
    ControlSend($hwnd, "", "", "{5}") ; AOE 2
EndFunc

Func skill4()
    ControlSend($hwnd, "", "", "{6}") ; AOE 3
EndFunc

Func manapot()
    ControlSend($hwnd, "", "", "{F2}")
EndFunc

I would like it to send key "4 5 6" every 500 ms, when it sends key "3" - every 13,5 sec, the 456 sending should stop, send 3 again a few times and then send 1...then continue.

It worked good but I created a GUI with a checkbox.

I dont know how to make it like this - When the checkbox is checked, the keys are being sended.

When I uncheck the checkbox, the keys shouldnt be sended. (idk how to interrupt the loop)

Hope my question is clear -_-

Edited by blackeagle93

Share this post


Link to post
Share on other sites
Edano

an unchecked checkbox has state 4 ($gui_unchecked), not 0. not sure if that helps you.

.

;http://www.autoitscript.com/forum/topic/152963-checkbox-interrupting-loop/
;Post #1
;D:\DOKUME~1\ADMINI~1\LOKALE~1\Temp\SLICER\Avatar\photo-thumb-81311.jpg
;by blackeagle93

;Script grabbed by SLICER by Edano here: http://www.autoitscript.com/forum/topic/152402-slicer-autoit-forum-script-grabber/?p=1093575

#include <GUIConstantsEx.au3>
#Include <GuiListView.au3>
#Include <Date.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiScrollBars.au3>
#NoTrayIcon

Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)

$Form1 = GUICreate("asd", 280, 280, 193, 90)
$ButtonSeg = GUICtrlCreateCheckbox("", 220, 215, 55, 20)
$cfko = 1
$hwnd = 0

TraySetState()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ButtonSeg
        _SEG()
    EndSwitch
WEnd

Func _SEG()
MsgBox(0,"",GUICtrlRead($ButtonSeg));<---------------------
If (GUICtrlRead($ButtonSeg) = 1) Then

    $ClientName = GUICtrlRead(GUICtrlRead($listviewCLIENT))
    $FixSeg = StringRegExpReplace($ClientName, "[|]", "")
    $hwnd = WinGetHandle($FixSeg)

If @Error Then
    MsgBox(0, "Error", "Sorry, the handle could not be found.")
    Exit
EndIf

AdlibRegister("curse",13500)
AdlibRegister("skill2",500)
AdlibRegister("skill3",500)
AdlibRegister("skill4",500)
AdlibRegister("manapot",50000)

While 2
If $cfko = 1 Then
    AdlibUnRegister("skill2")
    AdlibUnRegister("skill3")
    AdlibUnRegister("skill4")
    Sleep(500)
    Adlibregister("CFspam",500) ; 9x Curse Field again (for sure cast)
    Sleep(4510)
    AdlibUnregister("CFspam")
    Sleep(500)
    ControlSend($hwnd, "", "", "{1}") ; Heal
    Sleep(1000)
    AdlibRegister("skill2",500)
    AdlibRegister("skill3",500)
    AdlibRegister("skill4",500)
    $cfko = 0
EndIf
WEnd

ElseIf (GUICtrlRead($ButtonSeg) = 0) Then

    $cfko = 0
    AdlibUnregister("curse")
    AdlibUnregister("skill2")
    AdlibUnregister("skill3")
    AdlibUnregister("skill4")
    AdlibUnRegister("manapot")

EndIf
EndFunc

Func curse()
    ControlSend($hwnd, "", "", "{3}") ; Curse Field
    $cfko = 1
EndFunc

Func CFspam()
    ControlSend($hwnd, "", "", "{3}")
EndFunc

Func skill2()
    ControlSend($hwnd, "", "", "{4}") ; AOE 1
EndFunc

Func skill3()
    ControlSend($hwnd, "", "", "{5}") ; AOE 2
EndFunc

Func skill4()
    ControlSend($hwnd, "", "", "{6}") ; AOE 3
EndFunc

Func manapot()
    ControlSend($hwnd, "", "", "{F2}")
EndFunc

.

E.

 

edit: and this loop has no exit, so it is infinite:

While 2
If $cfko = 1 Then
    AdlibUnRegister("skill2")
    AdlibUnRegister("skill3")
    AdlibUnRegister("skill4")
    Sleep(500)
    Adlibregister("CFspam",500) ; 9x Curse Field again (for sure cast)
    Sleep(4510)
    AdlibUnregister("CFspam")
    Sleep(500)
    ControlSend($hwnd, "", "", "{1}") ; Heal
    Sleep(1000)
    AdlibRegister("skill2",500)
    AdlibRegister("skill3",500)
    AdlibRegister("skill4",500)
    $cfko = 0
EndIf
WEnd

.

you should better

.

If $cfko = 1Then
    AdlibUnRegister("skill2")
    AdlibUnRegister("skill3")
    AdlibUnRegister("skill4")
    Sleep(500)
    Adlibregister("CFspam",500) ; 9x Curse Field again (for sure cast)
    Sleep(4510)
    AdlibUnregister("CFspam")
    Sleep(500)
    ControlSend($hwnd, "", "", "{1}") ; Heal
    Sleep(1000)
    AdlibRegister("skill2",500)
    AdlibRegister("skill3",500)
    AdlibRegister("skill4",500)
    $cfko = 0
EndIf
Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites
UEZ

Which game you want to automate dude?

Br,
UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
blackeagle93

@Edano: ty for your reply...i used the infinite loop to keep the If func checking the value of $cfko. When it is not in the loop, it works only once. $CFko changes to 1, the If ...Then is made. Then it changes back to 0, after the timer runs out, CFko changes to 1 again but nothing happens. thats why i have put it into the inf. loop. Is there any other way to make the If function keep checking for the value of $CFko?

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.