反向 MoveMouseRelative Lua 编码
2021-10-5 16:2:47
收藏:0
阅读:195
评论:2
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) -- 防止鼠标卡住
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 ) ,但在游戏中不起作用。只有在桌面上有效。
我只想在释放鼠标单击后将其返回到中心或最初位置。
原文链接 https://stackoverflow.com/questions/69452839
点赞
stackoverflow用户1847592
如Luke100000所说,您需要一个“撤销”动作(使用相反符号的相同距离)。
function OnEvent(event, arg)
OutputLogMessage("event = %s, arg = %d\n", event, arg)
if event == "PROFILE_ACTIVATED" then
EnablePrimaryMouseButtonEvents(true)
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)
local n = 0
for i = 1, 17 do
n = n + 1
MoveMouseRelative(0, 2)
Sleep(15)
if not IsMouseButtonPressed(1) then break end
end
repeat -- 等待鼠标左键释放
until not IsMouseButtonPressed(1)
for i = 1, n do
MoveMouseRelative(0, -2)
end
MoveMouseRelative(0, 3)
elseif event == "MOUSE_BUTTON_PRESSED" and arg == 1 and recoil == 4 then
MoveMouseRelative(0, -3)
local n = 0
for i = 1, 35 do
Sleep(15)
n = n + 1
MoveMouseRelative(0, 2)
if not IsMouseButtonPressed(1) then break end
end
repeat -- 等待鼠标左键释放
until not IsMouseButtonPressed(1)
for i = 1, n do
MoveMouseRelative(0, -2)
end
MoveMouseRelative(0, 3)
end
end
2021-10-10 20:01:16
评论区的留言会收到邮件通知哦~
推荐文章
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
- 如何编写 Lua 模式将字符串(嵌套数组)转换为真正的数组?
为了撤销任何操作,我们需要使用一个 堆栈 来保留你所做的所有操作。但由于我们只有一个位置,因此顺序并不重要,我们只需使用一个简单的数字来存储移动的总 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
,而应该使用break
。这样你就可以到达事件的末尾并在那里添加一个undo()
。