lua - 反向 MoveMouseRelative Lua 编码
问题描述
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
elseif event == "PROFILE_DEACTIVATED" then
ReleaseMouseButton(2) -- to prevent it from being stuck on
elseif event == "MOUSE_BUTTON_PRESSED"
and (arg == 5 or arg == 4) then
recoil = recoil ~= arg and arg
elseif event == "MOUSE_BUTTON_PRESSED"
and arg == 1 and recoil == 5 then
MoveMouseRelative(0, -3)
for i = 1, 17 do
MoveMouseRelative(0, 2)
Sleep(15)
if not IsMouseButtonPressed(1) then return end
end
elseif event == "MOUSE_BUTTON_PRESSED"
and arg == 1 and recoil == 4 then
MoveMouseRelative(0, -3)
for i = 1, 35 do
Sleep(15)
MoveMouseRelative(0, 2)
if not IsMouseButtonPressed(1) then return end
end
if not IsMouseButtonPressed(1) then return end
end
end
这是 Lua 脚本,我想知道如何获得鼠标初始位置,然后返回初始位置。
我试图在脚本底部添加 MoveMousePosition(x,y)- (32767, 32767 ) 但在游戏中不起作用。只在桌面..
当我释放鼠标单击以返回中心或第一个位置时,我只想在 MoveMouseRelative 之后。
解决方案
要撤消任何操作,我们需要一个堆栈,您可以在其中记住您所做的一切。但是由于我们只有一个位置,因此顺序无关紧要,我们使用一个简单的数字来存储移动的总数 x 和 y。
local movedX = 0
local movedY = 0
function move(x, y)
MoveMouseRelative(x, y)
movedX = movedX + x
movedY = movedY + y
end
现在你move(0, 2)
只使用例如。
要撤消,我们会做相反的事情;因为我们只有减去一个数字。
function undo()
MoveMouseRelative(-movedX, -movedY)
movedX = 0
movedY = 0
end
不相关,但在你的循环中,不要使用return
but break
。这样你就可以到达事件的结尾并在undo()
那里添加一个。
推荐阅读
- javascript - 为什么这个 forEach() var 没有解析?
- azure-cosmosdb - Cosmos Mongo API NumberLong 查询找不到文档
- jenkins - Jenkins Pipeline:根据参数设置环境变量
- javascript - DeviceOrientationEvent.askPermission() 没有提示任何内容
- java - 如何使用 Gradle Java API 6.1.1
- angular - 表单组,表单数组
- input - UWP TextBox 聚焦但无法输入
- mongodb - MongoDB | 推入数组内对象的特定索引内的数组
- amazon-web-services - 如何比较两个 Amazon RDS 快照?
- debian - linstalling libc6:amd64 会破坏语言环境,并且不允许取消配置