Jump to content
Sign in to follow this  
TrickyDeath

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

Recommended Posts

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

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

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

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

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

    • By Garrik
      Hi guys!
       
      I need some help here, is there a way to use Random with While? 
      I need this script to run in between 1 and 4 times but I dont know how to do it, can you please help me?
       
      dim $i=1
      While $i<=4
      Sleep(3000)
      Send("{LWINDOWN}r{LWINUP}")
      Sleep(3000)
      Send("C:\Users\123\Catalogos\tags.txt{ENTER}")
      Sleep(3000)
      WinActivate("tags: Bloc de notas","")
      Sleep(3000)
      Send("{SHIFTDOWN}{END}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{DEL}{DEL}")
      Sleep(3000)
      Send("{CTRLDOWN}g{CTRLUP}{ALTDOWN}{F4}{ALTUP}")
      Sleep(3000)
      Send("{CTRLDOWN}v{CTRLUP}{SPACE}")
      $i=$i+1
      WEnd
    • By plankton
      Hi I want it to search for a specific color in certain area then excute the loop which presses ESC button and stop the loop when the color no longer present in that specific area.  Here is the example of my code. But it doesnt stop when color is disappeared.
       
      Pixelsearch(511, 455, 678, 501, 0xFFFFFF)
      If Not  @Error Then
      While 1
      Sleep(1000)
      Send("{ESC}")
      Pixelsearch(511, 455, 678, 501, 0xFFFFFF)
      If @Error Then Exitloop
       
    • By mannworks00
      Hey all,
      I know this code has been attempted before as a GUI app, and it would not copy text properly. Here is an updated version of the Google Search Shortcut  Script from: Google Search Shortcut Script
      #Region #AutoIt3Wrapper_Outfile=shortcuts.exe #EndRegion #include <Clipboard.au3> Opt("TrayMenuMode", 3) Opt("TrayOnEventMode", 1) HotKeySet("{F1}", "_googleit") TraySetToolTip("Right click to exit") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "_exit") While 1 Sleep(20) WEnd #cs _googleit() Source User: ViciousXUSMC https://www.autoitscript.com/forum/topic/177446-google-search-shortcut-script/?do=findComment&comment=1273519 #ce Source Func _googleit() Opt("WinTitleMatchMode", 2) ;Set Title Match To "Any Part of String" $sOldClip = ClipGet() ;Save Current Clipboard Send("^c") ;Copy Selected Text to Clipboard *before losing focus of current window WinActivate("Google Chrome", "") ; activate chrome ShellExecute("https://www.google.at/search?q=" & URLEncode(_ClipBoard_GetData())) ;Navigate to search ClipPut($sOldClip) ;Restore Old Clipboard Opt("WinTitleMatchMode", 1) ; Sets back to default EndFunc ;==>_googleit ;URL encoding is critical when doing string search queries via URL. #cs URLEncode Source User: Dhilip89 - UnicodeURL UDF https://www.autoitscript.com/forum/topic/46894-unicodeurl-udf/ #ce Func URLEncode($UnicodeURL) $UnicodeBinary = StringToBinary($UnicodeURL, 4) $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1) $UnicodeBinaryLength = StringLen($UnicodeBinary2) Local $EncodedString For $i = 1 To $UnicodeBinaryLength Step 2 $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2) If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString('0x' & $UnicodeBinaryChar, 4)) Then $EncodedString &= BinaryToString('0x' & $UnicodeBinaryChar) Else $EncodedString &= '%' & $UnicodeBinaryChar EndIf Next Return $EncodedString EndFunc ;==>URLEncode Func _exit() $result = MsgBox(1, "Shortcuts", "Do you wish to exit Shortcuts?", 0) If $result == 1 Then Exit EndFunc ;==>_exit  
       
      shortcuts.au3
      shortcuts.exe
    • 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  
    • 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  
×
×
  • Create New...