Toggle and loop only looping once

Get help with using AutoHotkey and its commands and hotkeys
Phasecoder
Posts: 7
Joined: 19 Sep 2017, 12:27

Toggle and loop only looping once

22 Sep 2017, 14:17

Here is my code

Code: Select all

#MaxThreadsPerHotkey 8


numpad1::
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 10, 94, 1032, 776, C:\Users\home\AppData\Roaming\MacroCreator\Screenshots\Screen_20170922172311.png
toggle := !toggle
SetTimer, Trigger, -1
Trigger:
	while(toggle) 
	{
Loop
{
	
		if ErrorLevel = 0
		
			MsgBox, 49, Continue?, Image / Pixel Found at %FoundX%x%FoundY%.`nPress OK to continue.
			IfMsgBox, Cancel
				return
	
	else
		if Errorlevel = 1
			Loop
			{
			SetWinDelay,-1 ;~ to make winactivate etc snappier and less obtrusive
			Sleep, 500
			ChromeSend("{F5}")
			Sleep, 500
			return
			}
		}

	return
	
}
return

	ChromeSend(keys){ ;keys = the keys you want to be sent e.g. "asbnd{space}lk{enter}"
	if (!WinActive("ahk_class Chrome_WidgetWin_1")){
		WinGetActiveTitle,currActive
		WinActivate,ahk_class Chrome_WidgetWin_1
		WinWaitActive,ahk_class Chrome_WidgetWin_1
	}
	Send, %keys%
	WinActivate,%currActive% ;no need to if this since it'll be empty if chrome was active
}
Basically I am trying to get the script to loop with the toogle of numpad1 getting to to run untill i press numpad1 to stop it. but is only working when I have numpad1 pressed in.

Also trying to get it to pause/toggle when the image apperas, im really not gettingit

any help pleaseeeeeeeeeeeeeeeeeeee
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Toggle and loop only looping once

22 Sep 2017, 15:08

Do it like me, make a button to toggle:

Code: Select all

~*t::
if mytoggle=0
{
mytoggle=1
soundbeep,500,200
return
}
if mytoggle=1
{
mytoggle=0
soundbeep,300,100
sleep,100
soundbeep,300,100
return
}
And make a loop that is controllable with your loop breaker:

*F1::
mytoggle=0
Loop,
{
if mytoggle=1
break
yourscript
)
return

Return to “Ask For Help”

Who is online

Users browsing this forum: arcticir, Google [Bot], SmithyZoomZoom and 176 guests