Sign in to follow this  
Followers 0
BoscoB

Exitloop on key press?

9 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

does this help?

#include <Misc.au3>

If _IsPressed ("09") Then $i = 10000

09 is the tab button

Edited by phantom

Share this post


Link to post
Share on other sites

Make a hotkey that sets $i to 10000?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

_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]

Share this post


Link to post
Share on other sites

does this help?

#include <Misc.au3>

If _IsPressed ("09") Then $i = 10000

09 is the tab button

That worked perfectly, thank you!

BoscoB

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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

Share this post


Link to post
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]

Share this post


Link to post
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

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  
Followers 0