LGS Lua脚本修改需求:将鼠标侧键5的切换模式改为按住触发
解决LGS Lua脚本按键5改为按住触发模式的问题
需求说明
将鼠标前进侧键(按键5)从切换激活/关闭模式改为按住时生效、松开即关闭的触发模式。
修改后的完整脚本
Offset = 4 Offset_random = 0 Btn_main_switch = 5 Btn_recoil_switch = 4 EnablePrimaryMouseButtonEvents(true) Is_ads = 0 Enabled = 0 Recoil = 0 Jitter_max = Offset + Offset_random Jitter_min = Offset - Offset_random function OnEvent(event, arg) ClearLog() OutputLogMessage("Current settings:\n\nJitter = %d\nRecoil = %d\n", Enabled, Recoil) local recovery_offset local downcount local jitter if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and Is_ads == 1 and Enabled == 1) then downcount = 0 repeat downcount = downcount + 1 if (downcount <= 150 and Recoil == 1) then MoveMouseRelative(0, 1) end jitter = math.random(Jitter_min, Jitter_max) recovery_offset = -jitter Sleep(2) MoveMouseRelative(jitter, jitter) Sleep(2) MoveMouseRelative(recovery_offset, recovery_offset) until not IsMouseButtonPressed(1) end -- 修改按键5为按住触发:按下时启用,松开时关闭 if (event == "MOUSE_BUTTON_PRESSED" and arg == Btn_main_switch) then Enabled = 1 end if (event == "MOUSE_BUTTON_RELEASED" and arg == Btn_main_switch) then Enabled = 0 end if (event == "MOUSE_BUTTON_PRESSED" and arg == Btn_recoil_switch) then if (Recoil == 0) then Recoil = 1 else Recoil = 0 end end if (event == "MOUSE_BUTTON_PRESSED" and arg == 2) then Is_ads = 1 end if (event == "MOUSE_BUTTON_RELEASED" and arg == 2) then Is_ads = 0 end end
关键修改点
- 删除原脚本中按键5的状态反转逻辑(按下时切换Enabled值)
- 新增按键5的释放事件处理:松开按键5时直接将
Enabled设为0 - 调整按键5的按下事件处理:按下时直接将
Enabled设为1,不再做状态切换
修改后,只有按住按键5期间,Enabled会保持1,主功能(抖动和后座控制)才能触发;松开按键5后,Enabled立即重置为0,功能停止。
内容的提问来源于stack exchange,提问作者Zai
相关产品推荐
相关产品推荐

