Reputation: 21
I was wondering if there was a way to write a AHK Script to Double-Click the left mouse button every random number of Left Clicks (Randomly Double-Click Every Couple Clicks)
Upvotes: 1
Views: 986
Reputation: 2344
From the docs, we have the Random
function that
Generates a pseudo-random number.
Using the syntax
Random, OutputVar , Min, Max
Where OutputVar
is the output variable, Min
is the minimum value (inclusive), and Man
is the manimum value (inclusive).
With this information, let's make a subroutine called generateNewRandom
that we can call every time every time we want to regenerate our random number.
For this example, I will set the Min
to 1 and the Max
to 10 so that a random number between [1, 10]
inclusive is generated. You can change these values as needed.
We will save the output of the Random
function into a variable named NumClicks
.
Next, let's create a hotkey that will trigger every time the Left Mouse Button is clicked.
However, this hotkey will require several various modifiers (namely: *, ~, and $) in order to function properly. You can find out more about them in the docs.
In short:
Send
itself without causing an infinite loop.For the hotkey itself, when LButton (The Left Mouse Button) is pressed, do the following:
numClicks
is 0
In addition to the Subroutine and the Hotkey, we will need to call the subroutine once in the auto-execute section at the beginning in order to generate an initial random value.
gosub generateNewRandom ;Generate initial random number
*~$LButton::
numClicks--
if(numClicks==0){
Click
gosub generateNewRandom ;Generate subsequent random numbers
}
return
generateNewRandom:
Random, numClicks , 1, 10 ;Adjust these values as needed
return
Upvotes: 1