double click to hold?

Ask gaming related questions (AHK v1.1 and older)
zongmucan
Posts: 4
Joined: 14 Apr 2021, 02:34

double click to hold?

Post by zongmucan » 14 Apr 2021, 02:56

When I am playing a game,I have to hold "w" to keep my character moving forward,so to release the burden,I hope to just double click "w" to realize that i was holding the "w" all the time until I press something like "s" or just the same "w", for example, I double click w,it output"wwww...", so I put my ahk code like this, but somehow it didn't work. please help

Code: Select all

~w::
if (A_ThisHotkey = A_PriorHotkey And A_TimeSincePriorHotkey < 400)
{
  send {w down}
  keywait s
  send {w up}
}       
Return
F6::suspend

Last edited by BoBo on 14 Apr 2021, 06:39, edited 1 time in total.
Reason: Moved to Gaming section.
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: double click to hold?

Post by Rohwedder » 14 Apr 2021, 05:03

Hallo,
try:

Code: Select all

$w::
if (A_ThisHotkey = A_PriorHotkey And A_TimeSincePriorHotkey < 400)
	Send, {w Down}
Else
	Send, w
Return
~s::Send, {w Up}
F6::suspend
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: double click to hold?

Post by mikeyww » 14 Apr 2021, 05:11

Code: Select all

~w Up::SetTimer, Go, % (double := A_ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 400) ? 20 : "Off"
#If double
s::
w::
SetTimer, Go, Off
double := False
Return
#If
Go:
Send w
Return
This might not be what you want, as it presses the key repeatedly instead of holding.
zongmucan
Posts: 4
Joined: 14 Apr 2021, 02:34

Re: double click to hold?

Post by zongmucan » 14 Apr 2021, 06:59

@Rohwedderit didn't work, but thank you

@mikeywwthank you for your time, it did output "wwww..." but since it is not holding the key, it is not usable in game, can ahk actually hold a key
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: double click to hold?

Post by mikeyww » 14 Apr 2021, 07:09

Code: Select all

~w Up::
If double := A_ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 400 {
 Send {w down}
 SoundBeep, 1500
}
Return
#If double
s::
w::
Send {w up}
double := False
SoundBeep, 1000
Return
#If
zongmucan
Posts: 4
Joined: 14 Apr 2021, 02:34

Re: double click to hold?

Post by zongmucan » 14 Apr 2021, 07:25

not working, is it because of my OS? win10 ltsc 17663.1817
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: double click to hold?

Post by mikeyww » 14 Apr 2021, 07:56

Does it work in Notepad?

Note that the hold might not generate a repeating kind of action-- may depend on the target window or keyboard driver.

Would also see tips for games.

https://autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/
zongmucan
Posts: 4
Joined: 14 Apr 2021, 02:34

Re: double click to hold?

Post by zongmucan » 14 Apr 2021, 08:11

it does not work in notepad, but my another ahk script which i use to remap the key works fine in the game
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: double click to hold?

Post by mikeyww » 14 Apr 2021, 08:49

Hmm. It worked in my testing. Remember that when the key is pressed down in this manner, you will not see the repetitions on the screen.

Perhaps others have a better solution for you.
Post Reply

Return to “Gaming Help (v1)”