Turbo button Topic is solved

Ask gaming related questions (AHK v1.1 and older)
shamus
Posts: 10
Joined: 29 Jun 2021, 15:37

Turbo button

Post by shamus » 02 Jul 2022, 11:34

I made a toggle and I want it to make holding down the spacebar act like repeatedly clicking the left mouse button. I've tried a few different scripts I found online and so far nothing seems to work.

The toggle (should be working as intended):

Code: Select all

#If
F4::
op := !op
SoundBeep, 1000 + 500 * op
Return
#If
The scripts I tried:

Code: Select all

#If (op)
Space::
while(GetKeyState("Space")) {
	click,down
	sleep 50 ;
	click,up
	sleep 50 ;
}
Return
#If


#If (op)
Space::
while(GetKeyState("Space")) {
	SetKeyDelay, 0, 50
	Send {Click}
}
Return
#If


#If (op)
Space::
while(GetKeyState("Space")) {
	Send {LButton Down}
	sleep 50 
	Send {LButton Up}
	sleep 50
}
Return
#If


What am I doing wrong?
Last edited by BoBo on 02 Jul 2022, 11:38, edited 1 time in total.
Reason: Added [code][/code]-tags.

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Turbo button  Topic is solved

Post by mikeyww » 02 Jul 2022, 14:57

Code: Select all

F4::SoundBeep, 1000 + 500 * op := !op
#If op
Space::
SetKeyDelay, 50, 50
While GetKeyState("Space", "P")
 Send {LButton}
Return
#If
Explained: GetKeyState() parameters

shamus
Posts: 10
Joined: 29 Jun 2021, 15:37

Re: Turbo button

Post by shamus » 02 Jul 2022, 15:30

oh shoot, that makes a lot more sense now. Massive thanks!

shamus
Posts: 10
Joined: 29 Jun 2021, 15:37

Re: Turbo button

Post by shamus » 02 Jul 2022, 15:36

mikeyww wrote:
02 Jul 2022, 14:57

Code: Select all

F4::SoundBeep, 1000 + 500 * op := !op
#If op
Space::
SetKeyDelay, 50, 50
While GetKeyState("Space", "P")
 Send {LButton}
Return
#If
Explained: GetKeyState() parameters
It's working as intended, but when I hold space for a few seconds it keeps spamming left clicks long after letting go of the spacebar. Is there any way around this?

shamus
Posts: 10
Joined: 29 Jun 2021, 15:37

Re: Turbo button

Post by shamus » 02 Jul 2022, 16:08

It only happens with clicking too. I tried replacing it with "Send a" and it no longer lagged.

shamus
Posts: 10
Joined: 29 Jun 2021, 15:37

Re: Turbo button

Post by shamus » 02 Jul 2022, 16:24

Doing this solves the lag, but isn't recognized by most games :(

Code: Select all

#If (op)
Space::
While GetKeyState("Space", "P")
  Send {LButton Down}
  Sleep 100
  Send {LButton Up}
Return
#If
[Mod edit: [code][/code] tags added.]

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Turbo button

Post by mikeyww » 02 Jul 2022, 18:00

In my script, you can adjust the values for the :arrow: SetKeyDelay.

shamus
Posts: 10
Joined: 29 Jun 2021, 15:37

Re: Turbo button

Post by shamus » 02 Jul 2022, 19:22

I tried loads of different values but it seems to keep clicking for about as long as I initially held space down, effectively doubling the total clicks as it's lagging. As I said, the previous code fixed that issue, but it is recognized as a single held down click in most applications for some reason. Is it something to do with Send {LButton Up} ?

User avatar
mikeyww
Posts: 26601
Joined: 09 Sep 2014, 18:38

Re: Turbo button

Post by mikeyww » 02 Jul 2022, 20:03

Indentation looks good but has no effect on how the script works. Use a block! For an example, see line 3 in your first post (second script).

Post Reply

Return to “Gaming Help (v1)”