简体   繁体   中英

Logitech scripting combining keystroke and mouse click

I'm trying to make a script that repeatedly clicks left mouse button when I hold left control key with left mouse button at the same time

This is what I have so far:

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  

Please note this is my first time looking over this type of coding as any help is greatly appreciated

First of all, you have to define EnablePrimaryMouseButtonEvents() to enables event reporting for mouse button 1

To avoid any endless loop you have to put sleep() ;

Press left control key then left mouse button it will repeat the click until you release the left mouse button then release left control key the script should be stopped

Your final code should be like:

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

What you are specifically looking for may not be possible with the api.

When you call PressMouseButton(1) this changes the state of the left mouse button. when you call ReleaseMouseButton(1) the same is true even if you are still pressing the button, the script will see it as released. This means you can't use IsMouseButtonPressed(1) to detect if the button is still pressed.

To create a "click" you would need to use PressAndReleaseMouseButton(1) and with this you can no longer detect when YOU stop pressing the mouse button. As an alternative you can look at the ctrl key and see if it is still pressed, using IsModifierPressed("ctrl") .

The following should repeat after a left click with ctrl down is detected and only end once ctrl has been released:

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

This information is based on the Logitech G-series Lua API V3.02 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM