我试图让下面的代码仅在按下或按住鼠标按钮1时执行一次MoveMouseRelative函数。我尝试删除“重复”行,但它破坏了代码。当前,当激活并按住鼠标1时,光标会不断向下拖动。
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(2) -- to prevent it from being stuck on
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
recoilx2 = not recoilx2
spot = not spot
end
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoilx2) then
if recoilx2 then
repeat
--Sleep(35)
Sleep(5)
MoveMouseRelative(0, 3)
until not IsMouseButtonPressed(1)
end
end
目标:Logitech鼠标的Lua脚本,它执行以下任务:当鼠标按钮5被“激活”时:-每1000毫秒单击一次(两次拍摄之间的时间),-并且每1000毫秒将鼠标拉下一次。因此,如果我按住鼠标左键,它将连续拍摄,但只有在拍摄时才向下拉
选择您在游戏中从未使用过的键盘按钮,并将其设置为发射手枪的替代方法。它将用于以编程方式触发。我假设键是P,但是您可以选择任何其他按钮:“ f12”,“ backspace”,“ num9”,...
local alternative_fire_button = "P"
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if (event == "PROFILE_ACTIVATED") then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
-- to prevent mouse buttons from being stuck on
for j = 1, 5 do ReleaseMouseButton(j) end
end
if event == "MOUSE_BUTTON_PRESSED" and arg == 5 then
recoilx2 = not recoilx2
end
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoilx2 then
if recoilx2 then
Sleep(20)
while IsMouseButtonPressed(1) do
MoveMouseRelative(0, 25)
local next_shot_time = GetRunningTime() + 1000
local LMB
repeat
Sleep(50)
LMB = IsMouseButtonPressed(1)
until not LMB or GetRunningTime() >= next_shot_time
if LMB then
PressKey(alternative_fire_button)
Sleep(50)
ReleaseKey(alternative_fire_button)
end
end
end
end
end