2
votes

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!

1
If you want the script to run automatically, why did you write a script that does the opposite? What were your attempts to write a script that actually does what you want?MCL
I never made that script. It was made by a friend, that isn't able to get access to his PC anymore. So I just need it changing to a 'toggle' however still retaining what it already does. If that make sense.user3389810
What were your attempts to write a script that actually does what you want?MCL
I tried the following: pastebin.com/1ewY3HpM But that doesn't right click then left click, it just spams left click... really fast :/user3389810

1 Answers

6
votes

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