【发布时间】:2020-03-10 00:04:33
【问题描述】:
我正在尝试为罗技鼠标制作一个脚本:
- 当按下鼠标左键时,将激活案例 1
- 按住鼠标右键并按下鼠标左键时,将激活案例2
但是,无论我如何尝试,它都只适用于案例 1。
EnablePrimaryMouseButtonEvents(true)
function OnEvent(event, arg)
-- Case 1: Press only Button 1
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and IsKeyLockOn("scrolllock") == false) then
Sleep(77)
if (IsMouseButtonPressed(1)) then
MoveMouseRelative(0, 4)
Sleep(76)
end
if (IsMouseButtonPressed(1)) then
MoveMouseRelative(0, 6)
Sleep(62)
end
if (IsMouseButtonPressed(1)) then
MoveMouseRelative(0, 5)
Sleep(84)
end
--Case 2: Press button 1+2
elseif (event == "MOUSE_BUTTON_PRESSED" and arg == 2 and IsKeyLockOn("scrolllock") == false) then
Sleep(77)
if (IsMouseButtonPressed(1)) then
MoveMouseRelative(0, 8)
Sleep(76)
end
if (IsMouseButtonPressed(1)) then
MoveMouseRelative(0, 9)
Sleep(62)
end
if (IsMouseButtonPressed(1)) then
MoveMouseRelative(0, 0)
Sleep(84)
end
end
end
我想在我按下这个脚本的人民币时再添加一个案例:
- 按下 RMB -> 按下 Lshift 按钮
- 释放RMB时->再次按下Lshift键
我在脚本的末尾添加了如下,它不起作用。
elseif (event == "MOUSE_BUTTON_PRESSED" and arg==2 and IsKeyLockOn("scrolllock")==false) then
PressAndReleaseKey("lshift")
elseif (event == "MOUSE_BUTTON_RELEASED" and arg==2 and IsKeyLockOn("scrolllock")==false) then
PressAndReleaseKey("lshift")
如果我想添加案例 3:按 LAlt + LMB,那么我应该把 IsModifierPressed("lalt") 放在哪里?我尝试如下但失败了
function OnEvent(event, arg)
if (event == "MOUSE_BUTTON_PRESSED" and arg == 1 and not IsKeyLockOn("scrolllock")) then
if not IsMouseButtonPressed(3) then -- 3 = Right Mouse Button (it's the same button as arg==2)
-- Case 1: Press only LMB
if IsModifierPressed("lalt") then
-- Case 3: Press LAlt+LMB
else
-- Case 2: Press RMB+LMB
end
elseif ((event == "MOUSE_BUTTON_PRESSED" or event == "MOUSE_BUTTON_RELEASED") and arg==2 and not IsKeyLockOn("scrolllock")) then
PressKey("lshift")
Sleep(50)
ReleaseKey("lshift")
end
end
【问题讨论】:
-
其实代码并没有按照你说的做。我不熟悉罗技软件,但在你的情况下,如果没有按下键 1(因为
elseif),你只会进入elseif (event == "MOUSE_BUTTON_PRESSED"。将第二个语句作为“正常”的 if 语句放入另一个语句中,它将起作用。
标签: lua logitech-gaming-software