首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Logitech LUA脚本添加睡眠计时器

Logitech LUA脚本添加睡眠计时器
EN

Stack Overflow用户
提问于 2021-05-25 09:07:17
回答 1查看 237关注 0票数 0

我想知道如何将睡眠计时器添加到我的LUA脚本中,这样它就不会一直以最快的速度循环并按下0x29,我想让它在鼠标按下按键1和3时,每3-4秒按一次0x29键,而不是尽可能快地按下。

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

发布于 2021-05-25 12:56:05

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

代码语言:javascript
运行
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67680489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档