Loop with increments 1a, 1b, 1c, 2a, 2b, 2c, 3a etc

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
cnahk
Posts: 11
Joined: 26 Aug 2018, 13:32

Loop with increments 1a, 1b, 1c, 2a, 2b, 2c, 3a etc

30 Aug 2018, 21:51

Hello, I need to loop the following:

Code: Select all

#!F11::
CoordMode, Mouse, Window
MouseGetPos, StartX, StartY
IfwinExist, ahk_exe abc.exe
WinActivate, ahk_exe abc.exe
WinwaitActive, ahk_exe abc.exe
// loop
Click 2400, 1321
Send {down}
Click 3312, 1321
Send %NUMBER%
// loop
Where %NUMBER% must be the following number+letter each loop:

1a
1b
1c
2a
2b
2c
3a
3b
3c
etc until 500a 500b 500c

I have no idea how to accomplish this... is it possible?

Thanks in advance!
User avatar
Datapoint
Posts: 296
Joined: 18 Mar 2018, 17:06

Re: Loop with increments 1a, 1b, 1c, 2a, 2b, 2c, 3a etc

30 Aug 2018, 21:59

Code: Select all

Loop, 500
{
    i := A_Index
    Loop, 3
    {
        ;Send % i . Chr(96 + A_Index)
        MsgBox % i . Chr(96 + A_Index)
    }
}
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Loop with increments 1a, 1b, 1c, 2a, 2b, 2c, 3a etc

30 Aug 2018, 22:05

There's more than one way to solve this problem. Rather than any loop inside of a loop, here's an answer with a single loop.

In a loop, you have the variable A_Index. We will use this in conjunction with the Ceil() function (Ceil, rounds up) and the Mod() function (Modulus, calculates a remainder from division).

I am going to use the Ternary operator which is a way to say If/else.

The . in there is a concatenate operator. This is how we'll put a number with a letter.

You will see me using a Forced Expression by using a lone % at the start of the Send parameter.

Code: Select all

Loop, 15 ; make into 1500 if you want 1a-500c
{ ; optional when only a single command is in the Loop
Send % Ceil(A_Index/3) . (Mod(A_Index,3)=1 ? "a" : Mod(A_Index,3) = 2 ? "b" : "c")
}
return
The answer by Datapoint reminded me about the Chr() function and that may be used here in fact. It's just a little messy since Mod will loop, when the divisor is 3, between values 1, 2, 0, not 0, 1, 2.

Code: Select all

Loop, 15
    Send % Ceil(A_Index/3) . (Mod(A_Index,3)=0 ? "c" : Chr(96 + Mod(A_Index,3)))
return
cnahk
Posts: 11
Joined: 26 Aug 2018, 13:32

Re: Loop with increments 1a, 1b, 1c, 2a, 2b, 2c, 3a etc

30 Aug 2018, 22:10

You guys are awesome, thanks for that!

Is it possible to start the loop from a different number than 1, say 150a 150b 150c, etc etc until 500 ?
cnahk
Posts: 11
Joined: 26 Aug 2018, 13:32

Re: Loop with increments 1a, 1b, 1c, 2a, 2b, 2c, 3a etc

31 Aug 2018, 11:13

Issue solved thanks to your very helpful replies. What a great community! Thank you very much :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, DataLife, ShatterCoder and 269 guests