我想知道如何将睡眠计时器添加到我的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
发布于 2021-05-25 12:56:05
您可以通过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
https://stackoverflow.com/questions/67680489
复制相似问题