I pieced together a script that should allow attacks with the right mouse button to work and while the button is held use randomly the numbers 1, 2 , 3, 4, and 5. The script works fine if i set it to be activated with a button, say "e", but when i change it to Rbutton it works once and stops.
I tried while (getKeyState("rbutton", "P")) (from https://www.autohotkey.com/boards/viewtopic.php?t=11952&p=85752), i tried toggle, and i tried HoldRightClick := true. They either do not work or still work once.
How do i make the script work while the button is held?
This is the script:
Code: Select all
~RButton:: ; I want the right mouse button to be active
HoldRightClick := true
KeyWait, RButton, T1 ; if the right mouse button is held for more than a second then do if
Sleep, %Delay% ; I want the rest of the script to work after some delay. Maybe this is overkill?
if (ErrorLevel) ; this whole part is supposed to press the five numbers randomly with random delays
{
Vari := "1,2,3,4,5"
Sort, Vari, Random D,
VariArray := StrSplit(Vari, ",")
Loop % VariArray.MaxIndex()
{
ThisVari := VariArray[A_Index]
SendInput, %ThisVari%
Random, Delay, 80, 200
Sleep, %Delay%
}
Sleep, % ran(3000,4000) ; those numbers should appear only after every 3 to 4 seconds
return
ran(min, max)
{
random, ran, min, max
return ran
}
}
else ; in case the button is only pressed instead of held then do a normal mouse click. This way i dont have to press another button to activate/deactivate the script.
Send {RButton}
Return