Jump to content

Recommended Posts

Posted

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?

Posted
#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
;=======================================================================================================

 

  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

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