I want to create a variable speed FastForward with a Hotkey sending Skips. Below test scripts explaining my problem in achieving that goal:
In the script below, when I type 3 it starts sending f at low speed, then when I press 2 I go to speed 2, then again to speed 3, then again to speed 0.
Code:
SetTitleMatchMode, 2
DetectHiddenText, On
#NoEnv
#Persistent
SendMode Input
#IfWinActive Notepad
Stop = 0
3:: FFW()
2::
Stop := stop + 1
if stop > 3
stop = 0
return
FFW()
{
Global stop = 1
Loop 400
{
SplashTextoff
SplashTextOn,200,50,Speed, %stop%
Send f
if stop = 0
break
if Stop = 1
Sleep 500
if stop = 2
sleep 150
if stop = 3
sleep 50
}
}
This is the functionnality I want, except that I would like to do that by sucessive press of the 3 key instead of using the 3 key to start and the 2 key to change speed.
press 3 starts sending f at speed 1
press 3 again, go to speed 2
press 3 again, go to speed 3
press 3 again, stop
Unfortunately, I cannot get that to work, as it seems that as long as the loop (trigerred by the 3 press) is running, It does not interpret furher key presses of 3.
I tried this without sucess:
Code:
SetTitleMatchMode, 2
DetectHiddenText, On
#NoEnv
#Persistent
SendMode Input
#IfWinActive Notepad
Stop = 0
3::
Stop := stop + 1
if stop > 3
stop = 0
FFW()
2::
stop = 0
return
FFW()
{
Global stop
Loop 400
{
SplashTextoff
SplashTextOn,200,50,Speed, %stop%
Send f
if stop = 0
break
if Stop = 1
Sleep 500
if stop = 2
sleep 150
if stop = 3
sleep 50
}
}
I also tried the script below using getkeystate, but it is unreliable as speed increases (short sleep time).
I believe because getkeystate does not listen all the time for the key press, but only during the brief instruction execution which rarely coincide with the press.
It would equire the press to be buffered, and the buffer to be read by the getkeypress.
Unreliable script:
Code:
SetTitleMatchMode, 2
DetectHiddenText, On
#NoEnv
#Persistent
SendMode Input
#IfWinActive Notepad
Stop = 0
3:: FFW()
2:: Stop = 0
return
FFW()
{
Global Stop = 1
loop 400
{
Send f
SplashTextoff
SplashTextOn,200,50,Speed, %stop%
if stop = 0
break
if Stop = 1
Sleep 500
if stop = 2
sleep 150
if stop = 3
sleep 50
if getkeystate("3", "p")
Stop := stop + 1
if stop > 3
stop = 0
}
}
I did succedd to get an acceptable working script with a loop on getkeystate and playing with timing, but it is still sensitive to how long you press the key.
So it would be better if we could use the trigger of the key rather than it state.
Somewhat working script:
Code:
SetTitleMatchMode, 2
DetectHiddenText, On
#NoEnv
#Persistent
SendMode Input
#IfWinActive Notepad
Stop = 0
3:: FFW()
2:: Stop = 0
return
FFW()
{
Global Stop = 1
Loop 400
{
Send f
if stop = 0
break
if Stop = 1
{
Sleep 250
loop 2
{
if getkeystate("3", "p")
Stop := stop + 1
if stop > 3
stop = 0
sleep 200
SplashTextOn,200,50,Speed, %stop%
}
}
if stop = 2
loop 1
{
if getkeystate("3", "p")
Stop := stop + 1
if stop > 3
stop = 0
sleep 200
SplashTextOn,200,50,Speed, %stop%
}
if stop = 3
{
if getkeystate("3", "p")
Stop := stop + 1
if stop > 3
stop = 0
sleep 50
SplashTextOn,200,50,Speed, %stop%
}
}
}
Welcoming any suggestions

Code: