首页 > 解决方案 > 反向 MoveMouseRelative Lua 编码

问题描述

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 之后。

标签: lualogitech-gaming-software

解决方案


要撤消任何操作,我们需要一个堆栈,您可以在其中记住您所做的一切。但是由于我们只有一个位置,因此顺序无关紧要,我们使用一个简单的数字来存储移动的总数 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

不相关,但在你的循环中,不要使用returnbut break。这样你就可以到达事件的结尾并在undo()那里添加一个。


推荐阅读