EnablePrimaryMouseButtonEvents(true) -- 启用鼠标事件
local all_button = 9  -- 定义开关按钮
local is_open_up = false -- 启开关,默认关闭
function OnEvent(event, arg)
    OutputLogMessage('Event: '..event..', Arg: '..arg..'\n')
    -- 切换开关
    if (event == "MOUSE_BUTTON_PRESSED" and arg == all_button) then
        is_open_up = not is_open_up
        if is_open_up then
            OutputLogMessage("开 on \n")
            OutputLogMessage("关 off \n")
    -- 侧键5被按下且开关开启时,进入节奏循环,模拟按下 F8
    if (is_open_up and IsMouseButtonPressed(5)) then
        OutputLogMessage("进入节奏 (F8)\n")
        repeat
            PressKey("f8") -- 模拟按下 F8 键
            Sleep(math.random(15, 20)) -- 按下的延迟
            ReleaseKey("f8") -- 模拟松开 F8 键
            Sleep(math.random(40, 60)) -- 间隔时间
        until not IsMouseButtonPressed(5) -- 侧键5松开时结束循环
        OutputLogMessage("进入节奏终止 (F8)\n")
    -- 侧键4被按下且开关开启时,进入节奏循环,模拟按下 F9
    if (is_open_up and IsMouseButtonPressed(4)) then
        OutputLogMessage("进入节奏 (F9)\n")
        repeat
            PressKey("f9") -- 模拟按下 F9 键
            Sleep(math.random(15, 20)) -- 按下的延迟
            ReleaseKey("f9") -- 模拟松开 F9 键
            Sleep(math.random(40, 60)) -- 间隔时间
        until not IsMouseButtonPressed(4) -- 侧键4松开时结束循环
        OutputLogMessage("进入节奏终止 (F9)\n")

该项目持续更新 在github gitee
gitee地址

当然罗技键盘我也写了发下代码用ALT 退出循环

EnablePrimaryMouseButtonEvents(true) -- 启用鼠标事件
local all_button = 3  -- 定义开关按钮
local is_open_up = false -- 启开关,默认关闭
function OnEvent(event, arg)
    OutputLogMessage('Event: '..event..', Arg: '..arg..'\n')
    -- 切换开关
    if (event == "G_PRESSED" and arg == all_button) then
        is_open_up = not is_open_up
        if is_open_up then
            OutputLogMessage("开 on \n")
            OutputLogMessage("关 off \n")
    -- 侧键5被按下且开关开启时,进入节奏循环,模拟按下 F8
    if (is_open_up and event == "G_PRESSED" and arg ==1) then
        OutputLogMessage("进入节奏 (F8)\n")
        repeat
            PressKey("f8") -- 模拟按下 F8 键
            Sleep(math.random(15, 20)) -- 按下的延迟
            ReleaseKey("f8") -- 模拟松开 F8 键
            Sleep(math.random(40, 60)) -- 间隔时间
        until IsModifierPressed("alt")-- 侧键5松开时结束循环
        OutputLogMessage("进入节奏终止 (F8)\n")
    -- 侧键4被按下且开关开启时,进入节奏循环,模拟按下 F9
    if (is_open_up and event == "G_PRESSED" and arg ==2) then	
        OutputLogMessage("进入节奏 (F9)\n")
        repeat
            PressKey("f9") -- 模拟按下 F9 键
            Sleep(math.random(15, 20)) -- 按下的延迟
            ReleaseKey("f9") -- 模拟松开 F9 键
            Sleep(math.random(40, 60)) -- 间隔时间
        until IsModifierPressed("alt") -- 侧键4松开时结束循环
        OutputLogMessage("进入节奏终止 (F9)\n")

年底我会出罗技教程

以前玩暗黑破坏神3,为了不至于断手,尝试了一下网络上提供的lua脚本,但全部使用的是死循环,消息被阻塞,而且创建新的职业脚本很麻烦,所以,尝试了这个框架,代码中的实际样例是用于猎魔人的多重射击,有兴趣的可以自行修改用于其他职业,严重缺CSDN积分,如果要转载到其他地方发布,请联系我。 里面的用法注释很详细,至于框架部分,不明白的不要修改。