Page 1 of 1

Can I write this better?

Posted: 01 Feb 2023, 11:30
by LAPIII
Is there a different way to script this:

Code: Select all

Send, +{Tab}
Sleep, 100
Send, +{Tab}
Sleep, 100
Send, +{Tab}

Re: Can I write this better?

Posted: 01 Feb 2023, 12:25
by morreo
If you're doing something repeatedly, you can use something call a loop

Code: Select all

Loop, 3
{
Send, +{Tab}
Sleep, 100
}
return
This will execute the code in the loop 3 times. Is that what you meant?

Re: Can I write this better?

Posted: 01 Feb 2023, 13:18
by gmoises

Code: Select all

#Requires AutoHotkey v1.1.36+
SetKeyDelay, 100

Loop, 3
	Send, +{Tab}

Re: Can I write this better?

Posted: 01 Feb 2023, 13:39
by AHK_user
Even better :lol:

Code: Select all

#Requires Autohotkey v2.0-beta.1+
SetKeyDelay(100)

Loop 3
	Send("+{Tab}")

Re: Can I write this better?  Topic is solved

Posted: 01 Feb 2023, 14:19
by malcev
More precisely not 100, but 110.

Code: Select all

SetKeyDelay, 110
Send, +{Tab 3}

Re: Can I write this better?

Posted: 02 Feb 2023, 03:02
by william_ahk
Even betterer :trollface:

Code: Select all

#Requires AutoHotkey v2.0
Persistent

(re(i) => (
	Send("+{Tab}"),
	i != 1 && SetTimer(%A_ThisFunc%.Bind(i-1), -100)
))(3)

Re: Can I write this better?

Posted: 02 Feb 2023, 05:36
by Scr1pter
I think we have different point of views regarding better. :D

morreo's solution is totally fine.
With tab stops it would be perfect, though.

Code: Select all

F1::
Loop, 3
{
    Send, +{Tab}
    Sleep, 100
}
return
Since LAPIII is apparently not an advanced user, I would suggest to use easy and beginner friendly methods.
Omitting { } can lead to unwanted errors while leaving { } will always work.

william_ahk's solution is - in my opinion - clearly a no go.
No offense :)

Cheers!

Re: Can I write this better?

Posted: 02 Feb 2023, 06:31
by wer
you could use while loop to do it whatever times you want:

Code: Select all

max:=2
now:=0
while (now<max)
{
Send, +{Tab}
Sleep, 100
now++
}
Send, +{Tab}
or just ordinary loop with break:

Code: Select all

max:=2
now:=0
loop
{
if now=max
   break
Send, +{Tab}
Sleep, 100
now++
}
Send, +{Tab}

Re: Can I write this better?

Posted: 02 Feb 2023, 06:41
by william_ahk
Scr1pter wrote:
02 Feb 2023, 05:36
william_ahk's solution is - in my opinion - clearly a no go.
I was just being sarcastic :lol: Using loop and sleep is the best in terms of flexibility for sure, SetKeyDelay subtracts that.