lua - 释放 LMB 时如何将 MoveMouseRelative 反转到确切的第一个位置
问题描述
我正在尝试为 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
解决方案
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
local recoil_sum_x, recoil_sum_y = 0, 0
local ctrl_is_down
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if event == "MOUSE_BUTTON_PRESSED" and arg == 1 then
for i = 1, #Recoil_Pattern do
Sleep(Shot_Sleep)
if IsMouseButtonPressed(1) then
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 )
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
推荐阅读
- android - 如何从 1440x1080 Surface 获得 1920x1080 视频?
- sql - SQL Server 使用 where 条件创建 Unpivot 表
- java - 为什么Tomcat使用大量内存?
- python-3.x - 在 Python-Selenium 中自动下载文件时,如何以编程方式重命名文件?
- javascript - 将 window.location 转换为具有变量链接的 window.open
- oracle - 为什么这个 PL/SQL 触发器不显示任何结果?
- r - r中关于mu和polygon的问题
- php - PHP 随机/百分比机会执行选项之一
- python - 如何在其他类中打包 tkiner 对象?
- android - (DAGGER-ANDROID) 不能在 Espresso 测试中使用 @Inject 并且不能使用 mockWebServer