是否有设置两个鼠标按钮来切换脚本的功能?

问题描述

我正在编写反冲脚本,我希望能够同时使用两个鼠标按钮激活或切换它。这就是我到目前为止所拥有的。我想使用 g4 和 g5 使其工作,而不仅仅是 g4

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
  end
  if (event == "MOUSE_BUTTON_pressed" and arg == 4) then
    recoil = not recoil
    spot = not spot
  end
  if (event == "MOUSE_BUTTON_pressed" and arg == 1 and recoil) then
    if recoil then
      repeat
        MoveMouseRelative(-2,5)
        Sleep(10)
        MoveMouseRelative(2,-5)
        Sleep(21)
      until not IsMouseButtonpressed(1)
    end
  end
end

解决方法

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 == 4) then
    if btn_5_is_pressed then
      recoil = not recoil
      spot = not spot
    else
      btn_4_is_pressed = true
    end
  elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 5) then
    if btn_4_is_pressed then
      recoil = not recoil
      spot = not spot
    else
      btn_5_is_pressed = true
    end
  elseif (event == "MOUSE_BUTTON_RELEASED" and arg == 4) then
    btn_4_is_pressed = false
  elseif (event == "MOUSE_BUTTON_RELEASED" and arg == 5) then
    btn_5_is_pressed = false
  elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil) then
    if recoil then
      repeat
        MoveMouseRelative(-2,5)
        Sleep(10)
        MoveMouseRelative(2,-5)
        Sleep(21)
      until not IsMouseButtonPressed(1)
    end
  end
end

编辑
通过双击鼠标按钮 #6 进行切换:

function OnEvent(event,arg)
   OutputLogMessage("event = %s,arg)
   if event == "PROFILE_ACTIVATED" then
      EnablePrimaryMouseButtonEvents(true)
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 6 then
      local now = GetRunningTime()
      if now - (prev_time or -1000000) < 200 then
         prev_time = nil
         recoil = not recoil
      else
         prev_time = now
      end
   elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil then
      repeat
         MoveMouseRelative(-2,5)
         Sleep(10)
         MoveMouseRelative(2,-5)
         Sleep(21)
      until not IsMouseButtonPressed(1)
   end
end