Jump to content

Issues with calling functions with GUI buttons


Recommended Posts

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
;Creating global variables
Global $Go, $Counter, $Start, $Stop, $Pause, $Reset, $Exit

;Actual GUI
Func GUI()
    $GUI = GUICreate("WUMiniMacro", 374, 178, 1536, 851, BitOR($WS_POPUP,$DS_SETFOREGROUND), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
    GUISetIcon("C:\Users\Brandon\Documents\Autoit\BlackEye.ico", -1)
    GUISetBkColor(0x000000)
    $Pic1 = GUICtrlCreatePic("C:\Users\Brandon\Documents\Autoit\BlackEye-jpg.jpg", 160, 32, 100, 100)
    $Key_Choice = GUICtrlCreateLabel("Key of Choice", 8, 8, 89, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "Small Fonts")
    GUICtrlSetColor(-1, 0xFFFF00)
    Global $Key = GUICtrlCreateInput("", 8, 24, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "Times New Roman")
    GUICtrlSetCursor (-1, 5)
    $Tick_Count = GUICtrlCreateLabel("Time Between Presses", 8, 56, 143, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "Small Fonts")
    GUICtrlSetColor(-1, 0xFFFF00)
    Global $Tick = GUICtrlCreateInput("", 8, 72, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER,$WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "Times New Roman")
    GUICtrlSetCursor (-1, 5)
    $Time_Duration = GUICtrlCreateLabel("Time to Run", 8, 104, 79, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "Small Fonts")
    GUICtrlSetColor(-1, 0xFFFF00)
    Global $Time = GUICtrlCreateInput("", 8, 120, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$WS_BORDER))
    GUICtrlSetFont(-1, 8, 800, 0, "Times New Roman")
    GUICtrlSetCursor (-1, 5)
    $Stop = GUICtrlCreateButton("Start", 288, 8, 75, 25, $BS_NOTIFY)
    GUICtrlSetFont(-1, 14, 800, 0, "Small Fonts")
    GUICtrlSetBkColor(-1, 0xA0A0A0)
    GUICtrlSetCursor (-1, 0)
    $Restart = GUICtrlCreateButton("Pause", 288, 72, 75, 25, $BS_NOTIFY)
    GUICtrlSetFont(-1, 14, 800, 0, "Small Fonts")
    GUICtrlSetBkColor(-1, 0xA0A0A0)
    GUICtrlSetCursor (-1, 0)
    $Exit = GUICtrlCreateButton("Exit", 288, 136, 75, 25, $BS_NOTIFY)
    GUICtrlSetFont(-1, 14, 800, 0, "Small Fonts")
    GUICtrlSetBkColor(-1, 0xA0A0A0)
    GUICtrlSetCursor (-1, 0)
    $Stop = GUICtrlCreateButton("Stop", 288, 40, 75, 25, $BS_NOTIFY)
    GUICtrlSetFont(-1, 14, 800, 0, "Small Fonts")
    GUICtrlSetCursor (-1, 0)
    $Reset = GUICtrlCreateButton("Reset", 288, 104, 75, 25, $BS_NOTIFY)
    GUICtrlSetFont(-1, 14, 800, 0, "Small Fonts")
    GUICtrlSetCursor (-1, 0)
    GUISetState(@SW_SHOW)

    ;While loop that constantly checks the buttons and whether they are pressed or not and what to do when they are
    While 1
        $nMsg = GUIGetMsg()
        Select
            Case $nMsg == $Start
                $Counter = 0
                Global $KeyValue = GUICtrlRead($Key, 1)
                Global $TickValue = GUICtrlRead($Tick, 1)
                Global $TimeValue = GUICtrlRead($Time, 1)
                WUMiniMacro() ;On start, run the WUMiniMacro program
            Case $nMsg == $Stop
                $Counter = Time($Time, $Tick) + 1  ;Increase the counter past the while loop threshold to stop the while loop
            Case $nMsg == $Pause ;Pause for a rediculous amount of time
                Sleep(2147483647)
            Case $nMsg == $Reset
                Reset()    ;Run the reset function to set the values of the text boxes to nothing
            Case $nMsg == $Exit
                Exit   ;Because I don't like the look of the X button, the only way to exit is with this button
        EndSelect
    WEnd
EndFunc

;Function to estimate the counter max based on user input
Func Time($Hours, $Seconds)
    Local $AmountSeconds = (60 * $Hours) * 60
    Local $AmountTicks = $AmountSeconds / $Seconds
    Return $AmountTicks
EndFunc

;Function that actually displays the text on screen based on user input
Func WUMiniMacro()
    While $Counter <= Time($TimeValue, $TickValue)
        AutoItSetOption("SendKeyDelay",($TickValue * 1000))
        Send($KeyValue, 1)
        $Counter += 1
    WEnd
EndFunc

;Function for the reset button that sets the text in the input boxes to nothing and resets the while loop counter
Func Reset()
    $Counter = 0
    GUICtrlSetData($Key, "")
    GUICtrlSetData($Tick, "")
    GUICtrlSetData($Time, "")
EndFunc

;Calling the GUI to run everything
GUI()

I tried to commend and organize to make it more readable, but hey...

Posted here because I feel this is going to turn out to be just a general answer not related to the GUI. 

Reset and Stop work just as I intended, but I'm having issues with the GUI button "Start" not actually calling the "WUMiniMacro" function like Reset so easily calls the reset function. Once I can get the Start running, I can go off see if the Stop and Pause functions will work as intended, but I need to be able to start the working script function first. 

Help me figure out why I can't call WUMiniMacro() through the select..case message loop and maybe give me extra pointers if you have time? Thank you!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...