【问题标题】:Logitech LUA script adding sleep timer罗技 LUA 脚本添加睡眠定时器
【发布时间】:2021-08-13 06:08:22
【问题描述】:

想知道如何将睡眠计时器添加到我的 LUA 脚本中,这样它就不会尽可能快地持续循环并按 0x29,我想这样做,所以当我按下鼠标上的按钮 1 和 3 时它会命中每 3-4 秒键入一次 0x29,而不是尽可能快。

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
    if event == "MOUSE_BUTTON_PRESSED" then
        if (arg == 1 or arg == 2) then
            mb1 = IsMouseButtonPressed(1);
            mb2 = IsMouseButtonPressed(3);
            --OutputLogMessage(tostring(mb1) .. " - " .. tostring(mb2));
            if (mb1 == true and mb2 == true) then
                PressAndReleaseKey(0x29);
            end
        end
    end
end

【问题讨论】:

  • 您的脚本模拟按键 0x29 每次按下物理鼠标按钮仅一次。它不是continually loops as fast as possible。实际上,您的代码中没有循环。所以,到目前为止,不需要睡眠定时器。
  • 我相信的罗技 G 集线器程序会自动无限循环脚本并尽可能快地循环,这是我遇到的问题,所以我必须实际放置一些东西,所以如果可能的话,它只执行一次
  • G hub program I believe automatically loops the script infinitely - 否。每次按下/释放物理按钮都会调用一次 OnEvent()。 I have to physically put something - “实际放置”是什么意思?
  • 我很抱歉我用错了词,谢谢你的帮助 Egor 我通过在脚本中添加一个按下和释放键的功能来解决我的问题。它现在按预期工作:)
  • 单独的问题,@EgorSkriptunoff 有没有办法做到这一点,如果我有 MouseButtonPressed(1) 和 (3),在 5 秒的时间范围内只按下并释放键 0x29 一次?即使在所述 5 秒的时间范围内释放并再次按下鼠标按钮 1 和 3。

标签: lua scripting logitech-gaming-software


【解决方案1】:

您可以通过GetRunningTime()获取当前时间(毫秒)

local last_time = -math.huge
local is_pressed = {}

function OnEvent(event, arg)
    if event == "PROFILE_ACTIVATED" then
        EnablePrimaryMouseButtonEvents(true)
    elseif event == "MOUSE_BUTTON_RELEASED" and (arg == 1 or arg == 2) then
        is_pressed[arg] = false
    elseif event == "MOUSE_BUTTON_PRESSED" and (arg == 1 or arg == 2) then
        is_pressed[arg] = true
        local mb1 = is_pressed[1]
        local mb2 = is_pressed[2]
        --OutputLogMessage(tostring(mb1) .. " - " .. tostring(mb2))
        if mb1 and mb2 and GetRunningTime() - last_time > 5000 then
            PressAndReleaseKey(0x29)
            last_time = GetRunningTime()
        end
    end
end

【讨论】:

  • 哇非常感谢!!这太棒了,我不知道你能做到这一点
猜你喜欢
  • 2021-05-15
  • 2021-03-29
  • 1970-01-01
  • 2021-08-14
  • 2021-04-12
  • 2021-08-13
  • 2021-10-22
  • 2020-11-02
  • 2013-08-01
相关资源
最近更新 更多