我正在尝试为 Logitech 鼠标制作一个脚本:
- 第 1 步:按下 LMB 时 -> 执行反冲模式
- 第 2 步:释放 LMB 时 -> MoveMouseRelative 到按下前的准确位置
那么有没有办法尝试第2步?这是脚本:
local Recoil_Pattern = {
{x = 0 ,y = 10 } ,--1st Shot
{x = 0 ,y = 10 } ,--2nd Shot (hold LMB 100ms)
{x = 0 ,y = 10 } ,--3rd Shot (hold LMB 200ms)
{x = 0 ,y = 10 } ,--4rd Shot (hold LMB 300ms)
{x = 0 ,y = 10 } ,--5rd Shot (hold LMB 400ms)
}
local Shot_Sleep = 100
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
if (IsMouseButtonPressed(1)) then
for i = 1, #Recoil_Pattern do
Sleep(10)
if IsMouseButtonPressed(1) then
Sleep(Shot_Sleep)
MoveMouseRelative( Recoil_Pattern[i].x, Recoil_Pattern[i].y )
end
end
end
elseif event == "MOUSE_BUTTON_RELEASED" and arg == 1 then
if not (IsMouseButtonPressed(1)) then
Sleep(10)
-- How to reverse the MoveMouseRelative to exact first position when releasing LMB
-- Ex.
-- If press and release LMB -> move mouse relative (0,-10)
-- If press and hold LMB for 100ms then release LMB -> move mouse relative (0,-20)
-- If press and hold LMB for 400ms then release LMB -> move mouse relative (0,-50)
end
end
end
Edit2:太好了,它在全自动拍摄模式下运行良好,但在半自动模式下(我使用“暂停”按钮作为拍摄按钮),如果 i == 3 之后它不会触发(它不会执行PressAndReleaseKey(“暂停”)更多)。请帮我完善一下,我在Edit 2中更新了半自动射击模式
local Recoil_Pattern = {
{x = 0 ,y = 10 } ,--1st Shot
{x = 0 ,y = 10 } ,--2nd Shot (hold LMB 100ms)
{x = 0 ,y = 10 } ,--3rd Shot (hold LMB 200ms)
{x = 0 ,y = 10 } ,--4th Shot (hold LMB 300ms)
{x = 0 ,y = 10 } ,--5th Shot (hold LMB 400ms)
}
local Shot_Sleep = 100
local recoil_sum_x, recoil_sum_y = 0, 0
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
for i = 1, #Recoil_Pattern do
Sleep(10)
if IsMouseButtonPressed(1) then
PressAndReleaseKey("pause")
Sleep(Shot_Sleep)
local dx, dy = Recoil_Pattern[i].x, Recoil_Pattern[i].y
recoil_sum_x, recoil_sum_y = recoil_sum_x - dx, recoil_sum_y - dy
MoveMouseRelative( dx, dy )
Sleep(Shot_Sleep)
if i == 3 then
ctrl_is_down = true
PressKey("lctrl")
end
else
break
end
end
elseif event == "MOUSE_BUTTON_RELEASED" and arg == 1 then
if ctrl_is_down then
ctrl_is_down = false
ReleaseKey("lctrl")
end
while recoil_sum_x ~= 0 or recoil_sum_y ~= 0 do
local dx, dy = recoil_sum_x, recoil_sum_y
dx = dx > 127 and 127 or dx < -127 and -127 or dx
dy = dy > 127 and 127 or dy < -127 and -127 or dy
MoveMouseRelative( dx, dy )
recoil_sum_x, recoil_sum_y = recoil_sum_x - dx, recoil_sum_y - dy
Sleep(10)
end
end
end