如何为Logitech鼠标编写简单的Lua代码?

问题描述 投票:0回答:2

我正在尝试为Logitech鼠标创建脚本:

  1. 当按下鼠标左键时,将激活情况1
  2. [按住鼠标右键并按下鼠标左键,将激活情况2

但是,无论我如何尝试,它仅适用于情况1。

EnablePrimaryMouseButtonEvents(true)

function OnEvent(event, arg)
  -- Case 1: Press only Button  1
  if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsKeyLockOn("scrolllock") == false) then
    Sleep(77)   
    if (IsMouseButtonPressed(1)) then
      MoveMouseRelative(0, 4)
      Sleep(76) 
    end 
    if (IsMouseButtonPressed(1)) then
      MoveMouseRelative(0, 6)
      Sleep(62) 
    end
    if (IsMouseButtonPressed(1)) then
      MoveMouseRelative(0, 5)
      Sleep(84) 
    end

  --Case 2: Press button 1+2
  elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 2 and IsKeyLockOn("scrolllock") == false) then
    Sleep(77)   
    if (IsMouseButtonPressed(1)) then
      MoveMouseRelative(0, 8)
      Sleep(76) 
    end 
    if (IsMouseButtonPressed(1)) then
      MoveMouseRelative(0, 9)
      Sleep(62) 
    end 
    if (IsMouseButtonPressed(1)) then
      MoveMouseRelative(0, 0)
      Sleep(84)
    end 
  end
end

当我按下此脚本的RMB时,我想再增加一个案例:

  • 按人民币时->按Lshift按钮
  • 释放人民币时->再次按Lshift按钮

我添加了脚本的结尾,如下所示,它不起作用。

elseif (event == "MOUSE_BUTTON_PRESSED" and arg==2 and IsKeyLockOn("scrolllock")==false) then       
    PressAndReleaseKey("lshift")


elseif (event == "MOUSE_BUTTON_RELEASED" and arg==2 and IsKeyLockOn("scrolllock")==false) then
    PressAndReleaseKey("lshift")

如果要添加情况3:按LAlt + LMB,那么我将IsModifierPressed(“ lalt”)放在哪里?我尝试如下,但失败

function OnEvent(event, arg)
  if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and not IsKeyLockOn("scrolllock")) then
    if not IsMouseButtonPressed(3) then -- 3 = Right Mouse Button (it's the same button as arg==2)
      -- Case 1: Press only LMB
    if IsModifierPressed("lalt") then 
      -- Case 3: Press LAlt+LMB
   else
      -- Case 2: Press RMB+LMB
    end
  elseif ((event == "MOUSE_BUTTON_PRESSED" or event == "MOUSE_BUTTON_RELEASED") and arg==2 and not IsKeyLockOn("scrolllock")) then
    PressKey("lshift") 
    Sleep(50)
    ReleaseKey("lshift") 
  end 
end
lua logitech-gaming-software
2个回答
2
投票
function OnEvent(event, arg)
  if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and not IsKeyLockOn("scrolllock")) then
    if IsModifierPressed("lalt") then 
      -- Case 3: Press LAlt+LMB
    elseif not IsMouseButtonPressed(3) then -- 3 = Right Mouse Button (it's the same button as arg==2)
      -- Case 1: Press only LMB
    else
      -- Case 2: Press RMB+LMB
    end
  elseif ((event == "MOUSE_BUTTON_PRESSED" or event == "MOUSE_BUTTON_RELEASED") and arg==2 and not IsKeyLockOn("scrolllock")) then
    PressKey("lshift") 
    Sleep(50)
    ReleaseKey("lshift") 
  end 
end

-1
投票

您在elseif之前不能有end。 elseif会自动充当最后一个的end

© www.soinside.com 2019 - 2024. All rights reserved.