首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Lua脚本-按下鼠标按钮时按下多个键,松开时停止

Lua脚本-按下鼠标按钮时按下多个键,松开时停止
EN

Stack Overflow用户
提问于 2021-09-18 12:29:18
回答 1查看 610关注 0票数 0

早上好,

我目前在Logitech中录制了一个宏("Loop"),它执行以下操作:

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

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

代码语言:javascript
运行
复制
local flag
function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 20 then
      PlayMacro("Loop")
   end
   if event == "MOUSE_BUTTON_RELEASED" and arg == 20 then
      AbortMacro()
   end
end

然而,这工作得很好。:D很明显,每次重复单击左键后的所有延迟都是相同的。我希望它们在120到160之间是随机的。遗憾的是,我是一个无可救药的LUA新手,所以我做了一些谷歌搜索,试图离开宏,并将其全部放入lua脚本中,但我做错了什么,因为它所做的一切就是不停的按下1:

代码语言:javascript
运行
复制
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(1)
   end   
   if event == "MOUSE_BUTTON_RELEASED" and arg == 20 then
      return
   end
end

我遗漏了什么?

感谢您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2021-09-18 21:29:18

步骤1.

你在游戏中使用鼠标按键4 ("Back")吗?

  • 如果是(游戏中某些动作设置为MB#4 ),则进入"Step 2“。
  • 如果没有(游戏忽略按MB#4键),则跳过"Step 2”,进入"Step 3“。

步骤2.

您必须将游戏操作从MB#4重新映射到其他键。

执行以下操作:

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

(假设当前未使用F12键)

  • 转到LGS中的大鼠标图片,将命令F12分配给您的物理MB#4

  • 转到您的游戏设置,并将游戏操作设置为F12,而不是MB#4

因此,当您按下physical MB#4时,游戏将接收F12并激活游戏操作。

现在跳过“步骤3”,继续执行“步骤4”。

步骤3.

转到LGS中的大鼠标图片。

从physical MB#4取消分配标准命令"Back“(从下拉菜单中选择" Unassign”)。

步骤4.

转到LGS中的大鼠标图片。

将命令"Back“分配给您的物理按钮G20。

步骤5.

设置脚本

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

https://stackoverflow.com/questions/69234657

复制
相关文章

相似问题

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