I need to add to my scripts below a toggle on/off. I want the script to be "on" when I press "3" key and to be "off" when I press "4" in first script and "5" is on, "6" is off for the second script. Now it is only starting to work when I press "a" and "j" and doesn't have any toggle off.
Hi Vosined. I understand that the toggle function is not working properly. The script I wrote before allows to toggle with only one button. You want to use two buttons, the first is on and the second is off.
I rewrote the script with one toggle button to work a bit different. Now the script below should be more reliable.
Code: Select all
$a::
If ToggleVar
{
ToggleVar := 0
Return
}
ToggleVar := 1
SetTimer, LoopAButton, -1 ; Start a new thread which runs the loop under "LoopAButton:".
Return
LoopAButton:
While ToggleVar {
SendInput, {a Down}
Sleep, 30000000
}
Return
$j::
If ToggleVar2
{
ToggleVar2 := 0
Return
}
ToggleVar2 := 1
SetTimer, SpamJ, -1 ; Start a new thread which runs the loop under "LoopAButton:".
return
SpamJ:
While ToggleVar2 {
Sendinput, {j Up}
Sleep, 100
SendInput, {j Down}
Sleep, 100
}
Return
Though you asked to use separate buttons for off and on. This script should provide that.
Code: Select all
3::
ToggleVar := 1
While ToggleVar {
SendInput, {a Down}
Sleep, 30000000
}
return
4::
ToggleVar := 0
Return
5::
ToggleVar2 := 1
While ToggleVar2 {
Sendinput, {j Up}
Sleep, 100
SendInput, {j Down}
Sleep, 100
}
return
6::
ToggleVar2 := 0
Return
Both scripts do not run the two While-loops together. So when J is being spammed, A cannot be send and vice versa. If this is realy necessary it is possible.