Hi all, I'm looking for some help to troubleshoot a short script that is not quite behaving as expected. For context, the aim of this script is to let me toggle the "Walk" function in-game (which requires holding a key down) by simply clicking it once to toggle on, and clicking it again to toggle off. This bit is simple and works well. However, to complicate matters, I'd also like certain other keys to instantly toggle off the "Walk" function so that if any of them are pressed, it will immediately send a "Key Up" input to the walk modifier.
Here's the code (I will explain the issue underneath):
Code: Select all
W::
KeyDown := !KeyDown
If KeyDown
{
SendInput {W down}
ToolTip, Walk Mode, 85, 1312
}
Else
{
SendInput {W up}
ToolTip
}
Return
~Esc::
SendInput {W up}
ToolTip
Return
~E::
SendInput {W up}
ToolTip
Return
~G::
SendInput {W up}
ToolTip
Return
The first bit works just fine. I press "W" once and it toggles "Walk mode" on; I press it again to turn it off. And the other three keys also work fine as far as sending the {W up} signal goes. However, I've noticed that whenever the input for {W up} comes from any of the other keys (i.e. Esc, E, and G), it takes two presses – not one – of the "W" key for it to be toggled on again. To clarify:
W (toggle on) >> W (toggle off) >> W (toggle on) = working as intended
W (toggle on) >> Esc or E or G (toggle off) = also working as intended
W (toggle on >> Esc or E or G (toggle off) >> W (toggle on) = does not produce expected result, requires one extra input of "W" to toggle back on
Realistically, this is not a massive issue but I'd like to also treat this as an opportunity to better understand AHK, so any help in figuring this out would be much appreciated.
[Mod action: Moved topic to "Gaming"]