So, I've written this code for the video game "The Witcher 3 Wild Hunt" to roam through the virtual world with my hand off the keyboard. W is for moving forward in the game and LShift is for sprinting. As you can see in the code, it needs to be double-pressed sometimes. In the case where LShift doesn't need to be double-pressed and even with the additional lines removed In the script, the issue persists. I do reload the script every time I made changes.
Code: Select all
; Variables
sprinting := 0
; Triggers
*CapsLock::
if(!GetKeyState("LShift"))
{
sprinting := 1
if(!GetKeyState("W", "P"))
SendInput, {W down}
SendInput, {LShift down}
Sleep, 25
SendInput, {LShift up}
Sleep, 25
SendInput, {LShift down}
}
else
{
sprinting := 0
if(!GetKeyState("W", "P"))
SendInput, {W up}
SendInput, {LShift up}
}
return
; Handlers
~W::
if(sprinting)
{
SendInput, {LShift down}
Sleep, 25
SendInput, {LShift up}
Sleep, 25
SendInput, {LShift down}
}
return
1. AUTO: If I'm not moving forward myself, it'll do that for me.
2. MANUAL: If I want full directional control, I hold down W during the toggle, and it'll just do the sprinting.
The handler is working as intended (if I stop at some point and then go on, I will be sprinting again).
BUT:
If I stop and go while in the sprinting mode, meaning that, however I started, I'm now in MANUAL, it always takes two presses on the toggle button (CapsLock) to turn off sprinting, unless I stopped first.
The same exact thing happens, if I replace "!GetKeyState("LShift")" with "!sprinting" in the first if-statement.
I did at some point have two triggers. They looked like this:
Code: Select all
; Triggers
*CapsLock::
if(!GetKeyState("LShift"))
{
sprinting := 1
SendInput, {W down}{LShift down}
Sleep, 25
SendInput, {LShift up}
Sleep, 25
SendInput, {LShift down}
}
else
{
sprinting := 0
SendInput, {W up}{LShift up}
}
return
~W & CapsLock::
if(!GetKeyState("LShift"))
{
sprinting := 1
SendInput, {LShift down}
Sleep, 25
SendInput, {LShift up}
Sleep, 25
SendInput, {LShift down}
}
else
{
sprinting := 0
SendInput, {LShift up}
}
What are your suggestions?