AHK实现鼠标瞬移(非MouseMove)及RustDesk游戏鼠标同步问题
问题:RustDesk远程桌面下AHK鼠标循环移动的同步与角色转动问题
我通过RustDesk远程桌面游玩游戏,编写了一款AHK脚本实现鼠标水平360度循环移动,但鼠标左右移动时游戏内角色会随之转动。希望实现非MouseMove方式的鼠标瞬移,且操作不会在RustDesk中同步显示;曾尝试使用BlockInput但会完全禁用鼠标,现寻求可行解决方案。
原脚本代码:
#Persistent SetTimer, check, -100 return check(){ If edge("left") { MouseMove, 1718, 490, 0 } else if edge("right") { MouseMove, 0, 490, 0 } ; ... SetTimer, check, -100 } edge(pos){ SysGet, VirtualWidth, 78 SysGet, VirtualHeight, 79 T := 10 CoordMode, Mouse, Screen MouseGetPos, mX, mY left := (mX < T) top := (mY < T) right := (mX > VirtualWidth - T) bottom := (mY > VirtualHeight - T) If (pos = "left") return left else if (pos = "top") return top else if (pos = "right") return right else if (pos = "bottom") return bottom }
我曾尝试使用BlockInput,但它会完全禁用鼠标。
解决方案
1. 改用SendInput发送硬件级鼠标瞬移
MouseMove属于系统级消息,易被远程桌面捕获;改用SendInput发送原始鼠标输入事件,既实现瞬间定位(不会触发游戏内角色转动),又能降低被RustDesk同步的概率。
修改核心逻辑后的代码:
check(){ If edge("left") { ; 0x0000参数表示使用绝对屏幕坐标瞬移 SendInput, {MouseMove 1718, 490, 0, 0x0000} } else if edge("right") { SendInput, {MouseMove 0, 490, 0, 0x0000} } ; ... SetTimer, check, -100 }
2. 局部拦截鼠标消息,避免RustDesk同步
不使用全局BlockInput,而是通过监听鼠标移动消息,在瞬移触发时临时拦截消息传递,仅让游戏接收定位信号:
完整修改后的脚本:
#Persistent Global BlockMouse := false ; 监听鼠标移动系统消息(0x0200) OnMessage(0x0200, "MouseMoveMsg") SetTimer, check, -100 return MouseMoveMsg(wParam, lParam) { Global BlockMouse ; 临时拦截鼠标移动消息 if (BlockMouse) return 1 } check(){ Global BlockMouse If edge("left") { BlockMouse := true SendInput, {MouseMove 1718, 490, 0, 0x0000} BlockMouse := false } else if edge("right") { BlockMouse := true SendInput, {MouseMove 0, 490, 0, 0x0000} BlockMouse := false } ; ... SetTimer, check, -100 } edge(pos){ SysGet, VirtualWidth, 78 SysGet, VirtualHeight, 79 T := 10 CoordMode, Mouse, Screen MouseGetPos, mX, mY left := (mX < T) top := (mY < T) right := (mX > VirtualWidth - T) bottom := (mY > VirtualHeight - T) If (pos = "left") return left else if (pos = "top") return top else if (pos = "right") return right else if (pos = "bottom") return bottom }
3. 限定输入范围到游戏窗口
将脚本输入锁定到游戏窗口内,进一步避免RustDesk捕获全局鼠标操作:
; 替换为你的游戏窗口标题,仅在窗口激活时执行脚本 #IfWinActive, 游戏窗口标题 ; 原脚本所有内容... #IfWinActive
内容的提问来源于stack exchange,提问作者Vladimir Putin
相关产品推荐
相关产品推荐

