Trying to keep rbutton pressed Topic is solved

Ask gaming related questions (AHK v1.1 and older)
ruguipi2
Posts: 2
Joined: 04 May 2021, 19:52

Trying to keep rbutton pressed

Post by ruguipi2 » 05 May 2021, 06:44

Hi everyone,

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 

Rohwedder
Posts: 7615
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Trying to keep rbutton pressed  Topic is solved

Post by Rohwedder » 05 May 2021, 09:02

Hallo,
try:

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?
While, GetKeyState("RButton","P") ; 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
}

ruguipi2
Posts: 2
Joined: 04 May 2021, 19:52

Re: Trying to keep rbutton pressed

Post by ruguipi2 » 05 May 2021, 10:02

Cool, it works now. Thank you very much.

Post Reply

Return to “Gaming Help (v1)”