WASD with release input and diagonals for roguelikes

Ask gaming related questions (AHK v1.1 and older)
RogueCodes
Posts: 2
Joined: 29 Jul 2021, 11:17

WASD with release input and diagonals for roguelikes

29 Jul 2021, 14:10

I'm pretty new to AHK and trying to make a script with WASD diagonal movement for roguelikes like Caves of Qud. The script I've made so far is below and it includes text of issues I'm having with each section:

Code: Select all


; Below are lines to make wasd only activate on release of those keys, to prevent accidental rapid steps and missteps. I'm making wasd = wasd because I still want to be able to type in-game, rather than have them translate to numpad 8426.

w Up:: SendInput {w}
return

a Up:: SendInput {a}
return

s Up:: SendInput {s}
return

d Up:: SendInput {d}
return

; I noticed that I couldn't type wasd in uppercase with the script active unless I included the bit below.

+w Up:: SendInput {W}
return

+a Up:: SendInput {A}
return

+s Up:: SendInput {S}
return

+d Up:: SendInput {D}
return

; These are wasd combinations to create diagonals on the numpad. For example, w + a = Numpad 7 = Move Northwest. This feels buggy, as sometimes I will hit a diagonal combo, it will put out the correct numpad key, but will also include the latter wasd key after. For example, if I hit w & d, it will throw out a 9, but sometimes inputs d after as well. I also tried to use {___ up}{___ down} because documentation said this would prevent the hotkey from repeating when held, but that doesn't seem to be the case.

w & a:: SendInput  {Numpad7 down}{Numpad7 up}
return

w & d:: SendInput  {Numpad9 down}{Numpad9 up}
return

s & a:: SendInput  {Numpad1 down}{Numpad1 up}
return

s & d:: SendInput {Numpad3 down}{Numpad3 up}
return

; Below are reversed duplicates because w & a:: as a command doesn't also imply a & w:: for some reason. Same issue as above.

a & w:: SendInput {Numpad7 down}{Numpad7 up}
return

d & w:: SendInput {Numpad9 down}{Numpad9 up}
return

a & s:: SendInput {Numpad1 down}{Numpad1 up}
return

d & s:: SendInput {Numpad3 down}{Numpad3 up}
return

; Below are lines for cancellations. For instance, w & s = nothing. It works, but has the same issue as above. So w & s will sometimes throw out an s, when it should be nothing.

w & s:: SendInput {null}
return

s & w:: SendInput {null}
return

a & d:: SendInput {null}
return

d & a:: SendInput {null}
return

The main thing is I just want it to stop spitting out the unwanted wasd inputs after I do diagonals and cancellations. Any help is appreciated.
User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: WASD with release input and diagonals for roguelikes

29 Jul 2021, 17:09

An idea is below.

Code: Select all

SetKeyDelay,, 25
a::a
w::w
d::d
s::s
w & s::
s & w::
a & d::
d & a::Return
a & w::
w & a::Send {Numpad7}
d & w::
w & d::Send {Numpad9}
a & s::
s & a::Send {Numpad1}
d & s::
s & d::Send {Numpad3}
RogueCodes
Posts: 2
Joined: 29 Jul 2021, 11:17

Re: WASD with release input and diagonals for roguelikes

30 Jul 2021, 11:08

mikeyww wrote:
29 Jul 2021, 17:09
An idea is below.

Code: Select all

SetKeyDelay,, 25
a::a
w::w
d::d
s::s
w & s::
s & w::
a & d::
d & a::Return
a & w::
w & a::Send {Numpad7}
d & w::
w & d::Send {Numpad9}
a & s::
s & a::Send {Numpad1}
d & s::
s & d::Send {Numpad3}
This is much cleaner and works great, thank you!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 86 guests