How can I interrupt a loop by pressing "any" key in AHK?

clayton33

I currently have a script that repeatedly presses the left mouse button, until the script is interrupted. To start and stop the script the ALT+2 is pressed. How can I have it start with ALT+2 but stop by pressing any key?

#MaxThreadsPerHotkey 3
!2::  ; ALT+2 hotkey 
#MaxThreadsPerHotkey 1
if KeepWinZRunning  
{
    KeepWinZRunning := false  ; 
    return  ; 
}

; Otherwise:
KeepWinZRunning := true
Loop
{
    ToolTip, Press ALT+2 again to stop.
    Sleep 100
    Send, {VK01 down}{VK01 up}
    Sleep 100
    if not KeepWinZRunning  

        break  ; Break out of this loop.

}
KeepWinZRunning := false  ; Reset in preparation for the next press of this hotkey.
ToolTip
return

ExitApp
F12::ExitApp
MCL

As per my comment, here's an example using Timers and Input:

endKeys={enter}{tab}{LControl}{RControl}{LAlt}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}

!2::
    SetTimer, SendSomething, 200
    Input, pressedKey, I L1, % endKeys
    SetTimer, SendSomething, Off
return

SendSomething:
    Send, {VK01 down}{VK01 up}
return

You may have to complete the list of endkeys, depending on your keyboard layout.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C++: How can I make an infinite loop stop when pressing any key?

From Dev

How can I change the var of a javascript function by pressing a key on the keyboard?

From Dev

How can I terminate a loop when pressing Enter

From Dev

How can I bind my mouse wheel to scroll down with a key, and this key is.. (AHK)

From Dev

How can I bind my mouse wheel to scroll down with a key, and this key is.. (AHK)

From Dev

In AHK, how do I say if key pressed is left arrow key

From Dev

How do I check if the user is pressing a key?

From Dev

AHK — How to interrupt alternate keys for same hotkey?

From Dev

how do I create a program in windows that can be activated by pressing short cut key instead of clicking?

From Dev

After typing a URL in Google Chrome, how can I launch the address without pressing the Return/Enter key?

From Dev

How can I run another app when pressing the calculator key on my keyboard?

From Dev

How can I get Unity to display applications when pressing start key?

From Dev

Android: How to trigger any key pressing event on soft keyboard?

From Dev

How to trigger mouse right click when pressing any other key?

From Dev

How to trigger mouse right click when pressing any other key?

From Dev

Exiting while loop by pressing enter without blocking. How can I improve this method?

From Dev

How to change what I've set a key to do in ahk

From Dev

How to interrupt a GPIO RPi loop at any time with TKinter button

From Dev

how can I interrupt a peach query?

From Dev

How can I immediately terminate a Thread? (Not interrupt)

From Dev

How can I make interrupt() work?

From Dev

exiting a loop by pressing a escape key

From Dev

How can I build a Trap function with any key

From Dev

How can I make "Press any key to continue"

From Dev

How can i improve my random programm AHK Script

From Dev

How to interrupt a loop with a hotkey

From Dev

How can I indicate in a Swift that key of for loop is NSString?

From Dev

How do I call a button click by pressing the Enter key in Powershell

From Dev

In java how do I check if a user is pressing a certain key?

Related Related

  1. 1

    C++: How can I make an infinite loop stop when pressing any key?

  2. 2

    How can I change the var of a javascript function by pressing a key on the keyboard?

  3. 3

    How can I terminate a loop when pressing Enter

  4. 4

    How can I bind my mouse wheel to scroll down with a key, and this key is.. (AHK)

  5. 5

    How can I bind my mouse wheel to scroll down with a key, and this key is.. (AHK)

  6. 6

    In AHK, how do I say if key pressed is left arrow key

  7. 7

    How do I check if the user is pressing a key?

  8. 8

    AHK — How to interrupt alternate keys for same hotkey?

  9. 9

    how do I create a program in windows that can be activated by pressing short cut key instead of clicking?

  10. 10

    After typing a URL in Google Chrome, how can I launch the address without pressing the Return/Enter key?

  11. 11

    How can I run another app when pressing the calculator key on my keyboard?

  12. 12

    How can I get Unity to display applications when pressing start key?

  13. 13

    Android: How to trigger any key pressing event on soft keyboard?

  14. 14

    How to trigger mouse right click when pressing any other key?

  15. 15

    How to trigger mouse right click when pressing any other key?

  16. 16

    Exiting while loop by pressing enter without blocking. How can I improve this method?

  17. 17

    How to change what I've set a key to do in ahk

  18. 18

    How to interrupt a GPIO RPi loop at any time with TKinter button

  19. 19

    how can I interrupt a peach query?

  20. 20

    How can I immediately terminate a Thread? (Not interrupt)

  21. 21

    How can I make interrupt() work?

  22. 22

    exiting a loop by pressing a escape key

  23. 23

    How can I build a Trap function with any key

  24. 24

    How can I make "Press any key to continue"

  25. 25

    How can i improve my random programm AHK Script

  26. 26

    How to interrupt a loop with a hotkey

  27. 27

    How can I indicate in a Swift that key of for loop is NSString?

  28. 28

    How do I call a button click by pressing the Enter key in Powershell

  29. 29

    In java how do I check if a user is pressing a certain key?

HotTag

Archive