Yingg
Yingg

Reputation: 1

What can I do to stop running the script when I release the left button?

enter image description here

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
    if IsKeyLockOn("capslock") and IsMouseButtonPressed(1) and IsMouseButtonPressed(3) then
        repeat
            PressMouseButton(1)
   Sleep(13)
   ReleaseMouseButton(1)
   Sleep(15)
   PressMouseButton(1)
   Sleep(18)
   ReleaseMouseButton(1)
   Sleep(12)
   PressMouseButton(1)
   Sleep(14)
   ReleaseMouseButton(1)
   Sleep(16)
        until not IsMouseButtonPressed(3)
    end
end

Upvotes: -1

Views: 99

Answers (1)

ESkri
ESkri

Reputation: 1928

The problem is: you cannot both simulate a mouse button press/release and monitor the same mouse button state (pressed/released) simultaneously.

To solve the problem you may:

  • either change the physical button (rapid-fire by another mouse button instead of LMB)
  • or change the simulated button (introduce alternative button for shoot in the game).

This answer describes how to implement the second option.
You need to satisfy all 3 steps:

  1. In the game, in the "Controls Settings", introduce alternative key for "Shoot" action.
    (I assume your game allows binding two different keys for the same action)
    For example, let it be keyboard key P.
    So, now in the game you can shoot either using Left Mouse Button or using Keyboard key P.
    Of course, you will use LMB for manual shooting as usually, but your LGS/GHub script will use P.

  2. Try to play the game with both LMB and P for shooting.
    Make sure you can shoot with P key while keeping LMB pressed.
    (Some games do not allow this)

  3. The script

EnablePrimaryMouseButtonEvents(true)

function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 1
      and IsKeyLockOn("capslock") and IsMouseButtonPressed(3)
   then
      repeat
         Sleep(math.random(10,30))
         PressKey("P")
         Sleep(math.random(10,30))
         ReleaseKey("P")
      until not (IsMouseButtonPressed(1) and IsMouseButtonPressed(3))
   end
end            

Upvotes: -1

Related Questions