I'm looking for some help with a script I wrote to make it easier for me to play video games. I have a motor disability, which makes it difficult for me to hold down the W key in order to move my character forward.
Here's the script I came up with:
Code: Select all
#NoEnv
#SingleInstance force
#Persistent
; Creation of the Windows speech synthesis object
voice := ComObjCreate("SAPI.SpVoice")
; Initialization of the automatic walking variable to false
automatic_walk := false
; Assigning the shortcut to the console key (scan code 029)
$SC029::
; Inverting the value of the automatic_walk variable
automatic_walk := !automatic_walk
; Announcing the state of the variable using speech synthesis
if (automatic_walk) {
voice.Speak("Automatic walking activated")
} else {
voice.Speak("Automatic walking deactivated")
; Sending the W key up if the variable is false
SendInput, {w up}
}
return
; Sending the W key down continuously if the variable is true
While automatic_walk{
SendInput, {w down}
}
Sleep, 100 ; Pause of 100 milliseconds to avoid slowing down the computer
When I press the designated key to toggle the script on and off, the variable changes states correctly and the script announces whether it is on or off. However, even when the variable is true, the W key is not being sent.
I'm pretty sure it's a silly mistake, but I just can't seem to find it. That's why I'm reaching out for help. Can anyone see what I'm doing wrong?
Thank you in advance for your assistance.
[Mod edit: Moved topic to AHK v1 help, based on posted code.]