Ok, you are talking to the right person, here. Some games need a delay during the keypress - In other words,
a delay AFTER the key is DOWN and BEFORE the key is RELEASED. The game I have been working on, seemed to need
a delay of 37 for holding a key down, and a delay of 2 between keypresses. So this should work with sendplay...
Code:
playkeydelay:=37
setkeydelay,,%playkeydelay%,play
F1::
sendplay {Enter 50}
return
But in my opinion, this is a much better way. I have put it in a function so that it is easy to use for any keypress.
You can experiment with changing the delays, but this is what I found was the fastest without any errors or skips.
Code:
delaybetweenfkeys:=2
fkeydowndelay:=37
F1::
loop 50
{
presskey("Enter")
}
return
presskey(key,del1 =999999, del2 =999999) ;you cant set variables as default parameters in functions
{ ; so this is a way around it
global delaybetweenfkeys,fkeydowndelay
del1:=del1=999999 ? fkeydowndelay : del1 ;default value will be value of 'fkeydowndelay'
del2:=del2=999999 ? delaybetweenfkeys : del2 ;default value will be value of 'delaybetweenfkeys'
sendinput {%key% down} ;press the key down
sleep %del1% ;hold for this delay
sendinput {%key% up} ;release key
sleep %del2% ; for this delay
return
}
Even better (depending on what you want) - this will continue pressing enter until you release F1.
Code:
delaybetweenfkeys:=2
fkeydowndelay:=37
F1::
loop
{
if checkkeyreleased(A_thishotkey) ; a_thishotkey is a built in variable
break ; that stores whatever the last key pressed was
presskey("Enter") ; which of course will be F1
}
return
presskey(key,del1 =999999, del2 =999999) ;you cant set variables as default parameters in functions
{ ; so this is a way around it
global delaybetweenfkeys,fkeydowndelay
del1:=del1=999999 ? fkeydowndelay : del1 ;default value will be value of 'fkeydowndelay'
del2:=del2=999999 ? delaybetweenfkeys : del2 ;default value will be value of 'delaybetweenfkeys'
sendinput {%key% down} ;press the key down
sleep %del1% ;hold for this delay
sendinput {%key% up} ;release key
sleep %del2% ; for this delay
return
}
checkkeyreleased(key,checkdelay =2)
{
Sleep, %checkdelay% ;tiny delay to give computer a chance to see if key is down
GetKeyState, state, %key%, P ;stores the state of the key to variable 'state'
if state = U ; The key has been released, so break out of the loop.
return true
else
return false
}