Rapid fire with logitech lua script?

泄露秘密 提交于 2021-02-19 07:42:07

问题


When writing lua scripts for my logitech g502, I've gotten rapid fire to work, but it will continue to execute mouse presses after the mouse one button is released as long as the ctrl key is held. I am wondering if there is any kind of iteration that would allow me to signal a function that presses and releases the mouse but under the conditional that the same mouse button is pressed.(For example, ctrl must be held and rapid fire only executes when mouse button 1 is held down, as opposed to until ctrl is released).

Here is the code I am referring to

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

I am wondering if there is any kind of iteration that would allow me to signal a function that presses and releases the mouse but under the conditional that the same mouse button is pressed.(For example, ctrl must be held and rapid fire only executes when mouse button 1 is held down, as opposed to until ctrl is released).

Alternatives I have considered: binding fire to another key that isn't mouse button 1, and having it repeated when mouse button one is pressed.

Thanks in advance


回答1:


The actual problem is you're trying to simultaneously read real status and simulate press/release the same mouse button.
The only way to resolve this problem is (as you have suggested) to bind fire to additional key.
For example, in the game config you assign both left mouse button and keyboard key combination CtrlP to "Fire". Please note that P without a modifier must be NOT assigned to any action in the game.
And your script would be the following:

EnablePrimaryMouseButtonEvents(true)

function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsModifierPressed("lctrl") then
      repeat
         Sleep(15)
         PressKey("P")
         Sleep(15)
         ReleaseKey("P")
      until not IsMouseButtonPressed(1) or not IsModifierPressed("lctrl")
   end
end


来源:https://stackoverflow.com/questions/58121181/rapid-fire-with-logitech-lua-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!