EnablePrimaryMouseButtonEvents(true)
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsMouseButtonPressed(3) and IsKeyLockOn("numlock") then
-- first group of moves: 10 steps in direction (-1,13), total group time = 750 ms
for i = 1, 10 do
MoveMouseRelative(-1,13)
Sleep(75)
if not IsMouseButtonPressed(1) then return end
end
-- second group of moves: 5 steps in direction (1,12), total group time = 375 ms
for i = 1, 5 do
MoveMouseRelative(1,12)
Sleep(75)
if not IsMouseButtonPressed(1) then return end
end
-- you can add more groups
end
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsMouseButtonPressed(3) and IsKeyLockOn("scrolllock") then
-- first group of moves: 10 steps in direction (-1,13), total group time = 750 ms
for i = 1, 10 do
MoveMouseRelative(-1,13)
Sleep(75)
if not IsMouseButtonPressed(1) then return end
end
-- second group of moves: 5 steps in direction (1,12), total group time = 375 ms
for i = 1, 5 do
MoveMouseRelative(1,12)
Sleep(75)
if not IsMouseButtonPressed(1) then return end
end
-- you can add more groups
end
end
UPDATE:
Step 0.
You are about to modify the behavior of Left Mouse Button.
This is a potentially dangerous operation: you can do almost nothing on your computer without LMB.
So you must create a "spare LMB".
For example, if you don't use Mouse Button 8, you can make it acting like a clone on LMB.
Go to the big mouse picture in LGS and assign command "Left Click" to your physical MB#8.
Now, if something goes wrong and your LMB stops working, you can press MB#8 instead of LMB.
Step 1.
Do you use Mouse Button 4 ("Back") in the game?
- If YES (some action is set to MB#4 in the game), proceed to "Step 2".
- If NO (the game ignores MB#4 press), skip "Step 2" and proceed to "Step 3".
Step 2.
You have to remap game action from MB#4 to some other key.
Do the following:
- choose keyboard key you don't currently use in the game
(let's assume the F12
key is not currently used)
- go to the big mouse picture in LGS and assign command
F12
to your physical MB#4
- go to your game settings and set the game action to
F12
instead of MB#4
As a result, when you press physical MB#4, the game receives F12
and activates the game action.
Now skip "Step 3" and proceed to "Step 4".
Step 3.
Go to the big mouse picture in LGS.
Unassign standard command "Back" from physical MB#4 (select "Unassign" from the drop-down menu).
Step 4.
Set the script (see below).
Step 5.
Go to the big mouse picture in LGS.
Assign command "Back" to your physical LMB.
You will see a warning about a potentially dangerous operation.
Allow this operation because you have the "spare LMB" if something goes wrong.
-- rapid fire (CAPSLOCK) is independent from anti-recoil (NUMLOCK and SCROLLLOCK)
local rapid_fire_interval = 30 -- milliseconds between LMB press/release simulation
local LMB_down, rapid_fire, prev_time, next_LMB_time
local function PressOrReleaseLMB(only_release)
if LMB_down then
ReleaseMouseButton(1)
LMB_down = false
elseif not only_release then
PressMouseButton(1)
LMB_down = true
end
end
local function Sleep_with_rapid_fire(ms)
-- returns true if LMB was released by user
prev_time = prev_time + ms
while GetRunningTime() < prev_time do
Sleep(10)
if not IsMouseButtonPressed(4) then
return true
end
while rapid_fire and GetRunningTime() >= next_LMB_time then
next_LMB_time = next_LMB_time + rapid_fire_interval
PressOrReleaseLMB() -- press LMB (if it's up) or release LMB (if it's down)
end
end
end
function OnEvent(event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" or event == "MOUSE_BUTTON_RELEASED" and arg == 1 then
PressOrReleaseLMB(true) -- release LMB
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
PressOrReleaseLMB() -- press LMB
prev_time = GetRunningTime()
next_LMB_time = prev_time + rapid_fire_interval
rapid_fire = IsKeyLockOn("capslock")
if IsMouseButtonPressed(3) then -- RMB pressed
if IsKeyLockOn("numlock") then
-- first group of moves: 10 steps in direction (-1,13), total group time = 750 ms
for i = 1, 10 do
MoveMouseRelative(-1,13)
if Sleep_with_rapid_fire(75) then return end
end
-- second group of moves: 5 steps in direction (1,12), total group time = 375 ms
for i = 1, 5 do
MoveMouseRelative(1,12)
if Sleep_with_rapid_fire(75) then return end
end
-- you can add more groups
elseif IsKeyLockOn("scrolllock") then
-- first group of moves: 10 steps in direction (-1,13), total group time = 750 ms
for i = 1, 10 do
MoveMouseRelative(-1,13)
if Sleep_with_rapid_fire(75) then return end
end
-- second group of moves: 5 steps in direction (1,12), total group time = 375 ms
for i = 1, 5 do
MoveMouseRelative(1,12)
if Sleep_with_rapid_fire(75) then return end
end
-- you can add more groups
end
end
Sleep_with_rapid_fire(math.huge) -- until user released LMB
end
end