主题
设置鼠标位置回调 - SetMousePosCallback
函数简介
注册鼠标位置回调。当游戏内鼠标坐标与 Windows / 插件系统坐标不一致时(如 RawInput 锁定、自研输入层、内存坐标与系统光标偏差),可通过回调提供 游戏真实坐标,插件在 真实轨迹 MoveTo 中自动矫正终点。
不影响 GetCursorPos —— 主动查询仍返回插件/hook 维护的坐标。
接口名称
SetMousePosCallbackDLL调用
cpp
int SetMousePosCallback(long ola, MousePosCallback callback, long user_data);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| callback | 回调函数 | MousePosCallback;传 NULL 等价于 ClearMousePosCallback。 |
| user_data | 长整数型 | 透传给回调的上下文(对象指针、窗口 ID 等),可为 0。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int ret = ola.SetMousePosCallback(0, 0);
if (ret == 1) {
// 操作成功
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
int ret = ola.SetMousePosCallback(0, 0);
if (ret == 1)
{
// 操作成功
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ret = ola.SetMousePosCallback(0, 0)
if ret == 1:
pass # 操作成功java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
int ret = ola.SetMousePosCallback(0, 0);
if (ret == 1) {
// 操作成功
}cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.SetMousePosCallback(0, 0)
if(ret == 1) {
// 操作成功
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.SetMousePosCallback(0, 0)
If ret = 1 Then
' 操作成功
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.SetMousePosCallback(0, 0)
.如果真 (ret = 1)
' 操作成功
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.SetMousePosCallback(0, 0);
if(ret == 1){
// 操作成功
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.SetMousePosCallback(0, 0)
如果真 (ret = 1)
{
// 操作成功
}cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int32_t ret = ola.SetMousePosCallback(0, 0);
if (ret == 1) {
// 操作成功
}原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
SetMousePosCallback(instance, 0, 0);csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int SetMousePosCallback(long ola, int callback, long user_data);
long instance = CreateCOLAPlugInterFace();
SetMousePosCallback(instance, 0, 0);python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.SetMousePosCallback(instance, 0, 0)返回值
| 值 | 说明 |
|---|---|
| 1 | 成功 |
| 0 | 失败(instance 无效、远程模式等) |
矫正算法说明
仅在 EnableRealMouse 开启且 MoveTo 走真实轨迹 时生效(见 SetConfig)。
每次 ensureMove(含 MouseDriftCheckTime 漂移检测循环)执行:
- 调用回调得到游戏坐标
(Gx, Gy);返回-1则 完全走原逻辑。 - 读取系统坐标
(Sx, Sy)= GetCursorPos(非回调)。 - 计算偏差:
offset = (Gx - Sx, Gy - Sy)。 - 若配置了
MousePosCallbackMinOffset > 0,且|offsetX|与|offsetY|均小于该阈值,则 不矫正。 - 矫正后目标:
corrected = MoveTo目标 - offset。 - 起点与相对移动基准仍用
::GetCursorPos系统光标;仅终点使用矫正坐标。
数值示例
| 量 | 值 |
|---|---|
| MoveTo 目标 | (200, 100) |
| GetCursorPos | (150, 100) |
| 回调坐标 | (120, 100) |
offsetX = 120 - 150 = -30
correctedX = 200 - (-30) = 230系统光标需移到屏幕 (230, 100) 附近,游戏内才会接近 (200, 100)。
相关配置
| 配置项 | 类型 | 默认 | 说明 |
|---|---|---|---|
| MousePosCallbackMinOffset | 整数型 | 0 | 偏差阈值(像素)。|offsetX| 与 |offsetY| 均小于该值时不触发矫正;0=不限制 |
| EnableRealMouse | bool | true | 须开启才会走轨迹矫正 |
| MouseDriftCheckTime | 整数型 | 0 | 漂移检测循环(毫秒),0=关闭 |
通过 SetConfig 或 SetConfigByKey 配置。
注意事项
- 仅本地 DLL 进程 有效;远程 ConnectRemote 实例返回失败。
- 未注册回调、回调返回
-1、或偏差低于阈值时,行为与 未接入本功能前完全一致。 - 非轨迹 MoveTo(未开 EnableRealMouse)当前 不 使用回调矫正。
- 销毁对象时自动清除回调,也可手动 ClearMousePosCallback。
