【问题标题】:does anyone know how to stop repeat in lua script when button is pressed?有谁知道按下按钮时如何在 lua 脚本中停止重复?
【发布时间】:2022-01-01 15:59:28
【问题描述】:

所以我目前正在为游戏编写一个快速射击脚本。这是我得到的

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
  if IsKeyLockOn("capslock")then
    if  IsMouseButtonPressed(1)then
      repeat
        Sleep(math.random(30, 60))
        PressMouseButton(1)
        Sleep(math.random(30, 60))
        ReleaseMouseButton(1)

      until not IsMouseButtonPressed(1)
    end
  end
end

所以当 capslock 打开并且 lmb 被按住时它会自动点击鼠标左键。 但是,有时即使我松开鼠标左键,脚本仍然会继续运行,那么有人知道如何解决这个问题吗? 或者以另一种方式,当按下“R”按钮或“shift”按钮时,有没有办法停止重复循环? 谢谢

【问题讨论】:

  • 持续多久?为什么要按下已经按下的按钮?如果按住 ReleaseMouseButton 会发生什么?哪个州有优先权?

标签: lua logitech-gaming-software


【解决方案1】:

您不能同时模拟 LMB 按下并监听其状态。
最简单的解决方案是为游戏分配另一个键而不是 LMB。
我假设你已经分配了 P 键进行拍摄。

function OnEvent(event, arg)
   if event == "PROFILE_ACTIVATED" then
      EnablePrimaryMouseButtonEvents(true)
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
      if IsKeyLockOn("capslock") then
         repeat
            PressKey("P")
            Sleep(math.random(30, 60))
            ReleaseKey("P")
            Sleep(math.random(30, 60))
         until not IsMouseButtonPressed(1)
      end
      PressKey("P")
   elseif event == "MOUSE_BUTTON_RELEASED" and arg == 1 then
      ReleaseKey("P")
   end
end

【讨论】:

    【解决方案2】:

    如果您使用的是 LOVE2D,我建议您尝试使用 love.mouse.isDown 功能。您可以通过以下链接了解更多信息:https://love2d.org/wiki/love.mouse

    【讨论】:

    • 这个问题是关于罗技 G 系列 Lua API 的。
    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2021-11-12
    • 2021-11-08
    • 2011-09-06
    • 1970-01-01
    • 2021-01-31
    • 2015-03-05
    • 1970-01-01
    • 1970-01-01
    • 2012-07-14
    相关资源
    最近更新 更多