hotkey for loop - problem in my script

Ask gaming related questions (AHK v1.1 and older)
Opatulek
Posts: 4
Joined: 07 Dec 2021, 09:34

hotkey for loop - problem in my script

Post by Opatulek » 07 Dec 2021, 10:18

Hello!

I have a problem with the hotkeys for loop sections in my script, what I want is to make it choose betwen one of two labels by using hotkey F1 for first loop and F2 for second one, but the main problem is that I can choose only one time F1/F2 then it will stuck on label1 or label2 (depending on what I choose ) and hotkey F1/F2 will not work anymore so I can't go back, my goal is make it work every time I click F1 or F2, I will be grateful if someone try help me <3 :oops: I am a noob at scripting and have already spent many hours creating this script.

Code: Select all

SetKeyDelay, 0
SetMouseDelay, 0
Setbatchlines, -1
#SingleInstance, Force
{
Label1:
Loop,
{
If WinActive("x")
{
PixelGetColor, Checka, 2665,164
PixelGetColor, Checkr, 2666,190
If (Checka <> 0xABABAB)
{
SendInput {F11}
Sleep, 200
}
Sleep, 30
If (Checkr <> 0x5ED4F1)
{
SendInput {F12}
Sleep, 200
}
}
Sleep, 30
}
$F1:: gosub, Label1
return
}
{
Label2:
Loop,
If WinActive("x")
{
PixelGetColor, Checkf, 2663,164
PixelGetColor, Checkd, 2664,191
If (Checkf <> 0x6985C7)
{
SendInput {F8}
Sleep, 200
}
Sleep, 30
If (Checkd <> 0xEDEDED)
{
SendInput {F9}
Sleep, 200
}
Sleep, 30
}
$F2:: gosub, Label2
return
}
$NumpadAdd:: Pause
return

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

Re: hotkey for loop - problem in my script

Post by Rohwedder » 07 Dec 2021, 11:07

Hallo,
try:

Code: Select all

SetKeyDelay, 0
SetMouseDelay, 0
Setbatchlines, -1
#SingleInstance, Force
SetTimer, Loops, 100
$F1::Loop = 1
$F2::Loop = 2
Loops:
While, Loop = 1
{
	If WinActive("x")
	{
		PixelGetColor, Checka, 2665,164
		PixelGetColor, Checkr, 2666,190
		If (Checka <> 0xABABAB)
		{
			SendInput {F11}
			Sleep, 200
		}
		Sleep, 30
		If (Checkr <> 0x5ED4F1)
		{
			SendInput {F12}
			Sleep, 200
		}
	}
	Sleep, 30
}
While, Loop = 2
{
	If WinActive("x")
	{
		PixelGetColor, Checkf, 2663,164
		PixelGetColor, Checkd, 2664,191
		If (Checkf <> 0x6985C7)
		{
			SendInput {F8}
			Sleep, 200
		}
		Sleep, 30
		If (Checkd <> 0xEDEDED)
		{
			SendInput {F9}
			Sleep, 200
		}
	}
	Sleep, 30
}
return
$NumpadAdd:: Pause
return

Opatulek
Posts: 4
Joined: 07 Dec 2021, 09:34

Re: hotkey for loop - problem in my script

Post by Opatulek » 07 Dec 2021, 11:34

@Rohwedder working perfectly! big thanks!

Post Reply

Return to “Gaming Help (v1)”