如何使此Logitech Mouse LUA脚本更好地工作?

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

我想在LUA中为Logitech鼠标制作一个简单的宏。我是新手,我只是从几个来源将几行内容粘贴在一起。


    EnablePrimaryMouseButtonEvents(true);

    function OnEvent(event, arg)
 if IsKeyLockOn("numlock" )then
    if IsMouseButtonPressed(3)then
                            repeat  
                if IsMouseButtonPressed(1) then
     repeat
                              PressKey("P")
                                                     MoveMouseRelative(0,13)
                    Sleep(10)
                                                      MoveMouseRelative(0,13)
                                Sleep(10)
                                                      MoveMouseRelative(0,13)
                                Sleep(10)
                                                      MoveMouseRelative(0,13)
                                Sleep(10)
                    MoveMouseRelative(0,13)
                                Sleep(10)
                                    ReleaseKey("P")

                    Sleep(200)
                                until not IsMouseButtonPressed(1)
                end 
            until not IsMouseButtonPressed(3)

        elseif not IsMouseButtonPressed(3)then
                            repeat  
                if IsMouseButtonPressed(1) then
            repeat
                              PressKey("P")
                                                     MoveMouseRelative(0,15)
                                Sleep(30)
                                                     MoveMouseRelative(0,12)
                                Sleep(10)
                                                     MoveMouseRelative(0,12)
                                Sleep(10)
                                                    MoveMouseRelative(0,12)
                                Sleep(10)
                                                    MoveMouseRelative(0,12)
                                     Sleep(130)
                                    ReleaseKey("P")
                    Sleep(200)
                                until not IsMouseButtonPressed(1)
                end 
            until  IsMouseButtonPressed(3)
        end
end
end

首先,它看起来像是一团糟,但是有点像作品,对不起,我是新手。现在我遇到的问题是;

  1. 我使用了numlock来启用或禁用整个功能,因为我无法弄清楚如何使用单个MouseButtonKey来将其打开和关闭,它会一直播放,或者会损坏整个功能。没关系,如果不是因为怪异的错误,在我关闭numlock之后,由于某种原因我必须按下MouseButton 2将其关闭。

  2. 我以为我想要实现的目标非常简单,我想拥有4个功能;

Function 1 MoveMouseRelative repeated every ()ms
Function 2 MoveMouseRelative repeated every ()ms
Function 3 PressKey("P") repeated every ()ms
Function 4 PressKey("P") repeated every ()ms

然后将其组合为如果我按下MouseButtonPressed(1),它将执行功能1 + 3,因此它单击P并同时将鼠标向下拖动,但是具有不同的sleep()间隔,这将在单独的函数中声明否则,如果我按下并按下MouseButtonPressed(3)(右键)+ MouseButtonPressed(1),它将执行2 + 4个功能,并且在按住的同时重复执行,如果释放按钮则停止重复。

甚至有可能吗?我陷入了这段代码,无法停止思考上周的修复方法,但是由于没有受过任何教育,只是简单地猜测事情会如何发展,我碰到了我无法突破的墙。

非常感谢您的帮助。

lua mouse logitech logitech-gaming-software
1个回答
0
投票
EnablePrimaryMouseButtonEvents(true)

local sequence_LMB     = {{x=0,y=15, t=30}, {x=0,y=12, t=10}, {x=0,y=12, t=10}, {x=0,y=12, t=10}, {x=0,y=12, t=130}}
local sequence_LMB_RMB = {{x=0,y=13, t=10}, {x=0,y=13, t=10}, {x=0,y=13, t=10}, {x=0,y=13, t=10}, {x=0,y=13, t=10}}

function OnEvent(event, arg)
   if event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsKeyLockOn("numlock") then
      repeat
         PressKey("P")
         local sequence = IsMouseButtonPressed(3) and sequence_LMB_RMB or sequence_LMB
         for i, step in ipairs(sequence) do
            MoveMouseRelative(step.x, step.y)
            Sleep(step.t)
         end
         ReleaseKey("P")
         Sleep(200)
      until not IsMouseButtonPressed(1)
   end
end
© www.soinside.com 2019 - 2024. All rights reserved.