我正在尝试优化我的 Lua 脚本,但为什么它没有变得更流畅?

我试图使我的 Lua 脚本更流畅,因此我减小了步长,并将延迟时间变长,但实际上并没有起作用,我想知道是否有人知道如何解决?这是我正在尝试使之更平滑的代码。

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
  OutputLogMessage("Event: "..event.." Arg: "..arg.."\n")
  if IsMouseButtonPressed(3)then
    if IsMouseButtonPressed(1) then
      local positions = {             -- 将 MoveMouseRelative 的参数移动到二维数组中。
          {-35,51},
          {5,45},
          {-55,41},
          {-42,35},
          {0,31},
          {16,29},
          {28,23},
          {38,18},
          {41,15},
          {41,10},
          {37,10},
          {31,17},
          {18,24},
          {0,28},
          {-14,31},
          {-26,32},
          {-36,31},
          {-42,28},
          {-45,23},
          {-44,16},
          {-41,7},
          {-34,4},
          {-23,14},
          {-11,20},
          {11,24},
          {35,27},
          {48,27},
          {48,25},
          {37,20},
      }
      local index = 1
      repeat
        MoveMouseRelative(positions[index][1], positions[index][2])
        Sleep(133)
        index = (index % #positions) + 1 -- 当它达到数组长度时循环索引。
      until not IsMouseButtonPressed(1)
    end
  end
end

这是我减小延迟时间和步长后得到的代码。出于某种原因,我做了这个之后,速度和位置完全偏离了预期。我正在想知道为什么会出现这种情况,并且如何解决它。

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
  OutputLogMessage("Event: "..event.." Arg: "..arg.."\n")
  if IsMouseButtonPressed(3)then
    if IsMouseButtonPressed(1) then
      local positions = {             -- 将 MoveMouseRelative 的参数移动到二维数组中。
          {-35,51},
          {-15,48},
          {5,45},
          {-25,43},
          {-55,41},
          {-49,38},
          {-42,35},
          {-21,33},
          {0,31},
          {8,30},
          {16,29},
          {22,26},
          {28,23},
          {23,21},
          {38,18},
          {40,17},
          {41,15},
          {41,13},
          {41,10},
          {39,10},
          {37,10},
          {34,14},
          {31,17},
          {25,21},
          {18,24},
          {9,26},
          {0,28},
          {-7,30},
          {-14,31},
          {-20,31},
          {-26,32},
          {-31,32},
          {-36,31},
          {-39,30},
          {-42,28},
          {-44,26},
          {-45,23},
          {-45,20},
          {-44,16},
          {-42,12},
          {-41,7},
          {-37,6},
          {-34,4},
          {-29,9},
          {-23,14},
          {-17,17},
          {-11,20},
          {0,22},
          {11,24},
          {23,25},
          {35,27},
          {42,27},
          {48,27},
          {48,26},
          {48,25},
          {43,23},
          {37,20},
      }
      local index = 1
      repeat
        MoveMouseRelative(positions[index][1], positions[index][2])
        Sleep(67)
        index = (index % #positions) + 1 -- 当它达到数组长度时循环索引。
      until not IsMouseButtonPressed(1)
    end
  end
end

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

点赞