【问题标题】:Reverse MoveMouseRelative Lua Codding反向 MoveMouseRelative Lua 编码
【发布时间】:2021-11-25 20:58:07
【问题描述】:
function OnEvent(event, arg)

  OutputLogMessage("event = %s, arg = %d\n", event, arg)
  if event == "PROFILE_ACTIVATED" then
    EnablePrimaryMouseButtonEvents(true)
  elseif event == "PROFILE_DEACTIVATED" then
    ReleaseMouseButton(2) -- to prevent it from being stuck on
  elseif event == "MOUSE_BUTTON_PRESSED" 
               and (arg == 5 or arg == 4) then 
    recoil = recoil ~= arg and arg
  elseif event == "MOUSE_BUTTON_PRESSED" 
               and arg == 1 and recoil == 5 then
    MoveMouseRelative(0, -3) 
    for i = 1, 17 do
      MoveMouseRelative(0, 2)  
      Sleep(15)
      if not IsMouseButtonPressed(1) then return end

    end

  elseif event == "MOUSE_BUTTON_PRESSED" 
               and arg == 1 and recoil == 4 then
    MoveMouseRelative(0, -3) 
    for i = 1, 35 do
      Sleep(15)
      MoveMouseRelative(0, 2)       
      if not IsMouseButtonPressed(1) then return end
    end
    if not IsMouseButtonPressed(1) then return end
  end
end

这是 Lua 脚本,我想知道如何获得鼠标初始位置,然后返回初始位置。

我尝试在脚本底部添加 MoveMousePosition(x,y)- (32767, 32767 ) 但在游戏中不起作用。仅在桌面上..

我只想在 MoveMouseRelative 之后释放鼠标单击以返回中心或第一个位置。

【问题讨论】:

  • @Egor Skriptunoff - 请帮助我,我知道你是这些 lua 问题的专家。
  • 我仍然对你的格式化感到头晕,但我认为这里的主要问题是你不能在相对模式下设置绝对位置(例如游戏)。是这样吗?如果是,只需使用MoveMouseRelative 并撤消您的移动。所以对于你的第一个脚本MoveMouseRelative(0, 3 - 17 * 2)
  • 我之前试过这个,但如果我只是使用水龙头开火——比如按下 2 秒,它会比我想要从撤销位置的那一刻上升得更快。如果我想按住比我不能因为 MoveMouseRelative(0, 3 - 17 * 2) 将在“for statement”结束后开始。我需要在这个脚本中介绍当点击在记录位置时以及当点击被释放以返回该位置时,我想在两个脚本中添加它。无论如何感谢撤消信息,我会考虑将来使用撤消语句制作一个
  • 我想我明白了。跟踪总移动位置。例如。在调用MoveMouseRelative 之后增加MouseMovedY 或其他东西(也许引入一个同时做这两个功能的函数)。然后,每当您想重置时,使用存储的值并将其重置为 0(基本上是您的undo())。
  • 我明白你说的,但你能举个例子吗?我是初学者,当鼠标在 Y 轴上移动时,我需要一些变量来获得 +1,而不是 IsMouseButtonPressed(1) 返回第一个位置?

标签: lua logitech-gaming-software


【解决方案1】:

正如 Luke100000 所说,您需要一个“撤消”运动(相同的距离,相反的符号)。

function OnEvent(event, arg)
   OutputLogMessage("event = %s, arg = %d\n", event, arg)
   if event == "PROFILE_ACTIVATED" then
      EnablePrimaryMouseButtonEvents(true)
   elseif event == "MOUSE_BUTTON_PRESSED" and (arg == 5 or arg == 4) then
      recoil = recoil ~= arg and arg
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil == 5 then
      MoveMouseRelative(0, -3)
      local n = 0
      for i = 1, 17 do
         n = n + 1
         MoveMouseRelative(0, 2)
         Sleep(15)
         if not IsMouseButtonPressed(1) then break end
      end
      repeat  -- wait for LMB release
      until not IsMouseButtonPressed(1)
      for i = 1, n do
         MoveMouseRelative(0, -2)
      end
      MoveMouseRelative(0, 3)
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil == 4 then
      MoveMouseRelative(0, -3)
      local n = 0
      for i = 1, 35 do
         Sleep(15)
         n = n + 1
         MoveMouseRelative(0, 2)
         if not IsMouseButtonPressed(1) then break end
      end
      repeat  -- wait for LMB release
      until not IsMouseButtonPressed(1)
      for i = 1, n do
         MoveMouseRelative(0, -2)
      end
      MoveMouseRelative(0, 3)
   end
end

【讨论】:

    【解决方案2】:

    要撤消任何操作,我们需要stack,您可以在其中记住您所做的一切。但是由于我们只有一个位置,因此顺序无关紧要,我们使用一个简单的数字来存储移动的 x 和 y 总数。

    local movedX = 0
    local movedY = 0
    function move(x, y)
        MoveMouseRelative(x, y)
        movedX = movedX + x
        movedY = movedY + y
    end
    

    现在你使用例如仅限move(0, 2)

    要撤消,我们会做相反的事情;因为我们只有减去一个数字。

    function undo()
        MoveMouseRelative(-movedX, -movedY)
        movedX = 0
        movedY = 0
    end
    

    不相关,但在您的循环中,不要使用return,而是使用break。这样您就可以在活动结束时添加undo()

    【讨论】:

    • 我明白我应该做什么,但就像我说的那样,我很难在那个脚本中实现这一点。即使有了第一个脚本,我也得到了很多帮助。我不知道如何在我的脚本中引入这个
    • 我希望我听起来不会太粗鲁,但我希望你学习编程的基础知识。 Stackoverflow 不能只为你编写代码,只能帮助 :)
    猜你喜欢
    • 2021-12-13
    • 2021-05-27
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 2015-10-31
    相关资源
    最近更新 更多