Jump to content

Exitloop on key press?


BoscoB
 Share

Recommended Posts

I have the following script that works as I need it but want to input a exitloop so that if I press a key (specified if need be) that the loop is exited. The documention only shows examples from what I can see of if a variable reaches a trigger point.

CODE
HotKeySet("{ESC}", "Terminate")

HotKeySet("1", "Normal")

HotKeySet("2", "Fast")

Opt("SendKeyDelay", 60)

While 1

Sleep(100)

WEnd

Func Terminate()

Exit 1

EndFunc

Func Normal()

$i = 0

WinActivate("????2", "")

While $i <= 9999

Send("z", 1)

$i = $i + 1

WEnd

EndFunc

Func Fast()

$i = 0

WinActivate("????2","")

Opt("SendKeyDelay", 3)

While $i <= 999

Send("z", 1)

$i = $i + 1

WEnd

EndFunc

Can this be done or do I need to re-evaluate my code and try a different approach?

BoscoB

Link to comment
Share on other sites

_IsPressed involves a lot of "included code" for such a simple request.

Outshynd pointed out a good way for the OP's specific code since it uses:

While $i <= 9999

This sample code should work no matter what expression is driving the loop:

HotKeySet("{ESC}", "dummy")

While 1
    Sleep(100)
    ToolTip("Looping")
    If @HotKeyPressed = "{ESC}" Then ExitLoop
WEnd

Func dummy()
EndFunc   ;==>dummy
Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

_IsPressed involves a lot of "included code" for such a simple request.

What I meant by this is - using _IsPressed the way it was suggested adds 440+ lines of code to your script when you only needed 4 lines to do what the OP asked for.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

I know its a small script, and i would use another approach to the problem. I would rather use a second variable.

All loops would have this

$endloop = 0
While (Your argument) or ($endloop = 1)


WEndoÝ÷ Ù8^¯y§îËb¢v¬¶¬jëh×6Func EndLoop()
$exitloop = 1
EndFunc
oÝ÷ Ø    Ý{azÚ)¡ûazÇ+ZºÚ"µÍÛØ[    ÌÍÙ^]ÛÜHÝÙ^TÙ]
    ][ÝÝ  ][ÝË  ][ÝÑ[ÛÜ ][ÝÊB

This way you can use it in differnet loops without the same variables etc (Non tested)

Edited by Shevilie

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Link to comment
Share on other sites

I know its a small script, and i would use another approach to the problem. I would rather use a second variable.

All loops would have this

$endloop = 0
While (Your argument) or ($endloop = 1)


WEndoÝ÷ Ù8^¯y§îËb¢v¬¶¬jëh×6 Func EndLoop()
$exitloop = 1
EndFunc
 oÝ÷ Ø   Ý{azÚ)¡ûazÇ+ZºÚ"µÍÛØ[    ÌÍÙ^]ÛÜHÝÙ^TÙ]
    ][ÝÝ  ][ÝË  ][ÝÑ[ÛÜ ][ÝÊBoÝ÷ Ù8b³²Êj{¬z+bØ}êçzÙh¢0ØhºÛazƦzö«¦åzÇ­pÚ'µë-yßêº^N«yªÞjÙ^jËmÂÞjÊ'²ØZ·*.(!¶z-Á©í¶(¶¬®­{TájÜ"Z''±ÛayË«­éíZ¥{õÙh¢!WÿN§üLb´º(¦X§yƧ{­ë-yÙh¢Ñh¯ó^ÆÙh¢"xLb´º(§}¶+n+aj·^®ÚÆZ{azZ Êjw±¦·¬²*'Â+aÞ¶§¢w®¦z{m¡ª^®Ê'ì-£
â¶)àr^"ØbKajܨºgÛhºÇªº@Ú®¢Ø§²×vêºN®«¨µh­«¨´êêºméh¢"W(ا¹æ¬àjÊ'zíæ«éÛ"²Úîy8b±Êz+#ºËm¢)eºËkjצÊ"Ò'­æ¥'ÞÊ°¢é]«Þjz-êÞÆ+¢wb¶*'Â+a{ajÕ¡W¿XIÝ)nëmꮢÒý8^ñ1Ò袮¢Ù¶Â)ejYhÃ*.¶±Öè¶h¢Ù¨½ê'¶!jׯz·(u謶èZ0jëh×6HotKeySet("{ESC}", "dummy")

For $i = 1 To 10000
    While 1
        Sleep(100)
        ToolTip("Looping")
        If @HotKeyPressed = "{ESC}" Then ExitLoop 2
    WEnd
Next

Func dummy()
EndFunc   ;==>dummy

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Well the or was a typo :)

And after looking through your script i would also prefer the

HotKeySet("{ESC}", "dummy")

For $i = 1 To 10000
    While 1
        Sleep(100)
        ToolTip("Looping")
        If @HotKeyPressed = "{ESC}" Then ExitLoop 2
    WEnd
Next

Func dummy()
EndFunc   ;==>dummy

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

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