Autorepeat after key held down continously for a set duration.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Rauvagol
Posts: 14
Joined: 25 Apr 2017, 00:30

Autorepeat after key held down continously for a set duration.

Post by Rauvagol » 26 Sep 2022, 16:35

Hello, I am essentially trying to replicate default windows behavior in a text box, but outside of a text box (ie, how you press a button, it sends the keystroke, then after a delay it spams it)

Problem is that with the contained code, if you press the key, then release and re-press it during the sleep, it acts as if that is a continual press, instead of two distinct events. I tried it with "KeyWait, space, T.5" in place of the sleep line, but it seemed like sometimes that would get "stuck" and make the timer continue to run after releasing the spacebar.

Any assistance would be great, I feel like there is a really obvious thing I am missing, but have had no luck finding it.

Code: Select all

	~space::
		sleep, 500
		SetTimer, SpaceHeld, 30
		KeyWait, space
		SetTimer, SpaceHeld, Off
	return

	SpaceHeld:
		Send {space}
	return

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

Re: Autorepeat after key held down continously for a set duration.

Post by mikeyww » 26 Sep 2022, 19:16

Code: Select all

$Space::
SetTimer, Go, -500
Send {Space}
KeyWait, Space
SetTimer, Go, Off
Return

Go:
Send {Space}
SetTimer, Go, -30
Return

Rauvagol
Posts: 14
Joined: 25 Apr 2017, 00:30

Re: Autorepeat after key held down continously for a set duration.

Post by Rauvagol » 27 Sep 2022, 12:33

aha I totally missed the negative period setting, thanks

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

Re: Autorepeat after key held down continously for a set duration.

Post by mikeyww » 27 Sep 2022, 13:01

The key here, most likely, is that the timer is reset whenever it is executed (started). That seems to match what you need. A Sleep does not get reset. The tilde also likely detracted from what you were trying to achieve.

Rauvagol
Posts: 14
Joined: 25 Apr 2017, 00:30

Re: Autorepeat after key held down continously for a set duration.

Post by Rauvagol » 01 Oct 2022, 13:05

yeah, after some more testing, it looks like the tilde was causing some extra weirdness, and replacing it with a send {space} to mimic the "passthrough" behavior did the trick

Post Reply

Return to “Ask for Help (v1)”