Jump to content

Pause/Run and Quit Button GUI


Ilounah
 Share

Recommended Posts

Good day Sir/Mam could you please lend me or path me on the right path because im confuse how to make Pause/Resume function using GUI, I know how to use Hotkeyset but we need to use GUI button could you please link me some information, I search on google but seems complicated. :sweating:

This is my created GUI using Koda

#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=

$Form1 = GUICreate("Computer II - Section B4", 286, 51, 335, 219)

$Button1 = GUICtrlCreateButton("START", 16, 8, 113, 33)

$Button2 = GUICtrlCreateButton("PAUSE", 152, 8, 113, 33)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

I just want to have a TogglePause using GUI Button I Made my script is

WinActivate ( "Untitled - Notepad" )

ControlSend("[Title:Untitled - Notepad]", "", "[CLASS:Edit1]", "the quick Brown Fox jump over the lazy dog.")

Sleep (1000)

ControlSend("[Title:Untitled - Notepad]", "", "[CLASS:Edit1]", "{ENTER}")

Thanks more power to you guys! :thumbsup:
Link to comment
Share on other sites

Hi,

There are plenty of toggle pause functions in the forum and here.

You will need to use the GUICtrlSetOnEvent function instead of the HotKeySet one.

Edit: Please use [autoit][/autoit] code tags to post your scripts ;)

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Hi,

There are plenty of toggle pause functions in the forum and here.

You will need to use the GUICtrlSetOnEvent function instead of the HotKeySet one.

Edit: Please use

[/autoit] code tags to post your scripts ;)

Br, FireFox.
[/quote]

[font='comic sans ms', cursive] [/font][font=comic sans ms,cursive]Thanks sir Firefox o:)[/font]

[font='comic sans ms', cursive]I try may best to fix it and i got this[/font]



[autoit]#include
#include
#include
#Region ### START Koda GUI section ### Form=
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Pause Toggle Project", 297, 65, 351, 254)
$Button1 = GUICtrlCreateButton("PAUSE / RESUME", 8, 16, 129, 33)
$Button2 = GUICtrlCreateButton("TERMINATE", 160, 16, 129, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetOnEvent($Button1, "TogglePause")
GUICtrlSetOnEvent($Button2, "Terminate")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

Global $NoWork
While 1
ConsoleWrite(123 & @CRLF)
Sleep(1000)
WEnd

Func TogglePause()
$NoWork = Not $NoWork
While $NoWork
sleep(100)
ToolTip('Typing 123 Console has been Pause!',491,149)
WEnd
ToolTip("")
EndFunc

Func Close()
Exit
EndFunc ;==>CancelPressed

Func Terminate()
Exit 0
EndFunc ;==>Terminate

Running the tscript works in send 123 to the Console.

Close button also work (Exit)

Terminate button also work (Exit)

May problem is the Pause / Resume Button at first click it works but to toggle it to resume it is stuck and function terminate and exit dont work. Could you path me in right coding thanks im not expert in programming im just starting thanks. :sweating:

Link to comment
Share on other sites

AutoIt is a single threaded language, if you have a while in your functions (or blocking stuff) then it will block the main while, hence the GUIs will stop responding.

You need to put your code in the main while, you can call a function if you have a lot of code.

Here you go :

#include <GUIConstantsEx.au3>

#region GUI
Opt("GUIOnEventMode", 1)

Global $hGUI = 0
Local $iButton1 = 0 ;, $iButton2 = 0

$hGUI = GUICreate("Pause Toggle Project", 297, 65, 351, 254)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$iButton1 = GUICtrlCreateButton("PAUSE / RESUME", 8, 16, 129, 33)
GUICtrlSetOnEvent($iButton1, "TogglePause")

;~ $iButton2 = GUICtrlCreateButton("TERMINATE", 160, 16, 129, 33)
;~ GUICtrlSetOnEvent($iButton2, "Terminate")

GUISetState(@SW_SHOW, $hGUI)
#endregion GUI

Global $blPaused = False

While 1
    Sleep(1000)
    If $blPaused Then ContinueLoop ;if the script is paused then continue the loop to the start

    ;this part is only executed when the script is not paused
    ConsoleWrite("123" & @CRLF)
WEnd

Func TogglePause()
    $blPaused = Not $blPaused

    ToolTip("Typing 123 Console has been Paused !", 491, 149)
EndFunc   ;==>TogglePause

Func _Exit()
    GUIDelete($hGUI)
    Exit
EndFunc   ;==>_Exit

Br, FireFox.

Link to comment
Share on other sites

Yehey :sorcerer: I found my answer in my project thanks to google :D

the DO..Until command.

#include 
#include 
#include 
#Region ### START Koda GUI section ### Form=
Opt("GUIOnEventMode", 1)
$doit = False
$Form1 = GUICreate("Pause Toggle Project", 297, 65, 351, 254)
$Button1 = GUICtrlCreateButton("PAUSE / RESUME", 8, 16, 129, 33)
$Button2 = GUICtrlCreateButton("TERMINATE", 160, 16, 129, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUICtrlSetOnEvent($Button1, "TogglePause")
GUICtrlSetOnEvent($Button2, "Terminate")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

GUISetState()

While 1
Sleep(100)
If $doit Then
$i = 0
Do

ConsoleWrite(123 & @CRLF)
Sleep(1000)

Until $i = 100 Or $doit = False
ToolTip('Stopping Loop...')
Sleep(1500)
$doit = False
ToolTip('')
EndIf
WEnd


Func TogglePause()
$doit = Not $doit
EndFunc

Func Close()
Exit
EndFunc ;==>CancelPressed

Func Terminate()
Exit 0
EndFunc ;==>Terminate
Link to comment
Share on other sites

AutoIt is a single threaded language, if you have a while in your functions (or blocking stuff) then it will block the main while, hence the GUIs will stop responding.

You need to put your code in the main while, you can call a function if you have a lot of code.

Here you go :

#include <GUIConstantsEx.au3>

#region GUI
Opt("GUIOnEventMode", 1)

Global $hGUI = 0
Local $iButton1 = 0 ;, $iButton2 = 0

$hGUI = GUICreate("Pause Toggle Project", 297, 65, 351, 254)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$iButton1 = GUICtrlCreateButton("PAUSE / RESUME", 8, 16, 129, 33)
GUICtrlSetOnEvent($iButton1, "TogglePause")

;~ $iButton2 = GUICtrlCreateButton("TERMINATE", 160, 16, 129, 33)
;~ GUICtrlSetOnEvent($iButton2, "Terminate")

GUISetState(@SW_SHOW, $hGUI)
#endregion GUI

Global $blPaused = False

While 1
    Sleep(1000)
    If $blPaused Then ContinueLoop ;if the script is paused then continue the loop to the start

    ;this part is only executed when the script is not paused
    ConsoleWrite("123" & @CRLF)
WEnd

Func TogglePause()
    $blPaused = Not $blPaused

    ToolTip("Typing 123 Console has been Paused !", 491, 149)
EndFunc ;==>TogglePause

Func _Exit()
    GUIDelete($hGUI)
    Exit
EndFunc ;==>_Exit

Br, FireFox.

Ill save this it will keep handy for future use thanks firefox.. :thumbsup:
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...