Shitobu

Ending a while executing

3 posts in this topic

I have this code:

 

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

_main()

Func _main()
   Global $resetButton
   Global $startButton
   Global $iMsg

   Global $loop = 0

   GUICreate("Startup", 109, 30)

   $resetButton = GUICtrlCreateButton("Reset", 5, 5, 50, 20)
   $startButton = GUICtrlCreateButton("Start", 56, 5, 50, 20)

   GUISetState()

   While 1
      Global $iMsg = GUIGetMsg()

      Select
         Case $iMsg = $GUI_EVENT_CLOSE
            $loop = 0
            ExitLoop

         Case $iMsg = $startButton
            $loop = 1
            _loop()

         Case $iMsg = $resetButton
            $loop = 0
      EndSelect
   WEnd

   GUIDelete()
   Exit
EndFunc

Func _loop()

   While $loop == 1

      if $iMsg = $resetButton Then
         $loop = 0
         _main()
      EndIf

      Send("{1}")
      sleep(1000)
   WEnd
EndFunc

 

What I'm trying to do is doing a startup program that will open every program I want as soon as I run it. But for now, since it's not complete, I'm facing this problem:

I made it spam "1" to be sure it's running, with a delay fo 1 sec.

With it, I would like to be able to STOP the while of the function _loop() if I wanted.

For example, the script is opening my facebook. But for now it's okay, now I wanna close the script. I press F8 <or any key> and the script will stop the loop like $resetButton was supposed to.

But I can't <the script doesn't receive the stop function, it just keeps spamming the while>.

What do I do?

Share this post


Link to post
Share on other sites



#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Opt("GUIOnEventMode", 1)
_main()
;=======================================================================================================
Func _main()
   Global $resetButton
   Global $startButton
   Global $iMsg

   Global $loop = 0

   GUICreate("Startup", 109, 30)

   $resetButton = GUICtrlCreateButton("Reset", 5, 5, 50, 20)
   GUICtrlSetOnEvent(-1, "Reset")
   $startButton = GUICtrlCreateButton("Start", 56, 5, 50, 20)
   GUICtrlSetOnEvent(-1, "Start")
   HotKeySet('{END}', 'Quit')
   GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
   GUISetState()

While 1
    If $loop = 1 Then
ConsoleWrite('ON - '&@MSEC&@CRLF)
;Send("{1}")
    Else
    ;Whatever or nothing
    EndIf
sleep(500)
WEnd
EndFunc
;=======================================================================================================
Func Reset()
    $loop = 0
    ConsoleWrite('Reset - '&@MSEC&@CRLF)
EndFunc
;=======================================================================================================
Func Start()
$loop = 1
ConsoleWrite('Start - '&@MSEC&@CRLF)
EndFunc
;======================================================================================
Func Quit()
    Exit
EndFunc   ;==>Quit
;=======================================================================================================

 


Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Firefox Profile Backup - Backup/restore previously saved profile.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

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