Jump to content

Can't exit loop using function


Recommended Posts

Hi guys,

I'm trying to call an "ExitLoop" with a hotkey function reference.

AutoIt won't let me run the script, saying that "ExitLoop" must be run inside a loop.

A cut down example would be:

__________________________________

HotKeySet("+{F12}", "ExitLoopPause")

WHILE 1

Sleep(500)

WEND

Func ExitLoopPause

ExitLoop

EndFunc

Link to comment
Share on other sites

That's not how ExitLoop is used. It's only used inside For, While, Do loop structures. If you need to exit the script when the hotkey is pressed, try this:

HotKeySet("+{F12}", "ExitLoopPause")

WHILE 1
Sleep(500)
WEND

Func ExitLoopPause
Exit
EndFunc
Edited by steveR
AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.
Link to comment
Share on other sites

I don't want to exit the whole program, just the loop..

That's not how ExitLoop is used. It's only used inside For, While, Do loop structures. If you need to exit the script when the hotkey is pressed, try this:

HotKeySet("+{F12}", "ExitLoopPause")

WHILE 1
Sleep(500)
WEND

Func ExitLoopPause
Exit
EndFunc

<{POST_SNAPBACK}>

Link to comment
Share on other sites

  • Developers

I don't want to exit the whole program, just the loop..

<{POST_SNAPBACK}>

HotKeySet("+{F12}", "ExitLoopPause")
$Looping = 1 

WHILE $Looping
    Sleep(500)
WEND

Func ExitLoopPause
   $Looping = NOT $Looping
EndFunc

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

If you wanted a toggle, do something like this:

opt("wintitlematchmode", 2)

run("notepad")
winwaitactive("Notepad")

HotKeySet("x","_exit")
HotKeySet("a","_toggle")
$flag = 0

While 1
    sleep(10)
    if $flag then _flash()
Wend

func _exit()
    Exit
EndFunc

Func _flash()
    DllCall("user32.dll", "int", "FlashWindow", "hWnd", WinGetHandle("Notepad"), "int", 1)
    sleep(100)
EndFunc

Func _toggle()
    if $flag then
        $flag = 0
    Else
        $flag = 1
    EndIf       
EndFunc
AutoIt3 online docs Use it... Know it... Live it...MSDN libraryglobal Help and SupportWindows: Just another pane in the glass.
Link to comment
Share on other sites

Thanks.

Worked nicely :)

Also worth noting, you can't use F12; from the help file "It is also reserved by Windows, according to its API."

Made basic changes to suit script..

$Looping = 1

WHILE $Looping = 1

Sleep(500)

WEND

Func ExitLoopPause

$Looping = 0

EndFunc

Cheers.

HotKeySet("+{F12}", "ExitLoopPause")
$Looping = 1 

WHILE $Looping
    Sleep(500)
WEND

Func ExitLoopPause
   $Looping = NOT $Looping
EndFunc

<{POST_SNAPBACK}>

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