The problem can be divided into 2 smaller ones:
ReleaseMouseButton(3) is called before the corresponding bullet is fired in the game (thus now I have coded 30 bullets, and it completes execution in the first two or three). I decided to increase the delay through Sleep(50), this gave the expected effect, albeit a weak one, but this is also not an option. there is a much shorter time interval between bullets.
Each mouse shift works in such a way that the previous one breaks. For example, let's call:
MoveMouseRelative(0, 0)
Sleep(10)
MoveMouseRelative(0, 15)
Sleep(10)
MoveMouseRelative(0, 5)
For some reason, the third affects the second, and the second affects the first, so I have to adjust all the offsets when adding a new one, and this is a very boring thing and definitely should not work like that.
Functions like EnablePrimaryMouseButtonEvents can be viewed in pdf logitech g-series lua api https://douile.com/logitech-toggle-keys/APIDocs.pdf
Whole code:
function OnEvent(event, arg)
EnablePrimaryMouseButtonEvents(true);
if IsMouseButtonPressed(3) then
repeat
MoveMouseRelative(0.15)
Sleep(50)
MoveMouseRelative(0,40)
Sleep(50)
MoveMouseRelative(0,30)
Sleep(90)
--MoveMouseRelative(0.9)
Sleep(100)
--MoveMouseRelative(0.7) -- 5
Sleep(10)
if not IsMouseButtonPressed(3) then break end
--[[MoveMouseRelative(0,6)
Sleep(10)
MoveMouseRelative(0.6)
Sleep(10)
MoveMouseRelative(0.6)
Sleep(10)
MoveMouseRelative(0.6)
Sleep(10)
MoveMouseRelative(0,6) -- 10
Sleep(10)
if not IsMouseButtonPressed(3) then break end
MoveMouseRelative(0.6)
Sleep(10)
MoveMouseRelative(0.7)
Sleep(10)
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0,7) -- 15
Sleep(15)
if not IsMouseButtonPressed(3) then break end
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0,7) -- 20
Sleep(15)
if not IsMouseButtonPressed(3) then break end
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0,7) -- 25
Sleep(15)
if not IsMouseButtonPressed(3) then break end
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0.7)
Sleep(15)
MoveMouseRelative(0,7) -- 30
Sleep(15)]]--
ReleaseMouseButton(3)
--OutputLogMessage("Repeat")
until not IsMouseButtonPressed(3) -- btn#4 is bound to btn#10
--OutputLogMessage("Stop")
end
end
The function mentioned by Luke in comments might look like the following:
local last_x, last_y
function SetOrigin()
last_x, last_y = 0, 0
end
function SmoothMouseMoveRelativeToOrigin(x, y, ms)
last_x, last_y, x, y = x, y, x - last_x, y - last_y
local tm = GetRunningTime()
local prev_dx, prev_dy = 0, 0
repeat
Sleep(10)
local t = GetRunningTime() - tm
local dt = math.min(ms, t) / ms
local dx = math.floor(dt * x + 0.5)
local dy = math.floor(dt * y + 0.5)
prev_dx, prev_dy, dx, dy = dx, dy, dx - prev_dx, dy - prev_dy
if dx ~= 0 or dy ~= 0 then
MouseMoveRelative(dx, dy)
end
until t >= ms
end
function OnEvent(event, arg)
SetOrigin()
....
repeat
SmoothMouseMoveRelativeToOrigin(0, 15, 50) -- after 50 ms: at (0, 15)
SmoothMouseMoveRelativeToOrigin(0, 20, 40) -- after 50+40 ms: at (0, 20), not (0, 35)
....
end