Logitech 脚本组合击键和鼠标点击

我正在尝试制作一个脚本,当我同时按住左侧 Ctrl 键和左侧鼠标键时,重复点击左键

目前我已经有了下面的代码:

function OnEvent(event, arg, family)
  OutputLogMessage("clicked event = %s, arg = %s\n", event, arg);
 if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and Ctrl_Down == 1 then
      repeat
      PressMouseButton(1) // 重复按住左键
      until not PressMouseButton(1)
     else ReleaseMouseButton(3) //左键抬起停止重复
  end

end

请注意,这是我第一次接触此类编码,任何帮助都将不胜感激。

点赞
用户7396148
用户7396148

当你使用 API 时,你想要的特定功能可能无法实现。

当你调用 PressMouseButton(1) 时,它会改变左键鼠标的状态。当你调用 ReleaseMouseButton(1) 时,即使你仍在按住鼠标,脚本也会将其识别为释放。这意味着你不能使用 IsMouseButtonPressed(1) 来检测按钮是否仍被按下。

如果你想要进行“点击”,你需要使用 PressAndReleaseMouseButton(1),但这样一来,你就无法再检测到何时停止按下鼠标按钮。作为替代方案,你可以查看 Ctrl 键是否仍被按下,使用 IsModifierPressed("ctrl")

当检测到按下带有 Ctrl 的左键单击时,以下内容应重复执行,直到释放 Ctrl 键:

function OnEvent(event, arg, family)
    OutputLogMessage("clicked event = %s, arg = %s\n", event, arg);
    if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and Ctrl_Down == 1 then
        repeat
            PressAndReleaseMouseButton(1) --when Ctrl is still pressed, repeat
        until not IsModifierPressed("ctrl")
    end
end

此信息基于_Logitech G 系列 Lua API V3.02_。

2019-02-18 21:04:35
用户8829161
用户8829161

首先,你必须定义 EnablePrimaryMouseButtonEvents() 来启用鼠标按键1的事件报告。为了避免任何无限循环,你必须使用 sleep()

按下左控制键然后按下左鼠标键,它会重复点击,直到你松开左鼠标键并松开左控制键时,这个脚本应该停止。

你的最终代码应该像这样:

EnablePrimaryMouseButtonEvents(true);

function OnEvent(event, arg)
    if IsModifierPressed("lctrl") then
        repeat
            if IsMouseButtonPressed(1) then
                repeat
                    PressMouseButton(1)
                    Sleep(15)
                    ReleaseMouseButton(1)
                until not IsMouseButtonPressed(1)
            end
        until not IsModifierPressed("lctrl")
    end
end
2019-02-22 14:14:12