Make GUI Toggle Button Function inside loop

Ask gaming related questions (AHK v1.1 and older)
PeanutBoi
Posts: 1
Joined: 25 Jan 2022, 21:13

Make GUI Toggle Button Function inside loop

Post by PeanutBoi » 25 Jan 2022, 21:23

I've made a loop (about a year ago) to help me AFK farm in a game, however, I'm currently trying to adapt it to a GUI toggle button instead of a keyboard shortcut. I've figured out how to create a GUI toggle button with certain parameters, but I can't find online how to have an infinite loop where the button is able to be toggled off while the loop is running. The code works as a toggle button exactly how I want it to without the loop, and if I was fine with it simply being on forever, it would also be working perfectly. However, I'd like to be able to toggle the loop off by pressing the same button again while it's running.
Thanks for any help you're able to offer!
Attachments
BikeFarmBut.ahk
(755 Bytes) Downloaded 49 times

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

Re: Make GUI Toggle Button Function inside loop

Post by mikeyww » 25 Jan 2022, 23:01

An easy technique is to have your button execute Reload. Another is to set a hotkey to Pause your script.

Rohwedder
Posts: 7624
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Make GUI Toggle Button Function inside loop

Post by Rohwedder » 26 Jan 2022, 03:21

Hallo,
try:

Code: Select all

#SingleInstance,Force
Button_State:=0
Gui,1:+AlwaysOnTop
Gui,1:Color,Green
Gui,1:Add,Text,x0 y0 w960 h100 gButton_Press
Gui,1:Add,Progress,x0 y0 w960 h100 BackgroundRed cRed vMy_Button,100
Gui,1:Show,w960 h100, T Button
return
GuiClose:
*^ESC::
ExitApp
Button_Press:
if(Button_state=0)
{
	GuiControl,+cLime,My_Button
	Button_State:=1
	SetTimer, Bike_Farm_Start, -1
}
else if(Button_State=1)
{
	GuiControl,+cRed,My_Button
	Button_State:=0
}
Return
Bike_Farm_Start:
send, {. down}
send, {lshift down}
While Button_State=1
{
	GuiControl,Text,x0 y0 w960 h100 gButton_Press
	send, {w down}
	sleep, 750
	send, {w up}
	send, {s down}
	sleep, 750
	send, {s up}
}
send, {. up}
send, {  down}
send, {  up}
return

Post Reply

Return to “Gaming Help (v1)”