Help Making Toggle Loop Script

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
melphoi
Posts: 3
Joined: 04 Feb 2023, 08:34

Help Making Toggle Loop Script

Post by melphoi » 04 Feb 2023, 08:45

Hello, I'm new to the Autohotkey V2, so I'm gathering script and try to change few code based from what I need.
These script works fine, but it require me to holding the F1 to make it loop, is there anything I should add to make it like if I press F1, it will start looping, and if I press it again, it will stop the loop, press it again, it will start again, and so on
Thanks in advance

Code: Select all

F1::                                       
{ 
Loop                                                   
{                                                          
    var := GetKeyState("F1", "P") ? "D" : "U"          
    if (var = "U")                                          
        Break                                           
    Click 1205, 642, "Down"
Sleep(200)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(75)
Send '{WheelUp}'
MouseMove 227, 383, 100
Sleep(300)
Send '^c'
Sleep(200)
Send '^{Tab}'
Sleep(750)
Send '^v'
Sleep(750)
Send '{Right}'
Sleep(100)
Send '^{Down}'
Sleep(100)
Send '{Down}{Left}'
Sleep(100)
Send '^+{Tab}'
Sleep(100)
Send '{PgDn 5}'
Sleep(500)
Click 1065, 685, "Up"
Click 1065, 685                                
    Sleep(200)                                         
}                                                           

[Mod action: Moved topic to v2 section]

User avatar
mikeyww
Posts: 26438
Joined: 09 Sep 2014, 18:38

Re: Help Making Toggle Loop Script

Post by mikeyww » 04 Feb 2023, 09:06

Welcome to this AutoHotkey forum!

Code: Select all

#Requires AutoHotkey v2.0
#MaxThreadsPerHotkey 2
SoundBeep 1000

F1:: {
 Static on := False
 If on := !on {
  SoundBeep 1500
  Send 123
  Sleep 10000
  Send 456
  SoundBeep 2000
  on := False
 } Else Reload
}

melphoi
Posts: 3
Joined: 04 Feb 2023, 08:34

Re: Help Making Toggle Loop Script

Post by melphoi » 04 Feb 2023, 09:24

mikeyww wrote:
04 Feb 2023, 09:06
Welcome to this AutoHotkey forum!

Code: Select all

#Requires AutoHotkey v2.0
#MaxThreadsPerHotkey 2
SoundBeep 1000

F1:: {
 Static on := False
 If on := !on {
  SoundBeep 1500
  Send 123
  Sleep 10000
  Send 456
  SoundBeep 2000
  on := False
 } Else Reload
}
Hello,Sir
Thanks for your responses
I tried adding few codes that you provided, but its works normally once, and did not looping at all
It did not start over from first line (Click 1205, 642, "Down")
I need the script to start over again automatically to the first line until I press F1 again when I need it to stop

User avatar
mikeyww
Posts: 26438
Joined: 09 Sep 2014, 18:38

Re: Help Making Toggle Loop Script

Post by mikeyww » 04 Feb 2023, 09:34

Before changing this script, test what is here, so that you know whether you have a working starting point.

Code: Select all

#Requires AutoHotkey v2.0
#MaxThreadsPerHotkey 2
SoundBeep 1000

F1:: {
 Static on := False
 If on := !on {
  Loop {
   Send 123
   Sleep 900
   Send 456
  }
 } Else Reload
}

melphoi
Posts: 3
Joined: 04 Feb 2023, 08:34

Re: Help Making Toggle Loop Script

Post by melphoi » 04 Feb 2023, 09:53

mikeyww wrote:
04 Feb 2023, 09:34
Before changing this script, test what is here, so that you know whether you have a working starting point.

Code: Select all

#Requires AutoHotkey v2.0
#MaxThreadsPerHotkey 2
SoundBeep 1000

F1:: {
 Static on := False
 If on := !on {
  Loop {
   Send 123
   Sleep 900
   Send 456
  }
 } Else Reload
}
Thank you very much,Sir
Now it working as what I expected it to be :superhappy:

Post Reply

Return to “Ask for Help (v2)”