Question

I wrote a script that sends autofire left clicks and can be triggered on and off. The script works. However, the problem is that holding the right mouse button does not work properly anymore because the left click keeps getting sent. So I want to change the script that it gets temporarily paused while I hold down the right mouse button.

How would I go about doing this? Here is my current code:

#MaxThreadsPerHotkey 3
   #z::
#MaxThreadsPerHotkey 1

if keep_winz_running = y

{
     keep_winz_running = n
     return
    }

; Otherwise:

keep_winz_running = y

Loop
{
GetKeyState, rbut, Rbutton
If rbut, = U 
{ 
Loop, 

{ 

    MouseClick, left 

    Sleep, 50 ;This means the script will wait 1.5 secs 

     if keep_winz_running = n  ; The user signaled the loop to stop.

        break  ; break out of the loop

}
Was it helpful?

Solution

Timers are the best!

sendToggle := false

#z::
    if(!sendToggle) {
        sendToggle := true
        SetTimer, SendClick, 100
    } else {
        sendToggle := false
        SetTimer, SendClick, Off
    }
return

#If sendToggle
RButton::
    SetTimer, SendClick, Off
    KeyWait, RButton
    SetTimer, SendClick, 100
return

SendClick:
    Click
return

I find the send interval of 50 ms awfully fast, especially since you won't be able to actually reach 50 ms without reducing SetBatchLines and SetKeyDelay. If it really needs to be that fast, consider changing them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top