Can I write this better? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Can I write this better?

Post by LAPIII » 01 Feb 2023, 11:30

Is there a different way to script this:

Code: Select all

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

morreo
Posts: 27
Joined: 08 Dec 2022, 10:57

Re: Can I write this better?

Post by morreo » 01 Feb 2023, 12:25

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?

gmoises
Posts: 74
Joined: 18 Nov 2017, 16:43

Re: Can I write this better?

Post by gmoises » 01 Feb 2023, 13:18

Code: Select all

#Requires AutoHotkey v1.1.36+
SetKeyDelay, 100

Loop, 3
	Send, +{Tab}

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: Can I write this better?

Post by AHK_user » 01 Feb 2023, 13:39

Even better :lol:

Code: Select all

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

Loop 3
	Send("+{Tab}")

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Can I write this better?  Topic is solved

Post by malcev » 01 Feb 2023, 14:19

More precisely not 100, but 110.

Code: Select all

SetKeyDelay, 110
Send, +{Tab 3}

william_ahk
Posts: 493
Joined: 03 Dec 2018, 20:02

Re: Can I write this better?

Post by william_ahk » 02 Feb 2023, 03:02

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)

User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: Can I write this better?

Post by Scr1pter » 02 Feb 2023, 05:36

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!
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09

wer
Posts: 57
Joined: 29 Nov 2022, 21:28

Re: Can I write this better?

Post by wer » 02 Feb 2023, 06:31

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}

william_ahk
Posts: 493
Joined: 03 Dec 2018, 20:02

Re: Can I write this better?

Post by william_ahk » 02 Feb 2023, 06:41

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.

Post Reply

Return to “Ask for Help (v1)”