How do I change a toggle hotkey to a held hotkey.

Ask gaming related questions (AHK v1.1 and older)
DryLips
Posts: 2
Joined: 10 Apr 2021, 15:53

How do I change a toggle hotkey to a held hotkey.

10 Apr 2021, 15:59

In a game I am playing, each time you press x it switches perspective. Is there any way to make it so when I hold down on x it presses it once (so switches perspective), then when I let go it presses it again (switches back to original perspective).
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: How do I change a toggle hotkey to a held hotkey.

10 Apr 2021, 17:39

Code: Select all

$x::
Send x
KeyWait, x
Send x
Return
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: How do I change a toggle hotkey to a held hotkey.

11 Apr 2021, 02:37

Hallo,
try:

Code: Select all

$x::
Send x
KeyWait, x
Send x
Return
s::Sleep, 5000
Press the X key down, type S, release X. You will see as long as the S-thread sleeps the X-thread is blocked!
A waiting KeyWait prevents its thread from being terminated. Since in Autohotkey only one thread is active at a time, this can lead to a blockade.
Now try:

Code: Select all

$x::Send,% ["x"][Tx:=1+0 Tx]
$x Up::Send,% ["x"][!Tx:=""]
s::Sleep, 5000
or ternarys instead of arrays:

Code: Select all

$x::Send,% (1=Tx:=1+0 Tx)?"x":
$x Up::Send,% (""=Tx:="")?"x":
s::Sleep, 5000
You can alternatively use this Up-Hotkey with "Extended parameters" in both scripts:

Code: Select all

$x Up::Send,% ("x", Tx:="")
https://www.autohotkey.com/boards/viewtopic.php?f=74&t=82267

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 107 guests