Question

So I need the current script below, to be able to toggle.

At the moment, the script only work when holding down the F8 key... which defeats the point of a afk script. lol

Anyhow, here's the script:

$F8::  
Loop
{
    if not GetKeyState("F8", "P")
        break  
    Click right
    Click
    Send {Numpad7 down}
    Send {Numpad7 up}
}
return

Would anyone be able to turn this into a toggle please? Any help is much appreciated!

Was it helpful?

Solution

Your attempt using a toggle variable (as per the code from your comment) is the right approach, but there are few things missing:

  1. Always initialize a toggle variable. Otherwise, how can you be sure what Toggle := !Toggle does with an unitialized Toggle? It could be true or false; most compilers wouldn't even allow it.
  2. I always recommend using timers when possible, especially for recurring tasks, that potentially get repeated very often.
  3. It is rarely neccessary to fire key sequences in maximum speed. The speed admittedly is effectively regulated by SetBatchLines and SetKeyDelay. But at the latest when those delays are reduced, the send speed could not only be overkill, but also affect the target application or even your system performance. That's why Sleep or SetTimer with an adequate delay should be used.

Here's an untested suggestion:

toggle := false
$F8::
    if(toggle) {
        toggle := false
        SetTimer, SendSomething, Off
    } else {
        toggle := true
        ; Choose a delay here!
        SetTimer, SendSomething, 100
    }
return

SendSomething:
    Click right
    Click
    Send {Numpad7}
return
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top