You are never gonna get an elegant solution by trying to say "This input key maps directly to that output key".
What instead you need to do is define a concept of a vector (A value of -1, 0 or 1) for each of the two axes (x and y) and tell the code what effect each input key has on each vector.
eg
pressing a sets the x axis vector to -1
releasing a sets the x axis vector to 0
pressing d sets the x axis vector to 1
pressing w sets the y axis vector to -1
pressing d sets the y axis vector to 1
Then, given both the x and y values are either -1, 0, or 1, you can build a matrix that tells you what the output key is.
eg
x = -1 and y = -1 (up left) is Numpad7
x = 1 and y = 1 (down right) is Numpad3
So given that you know the last and new vectors are for each axis x, we can tell what action to take
eg x/y was -1,-1 (up left = Numpad7) and is now 0,-1 (up = Numpad8) we know to release Numpad7 and hold Numpad8
Code: Select all
outputKeys := {-1: {-1: "Numpad7", 0: "Numpad4", 1: "Numpad1"}
, 0: {-1: "Numpad8", 0:"", 1: "Numpad2"}
, 1: {-1: "Numpad9", 0: "Numpad6", 1: "Numpad3"}}
w::
ProcessKeys("y", -1)
return
s::
ProcessKeys("y", 1)
return
w up::
s up::
ProcessKeys("y", 0)
return
a::
ProcessKeys("x", -1)
return
d::
ProcessKeys("x", 1)
return
a up::
d up::
ProcessKeys("x", 0)
return
^Esc::
ExitApp
ProcessKeys(axis, vector){
static keyVectors := {x: 0, y: 0}
static otherAxes := {x: "y", y: "x"}
global outputKeys
otherAxis := otherAxes[axis]
newVectors := {}
newVectors[axis] := vector
newVectors[otherAxis] := keyVectors[otherAxis]
oldKey := outputKeys[keyVectors.x, keyVectors.y]
newKey := outputKeys[newVectors.x, newVectors.y]
if (newKey != oldKey){
if (oldKey != ""){
str := "{Blind}{" oldKey " up}"
Send % str
;~ ToolTip % str
}
if (newKey != ""){
str := "{Blind}{" newKey " down}"
Send % str
;~ ToolTip % str
}
keyVectors[axis] := vector
}
}