如何将鼠标宏激活键从滚轮改为Scroll Lock键?
问题:如何将鼠标宏激活键从滚轮改为Scroll Lock键?
现有一段鼠标宏Lua代码,当前激活键设置为滚轮(对应变量
Macro_Activation_Key = 3),请问如何将激活键修改为Scroll Lock键?原代码如下:
local Macro_Activation_Key = 3 local function OutputLogs(s) OutputLogMessage(s.."\n") OutputDebugMessage(s.."\n") end local Recoil_Activator function OnEvent(event, arg) if (event == "PROFILE_ACTIVATED") then EnablePrimaryMouseButtonEvents(true) elseif event == "MOUSE_BUTTON_PRESSED" and arg == Macro_Activation_Key then Recoil_Activator = not Recoil_Activator OutputLogs(Recoil_Activator and "ON_Macro" or "OFF_Macro") elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and Recoil_Activator then MoveMouseRelative(2, -2) repeat MoveMouseRelative(-4, 4) Sleep(3) MoveMouseRelative(4, -4) Sleep(3) until not IsMouseButtonPressed(1) end end
解决方案
因为Scroll Lock是键盘按键,而非鼠标按钮,不能直接替换原鼠标按钮的数字值,需要调整两处核心逻辑:
- 将激活键变量改为键盘按键常量
"SCROLLLOCK" - 将监听事件从鼠标按钮按下
"MOUSE_BUTTON_PRESSED"改为键盘按键按下"KEYBOARD_PRESSED"
修改后的完整代码:
local Macro_Activation_Key = "SCROLLLOCK" local function OutputLogs(s) OutputLogMessage(s.."\n") OutputDebugMessage(s.."\n") end local Recoil_Activator function OnEvent(event, arg) if (event == "PROFILE_ACTIVATED") then EnablePrimaryMouseButtonEvents(true) elseif event == "KEYBOARD_PRESSED" and arg == Macro_Activation_Key then Recoil_Activator = not Recoil_Activator OutputLogs(Recoil_Activator and "ON_Macro" or "OFF_Macro") elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and Recoil_Activator then MoveMouseRelative(2, -2) repeat MoveMouseRelative(-4, 4) Sleep(3) MoveMouseRelative(4, -4) Sleep(3) until not IsMouseButtonPressed(1) end end
补充说明:
- 罗技G系列鼠标的Lua脚本中,键盘按键使用标准按键名作为常量,
"SCROLLLOCK"对应Scroll Lock键 - 修改后,按下Scroll Lock即可切换宏的开启/关闭状态,功能逻辑与原代码保持一致
内容的提问来源于stack exchange,提问作者Scott Smith
相关产品推荐
相关产品推荐

