Lua脚本-同时按下多个键,松开停止

早上好,

我目前有一个记录在洛技上的宏(“循环”),它执行以下操作:

120毫秒延迟,键1,90毫秒延迟,左键单击,150毫秒延迟,键2,90毫秒延迟,左键单击,140毫秒延迟

它设置为切换。然后我使用以下脚本:

local flag
function OnEvent(event, arg)
   if event ==“MOUSE_BUTTON_PRESSED”并且arg == 20 then
      PlayMacro(“循环”)
   end
   if event ==“MOUSE_BUTTON_RELEASED”并且arg == 20 then
      AbortMacro()
   end
end

这很好用,但是... :D 显然,左键单击后的所有延迟在每次重复时都是相同的。我希望它们随机在120和160之间。遗憾的是,我是一个无望的LUA新手,所以我做了一些搜索并尝试将其全部扔到lua脚本中,但是我做错了什么,因为它只是按下1而不停止:

local flag
function OnEvent(event, arg)
   if event ==“MOUSE_BUTTON_PRESSED”and arg == 20 then
      Sleep(math.random(120, 160))
      PressKey(“1”)
      Releasekey(“1”)
      Sleep(90)
      PressMouseButton(1)
      ReleaseMouseButton(1)
      Sleep(math.random(120, 160))
      PressKey(“2”)
      Releasekey(“2”)
      Sleep(90)
      PressMouseButton(1)
      ReleaseMouseButton(1end
   if event ==“MOUSE_BUTTON_RELEASED”and arg == 20 then
      return
   end
end

我还缺少什么?

感谢帮助!

原文链接 https://stackoverflow.com/questions/69234657

点赞
stackoverflow用户1847592
stackoverflow用户1847592

步骤1.

你在游戏中使用鼠标4号键(“后退”)吗?

  • 如果是(游戏中设置了某些操作使用了鼠标4号键),请继续到“步骤2”。
  • 如果不是(游戏忽略了鼠标4号键的按下),请跳过“步骤2”并继续到“步骤3”。

步骤2.

你需要将游戏操作从鼠标4号键重新映射到其他键。

请执行以下操作:

  • 选择在游戏中当前未使用的键盘键

    (假设目前未使用的键是 F12

  • 进入LGS中的大鼠标图片并将命令F12分配给你的物理鼠标4号键

  • 进入游戏设置并将游戏操作设置为F12,而不是鼠标4号键

结果是,当你按下物理鼠标4号键时,游戏会接收到F12并激活游戏操作。

现在跳过“步骤3”并继续到“步骤4”。


步骤3.

进入LGS中的大鼠标图片。

取消分配标准命令“后退”从物理鼠标4号键(从下拉菜单中选择“取消分配”)。


步骤4.

进入LGS中的大鼠标图片。

将命令“后退”分配给你的物理按钮G20。


步骤5.

设置脚本

local function InterruptableSleep(ms)
   local tm = GetRunningTime() + ms
   while GetRunningTime() < tm do
      Sleep(5)
      if not IsMouseButtonPressed(4) then return true end
   end
end

function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 20 then
      repeat
         if InterruptableSleep(math.random(120, 160)) then break end
         PressKey("1")
         Releasekey("1")
         if InterruptableSleep(90) then break end
         PressMouseButton(1)
         ReleaseMouseButton(1)
         if InterruptableSleep(math.random(120, 160)) then break end
         PressKey("2")
         Releasekey("2")
         if InterruptableSleep(90) then break end
         PressMouseButton(1)
         ReleaseMouseButton(1)
      until not IsMouseButtonPressed(4)  -- 4 = "Back"
   end
end
2021-09-18 21:29:17