Page 1 of 1

Possible to set controllable delay between actions?

Posted: 08 Dec 2017, 14:58
by plookey78
Hi everyone, complete noob here.
I need to know is it possible to do something like, press any key to increase/decrease delay of time between w and a by fixed amount/percentage when script is running, for example:

$w::
While GetKeyState("w","P")
{
Send, {w}{a}
Sleep, 100 ;(need to increase and decrease this value by pressing a different hotkeys)
}
Return

If not then i would like to know if its possible to achieve something like this in a different way.

Re: Possible to set controllable delay between actions?

Posted: 08 Dec 2017, 15:31
by boiler
Just replace the 100 with a variable, then use hotkeys to increase/decrease the value of that variable.

Re: Possible to set controllable delay between actions?

Posted: 08 Dec 2017, 17:43
by plookey78
boiler wrote:Just replace the 100 with a variable, then use hotkeys to increase/decrease the value of that variable.
Thx but i need more help then that. I couldnt find any short guide on how to set the variables like i did with my original script i posted and i dont really have time to study all the docs rn so can anyone can help or point me at the right direction on how to do this more easily?
Btw i need controllable delay only after {a} and {w} but not {w} and {a} for it to be percentage based.

Re: Possible to set controllable delay between actions?

Posted: 08 Dec 2017, 18:21
by boiler
I don't understand this:
plookey78 wrote:Btw i need controllable delay only after {a} and {w} but not {w} and {a} for it to be percentage based.
After a and w but not after w and a? But you only output w and a (you don't need the braces around them, btw). And what do you mean by "for it to be percentage based"?

It's sounding like you're asking for someone to write a script that's getting more and more complicated, when you originally said all you wanted was to know if it was possible as if you would figure it out once you knew that it could be done.

Re: Possible to set controllable delay between actions?

Posted: 08 Dec 2017, 18:46
by plookey78
I wasnt specific at first, thought i would figure it out after getting to know the basics. Well i think i make some progress on setting the values on my script but its still not working so anyone could tell me whats wrong on the script i posted bellow? And by percentage based i mean that i need to add and subtract the percentage values of the original value, like var1:= var1 + 100% instead of var1:= var1 + 100
$w::
While GetKeyState("w","P")
{
Send, {w}{a}
sleep, var1:= 2000
}
$n::
While GetKeyState("n","P")
{
var1:= var1 - 100
}
$m::
While GetKeyState("m","P")
{
var1:= var1 + 100
}

Return

Re: Possible to set controllable delay between actions?

Posted: 08 Dec 2017, 18:47
by plookey78
double post, not sure how to delete this..

Re: Possible to set controllable delay between actions?  Topic is solved

Posted: 08 Dec 2017, 19:22
by boiler
A few things:

Like I said, you don't need braces around the w and the a. Those are for named keys like {Tab} and {Enter}, not letter keys.

The $ isn't needed before a hotkey that doesn't send characters. That's so a hotkey doesn't call itself. You can remove it from the m and the n.

Get rid of the ":= 2000" where you have it. That would always make it 2000. You want it to be changed. Put var1 := 2000 at the top of your script before anything else to set its initial value.

The While GetKeyState isn't needed for typical hotkeys. That's for when you want that loop to repeat until you release the key.

You need return statements to mark the end of multi-line hotkeys (but not single line hotkeys).

To change a value of a variable by a percentage, you just multiply it by a number, not add a number to it, just like in normal math. To make a variable half of what it is, you say Var1 := Var1 * 0.5, or Var1 *= 0.5 for short. To increase it by 100%, you multiply it by 2.

Try this:

Code: Select all

Var1 := 2000
return

$w::
    While GetKeyState("w", "P")
    {
        Send, wa
        Sleep, Var1
    }
return

n::Var1 *= 0.5

m::Var1 *= 2

Re: Possible to set controllable delay between actions?

Posted: 08 Dec 2017, 19:50
by plookey78
That works nicely, thanks.