为何所有鼠标按键均可调节vertical_speed,而非仅按键9?
Lua脚本问题修复:仅鼠标按键9调节vertical_speed
问题原因
你的脚本逻辑存在结构错误:Shift和Alt的参数调节分支没有嵌套在「鼠标按键9按下」的判断条件内。当ScrollLock开启时,只要触发任意鼠标按键按下事件,即使不是按键9,代码也会执行后续的Shift/Alt判断,导致所有鼠标按键都能修改vertical_speed。
修复后的代码
local vertical_speed = 1 function OnEvent(event, arg) if IsKeyLockOn("scrolllock") then EnablePrimaryMouseButtonEvents(true) if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsMouseButtonPressed(3) then local frac, x, y = 0, 2 repeat Sleep(10) x, y, frac = -x, math.modf(frac + vertical_speed) MoveMouseRelative(x * 2, y) until x > 0 and not IsMouseButtonPressed(1) end if event == "MOUSE_BUTTON_PRESSED" and arg == 9 then if IsModifierPressed("lshift") then vertical_speed = vertical_speed + 1 elseif IsModifierPressed("lalt") then vertical_speed = 1 end end end end
修改说明
将Shift和Alt的状态判断代码移至if event == "MOUSE_BUTTON_PRESSED" and arg == 9 then的代码块内部,确保只有按下鼠标按键9时,才会根据Shift/Alt的按住状态调整vertical_speed参数。
内容的提问来源于stack exchange,提问作者AXIOM
相关产品推荐
相关产品推荐

