Is it possible to have a "toggleable" function inside a script? Topic is solved

Ask gaming related questions (AHK v1.1 and older)
F_B
Posts: 9
Joined: 15 Jun 2021, 14:29

Is it possible to have a "toggleable" function inside a script?

Post by F_B » 01 Aug 2021, 18:02

So I have two sections of a script that I am trying to figure out how to combine into one and have a one-line that I can "toggle" on command

First part:

Code: Select all

^Space::
Space::
Loop
{
	if not GetKeyState("Space","P")
		break
	Send {Space}
	Sleep 875
}
return
Second part:

Code: Select all

^LShift::
LShift::
Loop
{
	if not GetKeyState("LShift","P")
		break
	Send {LButton Down}
	Sleep 7
	Send {Space}
	Sleep 863
	Send {LButton Up}
}
return
Does anyone have any ideas on how I can combine the two where the Space button will be kept held down but the LButton will trigger whenever I press the LShift key?

My little script works this way but sometimes it messes up and I've been seeing if I can iron that issue out by combining both of them into one.

F_B
Posts: 9
Joined: 15 Jun 2021, 14:29

Re: Is it possible to have a "toggleable" function inside a script?

Post by F_B » 01 Aug 2021, 18:21

Looking back at it now, I've probably shouldn't have used the word toggleable in the title.

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

Re: Is it possible to have a "toggleable" function inside a script?  Topic is solved

Post by Rohwedder » 02 Aug 2021, 10:58

Hallo,
try:

Code: Select all

*Space::
IF !TSpace
	SetTimer, TSpace, 875,% TSpace:=True
Return
*Space Up::SetTimer, TSpace, Off,% TSpace:=False
TSpace:
Send, {Space}
Return
*LShift::
While, GetKeyState("LShift","P")
{
	Send {LButton Down}
	Sleep 7
	Send {Space}
	Sleep 863
	Send {LButton Up}
}
Return

F_B
Posts: 9
Joined: 15 Jun 2021, 14:29

Re: Is it possible to have a "toggleable" function inside a script?

Post by F_B » 02 Aug 2021, 15:34

:bravo: Thank you! This is exactly what I was looking for! :bravo:

Post Reply

Return to “Gaming Help (v1)”