What is
KeyWait, b, U for?? Why are you waiting for release of key b after every keypress?
I take it fundamentally that you are trying to convert WSAD into clicks on a virtual d-pad, but bear in mind that the technique you are using will not support diagonals.
The way I solve this problem is to break it down so that the code has a concept of "axis" (x/y) and "vector" (-1, 0, or +1) - ie any of the 8 directions can be described in this way - eg:
up+left is x= -1, y = -1
right is x= +1, y= 0
etc...
Then we build a lookup array with the coordinate for each of these axes.
Code: Select all
ClickCoords := {x: {-1: 100, 0: 250, 1: 400} , y: {-1: 700, 0: 800, 1: 900}}
So let's say you want to click on the left arrow, that's x = -1 and y = 0
looking those values up in the array, we get x=100, y=800
So then, we just need a variable to hold the current position of each "axis" - eg it starts at {x:0, y:0} and when you hold A, it changes it to {x:-1, y:0}
Then the user holds W and it changes the variable to {x: -1, y: -1}
So as you can see, you can use these "vectors" to calculate where the mouse needs to be for any combination of x/y
Code: Select all
#SingleInstance force
; --- User Configurable variables ---
; The coordinates to click at for each axis
; -1 is top or left. +1 is bottom or right
ClickCoords := {x: {-1: 100, 0: 250, 1: 400}
, y: {-1: 700, 0: 800, 1: 900}}
; --- NON User Configurable variables ---
CurrentPos := {x: 0, y: 0}
ClickState := 0
return
w::
HandleMouse("y", -1)
return
s::
HandleMouse("y", 1)
return
s up::
w up::
HandleMouse("y", 0)
return
a::
HandleMouse("x", -1)
return
d::
HandleMouse("x", 1)
return
a up::
d up::
HandleMouse("x", 0)
return
HandleMouse(axis, vector){
global ClickCoords, CurrentPos, ClickState
if (CurrentPos[axis] == vector){
; Key repeat tried to set axis to position it is already in - ignore
return
}
CurrentPos[axis] := vector
if (ClickState){
; If mouse held, release it before moving it
Send {LButton Up}
ClickState := 0
}
x := ClickCoords.x[CurrentPos.x]
y := ClickCoords.y[CurrentPos.y]
MouseMove, x, y, 0
Send {LButton Down}
ClickState := 1
}