Jump to content
Sign in to follow this  
DNnlee

need gui help: How do i run something when button is pressed

Recommended Posts

DNnlee

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

Share this post


Link to post
Share on other sites
MrCreatoR

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

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
DNnlee

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

Share this post


Link to post
Share on other sites
MrCreatoR

where do i input my program?

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

what does the Consolewrite do for me?

Nothing, it's just an example :).

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

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
DNnlee

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

Share this post


Link to post
Share on other sites
MrCreatoR

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

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
KegRaider

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

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  

×