如何在释放 LMB 时将 MoveMouseRelative 反转到精确的第一个位置

我正在尝试为罗技鼠标制作一个脚本,其中:

  1. 第一步:当 LMB 被按下时-〉做弹簧模式
  2. 第二步:当 LMB 被释放时-〉将 MoveMouseRelative 移动到按下之前的精确位置

那么有没有办法尝试第二步?这是脚本:

local Recoil_Pattern = {
    {x = 0  ,y = 10 }   ,--第一枪
    {x = 0  ,y = 10 }   ,--第二枪(按下 LMB 100 毫秒)
    {x = 0  ,y = 10 }   ,--第三枪(按下 LMB 200 毫秒)
    {x = 0  ,y = 10 }   ,--第四枪(按下 LMB 300 毫秒)
    {x = 0  ,y = 10 }   ,--第五枪(按下 LMB 400 毫秒)
}
local Shot_Sleep = 100

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
        if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
            if (IsMouseButtonPressed(1)) then
                for i = 1, #Recoil_Pattern do
                    Sleep(10)
                    if IsMouseButtonPressed(1) then
                        Sleep(Shot_Sleep)
                        MoveMouseRelative( Recoil_Pattern[i].x, Recoil_Pattern[i].y )
                    end
                end
            end

        elseif event == "MOUSE_BUTTON_RELEASED" and arg == 1 then
            if not (IsMouseButtonPressed(1)) then
                Sleep(10)
                -- 如何在释放 LMB 时将 MoveMouseRelative 反转到精确的第一个位置
                    -- 例如
                        -- 如果按下并释放 LMB-〉将鼠标移动到相对位置(0,-10)
                        -- 如果按下并持续按下 LMB 100ms 然后释放 LMB-〉将鼠标相对移动(0,-20)
                        -- 如果按下并持续按下 LMB 400ms 然后释放 LMB-〉将鼠标相对移动(0,-50)
            end
        end
    end

编辑2: 很好,它可以很好地运行全自动射击模式,但是在半自动模式下(我使用“暂停”按钮作为射击按钮),在 i == 3 然后它不会发射(它不会执行 PressAndReleaseKey ("pause"))。请帮助我完美,我在 Edit 2 中更新了半自动开火模式

local Recoil_Pattern = {
   {x = 0  ,y = 10 }   ,--第一枪
   {x = 0  ,y = 10 }   ,--第二枪(按下 LMB 100 毫秒)
   {x = 0  ,y = 10 }   ,--第三枪(按下 LMB 200 毫秒)
   {x = 0  ,y = 10 }   ,--第四枪(按下 LMB 300 毫秒)
   {x = 0  ,y = 10 }   ,--第五枪(按下 LMB 400 毫秒)
}
local Shot_Sleep = 100

local recoil_sum_x, recoil_sum_y = 0, 0

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
      for i = 1, #Recoil_Pattern do
         Sleep(10)
         if IsMouseButtonPressed(1) then
            PressAndReleaseKey("pause")
            Sleep(Shot_Sleep)
            local dx, dy = Recoil_Pattern[i].x, Recoil_Pattern[i].y
            recoil_sum_x, recoil_sum_y = recoil_sum_x - dx, recoil_sum_y - dy
            MoveMouseRelative( dx, dy )
            Sleep(Shot_Sleep)
            if i == 3 then
                ctrl_is_down = true
                PressKey("lctrl")
            end
         else
            break
         end
      end
   elseif event == "MOUSE_BUTTON_RELEASED" and arg == 1 then
        if ctrl_is_down then
                ctrl_is_down = false
                ReleaseKey("lctrl")
            end
      while recoil_sum_x ~= 0 or recoil_sum_y ~= 0 do
         local dx, dy = recoil_sum_x, recoil_sum_y
         dx = dx > 127 and 127 or dx < -127 and -127 or dx
         dy = dy > 127 and 127 or dy < -127 and -127 or dy
         MoveMouseRelative( dx, dy )
         recoil_sum_x, recoil_sum_y = recoil_sum_x - dx, recoil_sum_y - dy
         Sleep(10)
      end
   end
end
点赞
用户1847592
用户1847592
local Recoil_Pattern = {
   {x = 0  ,y = 10 }   ,--第1次射击
   {x = 0  ,y = 10 }   ,--第2次射击 (按住左键100毫秒)
   {x = 0  ,y = 10 }   ,--第3次射击 (按住左键200毫秒)
   {x = 0  ,y = 10 }   ,--第4次射击 (按住左键300毫秒)
   {x = 0  ,y = 10 }   ,--第5次射击 (按住左键400毫秒)
}
local Shot_Sleep = 100

local recoil_sum_x, recoil_sum_y = 0, 0
local ctrl_is_down

EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
      for i = 1, #Recoil_Pattern do
         Sleep(Shot_Sleep)
         if IsMouseButtonPressed(1) then
            local dx, dy = Recoil_Pattern[i].x, Recoil_Pattern[i].y
            recoil_sum_x, recoil_sum_y = recoil_sum_x - dx, recoil_sum_y - dy
            MoveMouseRelative( dx, dy )
            if i == 3 then
               ctrl_is_down = true
               PressKey("lctrl")
            end
         else
            break
         end
      end
   elseif event == "MOUSE_BUTTON_RELEASED" and arg == 1 then
      if ctrl_is_down then
         ctrl_is_down = false
         ReleaseKey("lctrl")
      end
      while recoil_sum_x ~= 0 or recoil_sum_y ~= 0 do
         local dx, dy = recoil_sum_x, recoil_sum_y
         dx = dx > 127 and 127 or dx < -127 and -127 or dx
         dy = dy > 127 and 127 or dy < -127 and -127 or dy
         MoveMouseRelative( dx, dy )
         recoil_sum_x, recoil_sum_y = recoil_sum_x - dx, recoil_sum_y - dy
         Sleep(10)
      end
   end
end
2020-05-09 08:23:56