Loop

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Deniz
Posts: 3
Joined: 06 Dec 2021, 02:45

Loop

Post by Deniz » 06 Dec 2021, 02:51

Hi, im new to AHK and i never made a script my-self, and i want to know how can i make a loop macro, but i dont want to have a toggle button (like press f1 to activate, press again f1 to disactivate), i want a loop that its stopping when i release button T.
If anyone can help me that would be nice

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

Re: Loop

Post by Rohwedder » 06 Dec 2021, 03:51

Hallo,
try:

Code: Select all

t::
While, GetKeyState("t","P")
{
	SoundBeep, 4000, 20
	Sleep, 200
	SoundBeep, 1000, 20
	Sleep, 200
}
Return
or with Exit inside every Sleep:

Code: Select all

t::
t Up::
While, Tdown := GetKeyState("t","P")
{
	SoundBeep, 4000, 20
	Sleep(200, TDown)
	SoundBeep, 1000, 20
	Sleep(200, TDown)
}
Return
Sleep(Time,ByRef Active:=True)
{ ;like "Sleep, Time", but if Active becomes False, the Thread ends
    End:= A_TickCount + Time
    While, S:= End-A_TickCount > 0
        IF Active
            Sleep,S>100?100:S
        Else Exit
} ;a long Sleep will be segmented to be able to interrupt it fast

Deniz
Posts: 3
Joined: 06 Dec 2021, 02:45

Re: Loop

Post by Deniz » 06 Dec 2021, 09:13

Rohwedder wrote:
06 Dec 2021, 03:51
Hallo,
try:

Code: Select all

t::
While, GetKeyState("t","P")
{
	SoundBeep, 4000, 20
	Sleep, 200
	SoundBeep, 1000, 20
	Sleep, 200
}
Return
or with Exit inside every Sleep:

Code: Select all

t::
t Up::
While, Tdown := GetKeyState("t","P")
{
	SoundBeep, 4000, 20
	Sleep(200, TDown)
	SoundBeep, 1000, 20
	Sleep(200, TDown)
}
Return
Sleep(Time,ByRef Active:=True)
{ ;like "Sleep, Time", but if Active becomes False, the Thread ends
    End:= A_TickCount + Time
    While, S:= End-A_TickCount > 0
        IF Active
            Sleep,S>100?100:S
        Else Exit
} ;a long Sleep will be segmented to be able to interrupt it fast
Does it spam T?, like how csgo bhop does, it spam space when you press space, because here when i press t, it doesnt spam T after, if you understand

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

Re: Loop

Post by Rohwedder » 06 Dec 2021, 09:40

You wrote:
i want a loop that its stopping when i release button T.
i.e. no hint that the loop should spam anything! In the current state the loop beeps.

Deniz
Posts: 3
Joined: 06 Dec 2021, 02:45

Re: Loop

Post by Deniz » 06 Dec 2021, 10:27

Rohwedder wrote:
06 Dec 2021, 09:40
You wrote:
i want a loop that its stopping when i release button T.
i.e. no hint that the loop should spam anything! In the current state the loop beeps.
I must sound rude or like selfish, but can you please put only button t, to not spam anything, only if that is possible :))
If not thats ok, i will try to find out a different way to fix it

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

Re: Loop

Post by Rohwedder » 06 Dec 2021, 11:54

This?
Tilde: ~ prefix when the hotkey fires, its key's native function will not be blocked.
Replace:

Code: Select all

t::
by:

Code: Select all

~t::
and

Code: Select all

t Up::
by

Code: Select all

~t Up::

Post Reply

Return to “Ask for Help (v1)”