Jump to content

Recommended Posts

Posted

I have made a bot using Autoit, it works fine but i wanted to add a GUI that controls it

This is what i have so far, not sure how to make it so when i press Pause on the GUI, it pauses the bot.

or where shall i enter the codes for my bot

#include <GUIConstants.au3>
GUICreate("Gui Program", 225, 400,0,335  ) 
GUISetState (@SW_SHOW)

$start = GUICtrlCreateButton("Start Bot", 15, 350, 60)
$pause = GUICtrlCreateButton("Pause Bot", 80, 350, 60)
$stop = GUICtrlCreateButton("Stop Bot", 145, 350, 60)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $start
        GUICtrlCreateLabel("Running", 70, 20)
        While 1
            $nMsg = GUIGetMsg()
            Switch $nMsg
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $pause
                    GUICtrlCreateLabel("Paused", 70, 20)
                case $stop
                    GUICtrlCreateLabel("Stopped", 70, 20)
                ;ExitLoop
            EndSwitch
        WEnd
     EndSwitch
Wend
Posted

Something like this:

#include <GUIConstants.au3>

Global $IsPaused = True

GUICreate("Gui Program", 225, 400, 0, 335) 
GUISetState(@SW_SHOW)

$Status_Label = GUICtrlCreateLabel("Stopped", 70, 20, 150)

$Start_Button = GUICtrlCreateButton("Start Bot", 15, 350, 60)
$Pause_Button = GUICtrlCreateButton("Pause Bot", 80, 350, 60)
$Stop_Button = GUICtrlCreateButton("Stop Bot", 145, 350, 60)

While 1
    $nMsg = GUIGetMsg()
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Start_Button
            GUICtrlSetData($Status_Label, "Running")
            
            AdlibEnable("_MyWorkingFunction", 1000) ;Every second call our function
            $IsPaused = False
        Case $Stop_Button
            GUICtrlSetData($Status_Label, "Stopped")
            AdlibDisable()
        Case $Pause_Button
            GUICtrlSetData($Status_Label, "Paused")
            $IsPaused = True
    EndSwitch
Wend

Func _MyWorkingFunction()
    If $IsPaused Then Return ;We do nothing if the state is "Paused".
    
    ConsoleWrite("Do stuff here.." & @LF)
EndFunc

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

  MrCreatoR said:

Something like this:

#include <GUIConstants.au3>

Global $IsPaused = True

GUICreate("Gui Program", 225, 400, 0, 335) 
GUISetState(@SW_SHOW)

$Status_Label = GUICtrlCreateLabel("Stopped", 70, 20, 150)

$Start_Button = GUICtrlCreateButton("Start Bot", 15, 350, 60)
$Pause_Button = GUICtrlCreateButton("Pause Bot", 80, 350, 60)
$Stop_Button = GUICtrlCreateButton("Stop Bot", 145, 350, 60)

While 1
    $nMsg = GUIGetMsg()
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Start_Button
            GUICtrlSetData($Status_Label, "Running")
            
            AdlibEnable("_MyWorkingFunction", 1000) ;Every second call our function
            $IsPaused = False
        Case $Stop_Button
            GUICtrlSetData($Status_Label, "Stopped")
            AdlibDisable()
        Case $Pause_Button
            GUICtrlSetData($Status_Label, "Paused")
            $IsPaused = True
    EndSwitch
Wend

Func _MyWorkingFunction()
    If $IsPaused Then Return ;We do nothing if the state is "Paused".
    
    ConsoleWrite("Do stuff here.." & @LF)
EndFunc

sorry, i don't really understand where do i input my program? and what does the Consolewrite do for me?

i tried doing this, and when i press pause, it wouldn't stop

Func _MyWorkingFunction()
    If $IsPaused Then Return;We do nothing if the state is "Paused".
    mousemove(50,50)
EndFunc
Posted

  Quote

where do i input my program?

:) under _MyWorkingFunction() ? but i supose you figured it out? :)

  Quote

what does the Consolewrite do for me?

Nothing, it's just an example :).

  Quote

i tried doing this, and when i press pause, it wouldn't stop

Well, are you sure that you fast enough to press pause before the mouse jumps to the left up corner of the screen?

It's work for me if i put a msgbox there...

Func _MyWorkingFunction()
    If $IsPaused Then Return ;We do nothing if the state is "Paused".
    
    MsgBox(0, "", "Hello")
EndFunc

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

  MrCreatoR said:

:) under _MyWorkingFunction() ? but i supose you figured it out? :)

Nothing, it's just an example :).

Well, are you sure that you fast enough to press pause before the mouse jumps to the left up corner of the screen?

It's work for me if i put a msgbox there...

Func _MyWorkingFunction()
    If $IsPaused Then Return ;We do nothing if the state is "Paused".
    
    MsgBox(0, "", "Hello")
EndFunc

yes, im sure it doesn't work if i put it under _myworkingfunction

it works only with msgbox because it loads it, and load it repeatedly... my program doesn't just do one thing and repeat

i needed for the Pause button to pause my bot instantly at that moment when i press it.

Posted

  Quote

i needed for the Pause button to pause my bot instantly at that moment when i press it.

In my example the function will be not called after the pause, if you want to stop all the stuff that your function doing in the "real time" you will have to check the $IsPaused variable.. and maybe better way is using OnEvent mode, something like this:

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

Global $IsPaused = True

GUICreate("Gui Program", 225, 400, 0, 335)
GUISetOnEvent($GUI_EVENT_CLOSE, "MainEvents_Proc")

$Status_Label = GUICtrlCreateLabel("Stopped", 70, 20, 150)

$StartPause_Button = GUICtrlCreateButton("Start Bot", 15, 350, 60)
GUICtrlSetOnEvent(-1, "MainEvents_Proc")

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
    _MyBot()
Wend

Func MainEvents_Proc()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $StartPause_Button
            $IsPaused = Not $IsPaused
            
            If $IsPaused Then
                GUICtrlSetData($Status_Label, "Running")
                GUICtrlSetData($StartPause_Button, "Start Bot")
            Else
                GUICtrlSetData($Status_Label, "Paused")
                GUICtrlSetData($StartPause_Button, "Pause Bot")
            EndIf
    EndSwitch
EndFunc

Func _MyBot()
    If $IsPaused Then Return ;We do nothing if the state is "Paused".
    
    $iCount = 0
    
    ;In this loop you do whatever you need while the state is not "Paused".
    While Not $IsPaused
        $iCount += 1
        Sleep(500)
        ConsoleWrite("Just counting example: " & $iCount & @LF)
    WEnd
EndFunc

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

  DNnlee said:

yes, im sure it doesn't work if i put it under _myworkingfunction

it works only with msgbox because it loads it, and load it repeatedly... my program doesn't just do one thing and repeat

i needed for the Pause button to pause my bot instantly at that moment when i press it.

Hi DNnlee,

I have been working on a Bot also, tweaking it for quite some time, and realized that I also needed a 'Pause' function. I pressed F1 in SciTE and looked for the solution. In this case the help file was perfect. My bot relies heavily on the mouse, so me pressing a button wouldn't suffice. I made it as a "Hotkey" and it works great.

This is taken straight from the help file....

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")

;;;; Body of YOUR program would go here;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

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