【问题标题】:Logitech scripting combining keystroke and mouse click罗技脚本结合击键和鼠标点击
【发布时间】:2019-07-07 05:29:44
【问题描述】:

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

这是我目前所拥有的:

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) //repeat while the left mouse button down
      until not PressMouseButton(1)
     else ReleaseMouseButton(3) //stop the repating on left mouse button up
  end

end  

请注意,这是我第一次查看这种类型的编码,非常感谢任何帮助

【问题讨论】:

    标签: lua logitech logitech-gaming-software


    【解决方案1】:

    首先,您必须定义 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
    

    【讨论】:

    • 太棒了!这正是我想做的
    【解决方案2】:

    使用 api 可能无法实现您特别寻找的内容。

    当您调用PressMouseButton(1) 时,这会更改鼠标左键的状态。当您调用ReleaseMouseButton(1) 时,即使您仍然按下按钮,脚本也会看到它已释放。这意味着您不能使用IsMouseButtonPressed(1) 来检测按钮是否仍被按下。

    要创建“点击”,您需要使用PressAndReleaseMouseButton(1),这样您就无法再检测到何时停止按下鼠标按钮。作为替代方案,您可以使用IsModifierPressed("ctrl") 查看 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) --repeat while the ctrl is still pressed
            until not IsModifierPressed("ctrl")
        end
    end
    

    此信息基于 Logitech G 系列 Lua API V3.02

    【讨论】:

    • @Liam 是不是进入了if语句?我找不到信息来确认这种情况Ctrl_Down == 1 它可能需要替换为IsModifierPressed("ctrl")
    • 它还在重复点击脚本没有停止
    • 它是否在repeat 循环中无休止地重复?还是PressAndReleaseMouseButton 导致对OnEvent 的递归调用?如果您看到多个 OutputLogMessage 而不是 OnEvent 如果是这种情况,可以一起删除 repeat 循环。
    • 它在重复循环中无休止地重复它导致电脑延迟,我需要重新启动电脑来修复它
    猜你喜欢
    • 2021-10-07
    • 1970-01-01
    • 2022-01-26
    • 2020-01-26
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 2013-09-29
    • 2021-03-02
    相关资源
    最近更新 更多