Jump to content
Sign in to follow this  
TrickyDeath

Brake while loop with Hotkey / How to use ExitLoop in right way here?

Recommended Posts

TrickyDeath

Hello everyone,

Have a tricky question:
 
How i manage to exit from loop, but not from script?
(ExitLoop it is ok, but runned out of ways, how to use it in my script :( )
 
With this i have a problem:
If i unpause (F2) the script, it will continue the loop.
While scrip is paused (F2) i can restart it (F1), but:
While script is paused (F2), and i open  my form (F3), and try to press button on it, it will not work, cause active loop is paused at background. (I hope i understand right the method)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{F1}", "RunScript")
HotKeySet("{F2}", "Pause")
HotKeySet("{F3}", "OpenForm")

Global $Pause

$GUI_Create_Form = GUICreate("Settings", 175, 95)
$Button_Save = GUICtrlCreateButton("Save", 10, 60, 75, 25)
$Button_Cancel = GUICtrlCreateButton("Cancel", 90, 60, 75, 25)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button_Save
            MsgBox(0, "Notification", "Settings have been saved!", 1)
            GUISetState(@SW_HIDE)
        Case $Button_Cancel
            GUISetState(@SW_HIDE)
    EndSwitch
WEnd

Func RunScript()
    Local $Numbers = 1
    While 1
        $Numbers = $Numbers + 1
        Sleep(250)
        ToolTip("Numbers:" & $Numbers, 0, 0)
    WEnd
EndFunc   ;==>RunScript

Func Pause()
    $Pause = Not $Pause
    While $Pause
        Sleep(100)
        ToolTip('Scrpit is "Paused"', 0, 0)
    WEnd
    ToolTip("", 0, 0)
EndFunc   ;==>Pause

Func OpenForm()
    GUISetState()
EndFunc   ;==>OpenForm

All i want is, brake the counter loop with hotkey.
Can anyone help me to give a logical answare?
(I do need the form with buttons, to store data / save settings)


Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

Share this post


Link to post
Share on other sites
Danyfirex

Hi. You can Use AdlibRegister.

Something like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{F1}", "Start")
HotKeySet("{F2}", "Pause")
HotKeySet("{F3}", "OpenForm")

Global $Pause=False

$GUI_Create_Form = GUICreate("Settings", 175, 95)
$Button_Save = GUICtrlCreateButton("Save", 10, 60, 75, 25)
$Button_Cancel = GUICtrlCreateButton("Cancel", 90, 60, 75, 25)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button_Save
            MsgBox(0, "Notification", "Settings have been saved!", 1)
            GUISetState(@SW_HIDE)
        Case $Button_Cancel
            GUISetState(@SW_HIDE)
    EndSwitch
WEnd



Func RunScript()
Local Static $Numbers = 1
ToolTip("Numbers:" & $Numbers, 0, 0)
$Numbers+=1
EndFunc   ;==>RunScript


Func Start()
    If not $Pause then
    AdlibRegister("RunScript")
    $Pause=True
    EndIf
EndFunc


Func Pause()
    AdlibUnRegister("RunScript")
    $Pause=False
EndFunc


Func OpenForm()
    GUISetState()
EndFunc   ;==>OpenForm

Saludos

Share this post


Link to post
Share on other sites
Danyfirex

Well You real question was another. to break the loop You can do this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{F1}", "RunScript")
HotKeySet("{F2}", "Pause")
HotKeySet("{F3}", "OpenForm")

Global $Pause=False

$GUI_Create_Form = GUICreate("Settings", 175, 95)
$Button_Save = GUICtrlCreateButton("Save", 10, 60, 75, 25)
$Button_Cancel = GUICtrlCreateButton("Cancel", 90, 60, 75, 25)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Button_Save
            MsgBox(0, "Notification", "Settings have been saved!", 1)
            GUISetState(@SW_HIDE)
        Case $Button_Cancel
            GUISetState(@SW_HIDE)
    EndSwitch
WEnd

Func RunScript()
    Local $Numbers = 1
    $Pause=False
    While 1
        $Numbers = $Numbers + 1
        Sleep(250)
        ToolTip("Numbers:" & $Numbers, 0, 0)
        if $Pause=True Then
        ToolTip('Scrpit is "Paused"', 0, 0)
         ExitLoop
        EndIf
    WEnd
EndFunc   ;==>RunScript

Func Pause()
 $Pause=True
EndFunc   ;==>Pause

Func OpenForm()
    GUISetState()
EndFunc   ;==>OpenForm

Sorry for my caveman english :S

Saludos

Share this post


Link to post
Share on other sites
TrickyDeath

I change Pause function as Stop and I added a pause function what only pause the script. So now work fine.

I am able to:

  • Run script
  • Pause script
  • Exit from loop
  • Restart / continue the script

 

Did not know u can use True / False on pause function like this. More simple then Help file examples.

Ps.: Your english is good enough. So do not worry about it. ;)

Thank you!

Tricky

Edited by TrickyDeath
  • Like 1

Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

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  

  • Similar Content

    • tentacole
      By tentacole
      Afternoon!
      This is my first post, so I apologize if this is in the wrong place. 
      I've created a while loop to click in a certain area of an application, and have the y axis change at the end of each loop. My loop continues to click at x:27, x:10, even though the $y is adding 15 at the end of each loop. I did a Send($x) and Send($y) into a Notepad to see if the $y had changed after each loop, and the 15 was being added to $y each loop. (If this makes sense)
       
      I'm unsure where I'm going wrong, and would be extremely grateful if someone can point me in the correct direction to fix this. 
      Local $rDirectory = "H:\oDemandProject\fList.txt" Local $rLine = _FileCountLines($rDirectory) Local $x = 27 Local $y = 10 While $rline > 0 WinActivate("OnDemand", "-> 1") WinWaitActive("OnDemand", "-> 1") ControlClick("OnDemand", "", "[CLASS:AfxFrameOrView120u; INSTANCE:1]", "left", 4, $x, $y) $y += 15 $rLine -= 1 WEnd  
    • guinness
      By guinness
      Right now the script will exit immediately if I don't pause it somehow (obvious of course).
      I was  curious on people's opinions of how they do it or what option they prefer below? Thanks
      Option 1 (I prefer)
      #include <MsgBoxConstants.au3> HotKeySet('^!p', SomeFunc) ProcessWaitClose(@AutoItPID) Func SomeFunc() MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) EndFunc Option 2 (in the help file)
      #include <MsgBoxConstants.au3> HotKeySet('^!p', SomeFunc) While Sleep(100) WEnd Func SomeFunc() MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) EndFunc Option 3
      #include <MsgBoxConstants.au3> HotKeySet('^!p', SomeFunc) While 1 GUIGetMsg() ; Use the internal sleep WEnd Func SomeFunc() MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) EndFunc  
    • rkr
      By rkr
      hi, i am new to autoit. i prepared the attached code which will replace particular values in the file. the program works well in the first pass, but the while loop is not working in the second go. could anyone look into the attached code. If the ';#' in the code are replaced with '#', then the program works well.
      sacs-read.au3
      GMS Det Leg.txt
    • AndreyS
      By AndreyS
      Dear developers and creators of the language, please explain to me why when pressing the combination Crtl + Shift + C from the 5th or the 10th time "sticks / sinks" Ctrl or Shift? And then you need to press Ctrl or Shift again to reset their triggering. I only need to use hot keys like in the example!
      The code is a small example. Its essence is that when a user in the editor selects any number and presses a combination, then it increases by 1. 
      Dim $x HotKeySet("+^c","Calc") While 1 Sleep(10000) WEnd Func Calc() Send("^c") Sleep(50) $x=ClipGet()+1 ClipPut($x) Send("^v") EndFunc I thought that in my program some kind of glitch was searching for a reason for a long time. And it turned out that apparently somehow the work of some functions used in the example is not compatible. 
      Tell me, please, what is the problem?
    • StudioMaker
      By StudioMaker
      Hey anyone knows how i can have a inputbox that is connected to an HotKeySet? Like if u put in like "a" in the inputbox it sets the hotkey to "a"?
       
×