Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AHK turn off loop when Key is pressed

I created a code that should send the "E" key until i press the "T" key. Right now the loop only stops when I hold the "T" key. Could someone help me with this.

F12::
    loop
    {
    Send e
    Sleep 3500
    if (GetKeyState("t")) {
    break
    }
    }
return

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I would suggest to use the following code:

   F12::
        Loop    {
            Send, e
            Sleep 3500
            if break
                break
            }
        return
    
    T::
        break := !break
    return

The above script will stop in a interval between 0 and 3500ms after you press the "T" because you have a "Sleep 3500" in each evaluation.

Your script only stop when you HOLD the "T", because the "T" MUST be pressed while the loop IS ON the GETKEYSTATE function.

P.S:
My english is a work in progress..

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading