Lua脚本-按下鼠标按钮时多键,释放时停止



早上好

我目前在Logitech中记录了一个宏("Loop"),它执行以下操作:

120延时,键1,90延时,左键点击,150延时,键2,90延时,左键点击,140延时

设置为切换。然后使用以下脚本:

local flag
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 20 then
PlayMacro("Loop")
end
if event == "MOUSE_BUTTON_RELEASED" and arg == 20 then
AbortMacro()
end
end

这工作得很好,但是…很明显,每次重复点击左键后的所有延迟都是一样的。我希望它们在120到160之间是随机的。遗憾的是,我是一个毫无希望的LUA新手,所以我做了一些谷歌搜索,并试图从宏中移开,并将其全部扔到LUA脚本中,但是我做错了,因为它所做的就是不停地按1:

local flag
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 20 then
Sleep(math.random(120, 160))
PressKey("1")
Releasekey("1")
Sleep(90)
PressMouseButton(1)
ReleaseMouseButton(1)
Sleep(math.random(120, 160))
PressKey("2")
Releasekey("2")
Sleep(90)
PressMouseButton(1)
ReleaseMouseButton(1)
end   
if event == "MOUSE_BUTTON_RELEASED" and arg == 20 then
return
end
end

我错过了什么?

感谢你的帮助!

第一步
你会在游戏中使用鼠标4键("后退")吗?

  • 如果是(游戏中某些动作被设置为mb# 4),则继续"步骤2"。
  • 如果没有(游戏忽略mb# 4按键),跳过"第2步"。并进入"步骤3"。

步骤2。
你必须将游戏动作从mb# 4重新映射到其他键上。

  • 选择当前不在游戏中使用的键盘键
    (让我们假设当前未使用F12键)
  • 转到LGS中的大鼠标图片,并将命令F12分配给物理MB#4
  • 进入你的游戏设置,将游戏动作设置为F12而不是mb# 4

因此,当您按下物理mb# 4时,游戏接收F12并激活游戏动作。
现在跳过"并继续"第4步"。


步骤3。
进入LGS中的大鼠标图片。
取消指定标准命令"Back"从物理MB#4 (select "Unassign">


步骤4。
进入LGS中的大鼠标图片。
分配命令"返回"到您的物理按钮G20


第5步。
设置脚本

local function InterruptableSleep(ms)
local tm = GetRunningTime() + ms
while GetRunningTime() < tm do
Sleep(5)
if not IsMouseButtonPressed(4) then return true end
end
end
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 20 then
repeat
if InterruptableSleep(math.random(120, 160)) then break end
PressKey("1")
Releasekey("1")
if InterruptableSleep(90) then break end
PressMouseButton(1)
ReleaseMouseButton(1)
if InterruptableSleep(math.random(120, 160)) then break end
PressKey("2")
Releasekey("2")
if InterruptableSleep(90) then break end
PressMouseButton(1)
ReleaseMouseButton(1)
until not IsMouseButtonPressed(4)  -- 4 = "Back"
end
end

最新更新