Press the Esc key to end the Loop.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chngrcn
Posts: 190
Joined: 29 Feb 2016, 08:55

Press the Esc key to end the Loop.

07 Dec 2018, 10:51

Hi.
I have a code that contains the loop below.
I want to stop the loop when I press Esc. How can I do this?
Thank you.

Code: Select all

Test:

loaded := false
While !loaded
{
    try
    {
         err := add5(driver.executeScript("return document.documentElement.innerHTML"), "error",0)
			if ( err != "error")
			{
				loaded := true
			}
			else
			{
				return
			}
			
    }
    Sleep 10
}

loaded := false
While !loaded
{
    try
    {
        if driver.executeScript("return document.getElementById('formId:tesComponent:Tpi_label').innertext = '7103'") 
            loaded := true
    }
    Sleep 10
 }
 
 return
 
hymal7
Posts: 66
Joined: 14 Sep 2016, 05:37

Re: Press the Esc key to end the Loop.

07 Dec 2018, 11:15

put this at the end of your code

Code: Select all

esc::exitapp
User avatar
Scr1pter
Posts: 1277
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Press the Esc key to end the Loop.

07 Dec 2018, 12:19

I'm not sure if he actually wants to exit the whole script?
Probably more setting a variable to false when pressing Esc.

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
chngrcn
Posts: 190
Joined: 29 Feb 2016, 08:55

Re: Press the Esc key to end the Loop.

07 Dec 2018, 18:26

hymal7 wrote:
07 Dec 2018, 11:15
put this at the end of your code

Code: Select all

esc::exitapp
if i use the code that you have given, it will exit gui. I did not mention the existence of gui in the subject. sorry. The goal is to close the loop before the gui closes and the gui is locked. I want to be able to end the loop with esc key, no matter where in the loop. Hopefully there are solutions? thank you.
cristofayre
Posts: 6
Joined: 21 Jul 2022, 07:15

Re: Press the Esc key to end the Loop.

27 Jul 2022, 03:54

I had a loop that I had to pause whilst I completed another action, then press a button to continue. The solution came in something called "input" which basically waits for an input until it continues with script. (It may not help directly as I don't think you want to pause each loop, but only when you hit escape)

Code: Select all

Loop:
{
Additional code to run
Input, SingleKey, L1, {Home}{Down}
if (ErrorLevel == "EndKey:Down"){
nF.Push(line)
Send {HOME, D}
}
else{
proc.Push(line)
}
}
}
This waits for me to press the HOME key to push data to "nF" array, or the down arrow to save to "proc" array

There might be something in that code that is usable.

You might also try a "while" loop which would be easier to break out of. Something like:

Code: Select all

While (x=1){
Your code
if ({Esx}){
x=0;
}
}
i

Note: This is not exact syntax, only a guide. It's basically saying, "Whilst x is 1, (true) go through the loop again. If it is 0 (false)then exit loop" When you hit the Esc key, x is set to 0.So the "condition" of the while loop is false and it exits

NB: I have only been using AHK four days, so far from an expert!)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CoffeeChaton and 158 guests