首页 > 解决方案 > 是否可以将 .ahk 转换为 .lua?

问题描述

我想在LUA中为罗技鼠标制作一个简单的宏。我完全是新手,我只是从几个来源将几行粘贴在一起。首先,它看起来像一团糟,但有点工作,对不起,我完全是新手。现在我遇到的问题是;

我想要完成的是当我按下我分配给它的任何键时,它会切换这个脚本以循环/重复,直到我再次按下任何键。

我希望能够在鼠标上按 CTRL+7 并打开重复,直到我再次按 CTRL+7 来关闭重复。

请帮忙。感谢您的时间。

OutputLogMessage("Event: "..event.." Arg: "..arg.."\n")
if event == "MOUSE_BUTTON_PRESSED" and arg == nil then
   repeat
      MoveMouseRelative(1280,-5000)
      PressAndReleaseMouseButton(1)
      Sleep(3200)
until not IsMouseButtonPressed(nil)
end
end

标签: lualogitech-gaming-software

解决方案


第 1 步。
您在游戏中使用鼠标按钮 4(“返回”)吗?

  • 如果是(游戏中某些动作设置为 MB#4),则继续“步骤 2”。
  • 如果否(游戏忽略 MB#4 按下),跳过“步骤 2”并继续进行“步骤 3”。

第 2 步。
您必须将游戏动作从 MB#4 重新映射到其他键。
请执行下列操作:

  • 选择您当前未在游戏中使用的键盘键
    (假设F12当前未使用该键)
  • 转到 GHUB(鼠标设备、“作业”屏幕、KEYS 选项卡);
    分配F12给您的物理 MB#4
  • 转到您的游戏设置;
    将游戏动作设置为F12而不是 MB#4

现在,当您按下物理 MB#4 时,游戏会接收F12并激活游戏动作。
跳过“步骤 3”并继续执行“步骤 4”。


步骤 3.
转到 GHUB(鼠标设备,“作业”屏幕)。
从物理 MB#4 取消分配标准命令“Back”(单击并从下拉菜单中选择 DISABLE)。
禁用的 MB#4 看起来像一个白色圆圈,里面有黑色。


步骤 4.
转到 GHUB(键盘设备,“作业”屏幕)。
将标准命令“Back”分配给物理键 G7。


步骤 5.
设置脚本:

local toggle, prev_down

local function Interruptable_Sleep(ms)
   local tm = GetRunningTime() + ms
   repeat
      local now = GetRunningTime()
      if now < tm then
         Sleep(math.min(10, tm - now))
         local down = IsMouseButtonPressed(4)  -- 4 = "Back"
         toggle, prev_down = toggle or not prev_down and down, down
      end
   until toggle or now >= tm
end

function OnEvent(event, arg)
   OutputLogMessage("Event: "..event.." Arg: "..arg.."\n")
   if event == "G_PRESSED" and arg == 7 then
      toggle = not toggle
      if toggle then
         prev_down, toggle = true
         repeat
            for j = 1, 40 do
               MoveMouseRelative(1280/40,-5000/40)
               Interruptable_Sleep(10)
            end
            if not toggle then 
               PressAndReleaseMouseButton(1)
               Interruptable_Sleep(3200)
            end
         until toggle
      end
   end
end

现在您可以通过按键盘键 G7 来启动和停止循环


推荐阅读