Skip to content

设置鼠标位置回调 - SetMousePosCallback

函数简介

注册鼠标位置回调。当游戏内鼠标坐标与 Windows / 插件系统坐标不一致时(如 RawInput 锁定、自研输入层、内存坐标与系统光标偏差),可通过回调提供 游戏真实坐标,插件在 真实轨迹 MoveTo 中自动矫正终点。

不影响 GetCursorPos —— 主动查询仍返回插件/hook 维护的坐标。

接口名称

SetMousePosCallback

DLL调用

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 If
text
.局部变量 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 漂移检测循环)执行:

  1. 调用回调得到游戏坐标 (Gx, Gy);返回 -1完全走原逻辑
  2. 读取系统坐标 (Sx, Sy) = GetCursorPos(非回调)。
  3. 计算偏差:offset = (Gx - Sx, Gy - Sy)
  4. 若配置了 MousePosCallbackMinOffset > 0,且 |offsetX||offsetY| 小于该阈值,则 不矫正
  5. 矫正后目标:corrected = MoveTo目标 - offset
  6. 起点与相对移动基准仍用 ::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=不限制
EnableRealMousebooltrue须开启才会走轨迹矫正
MouseDriftCheckTime整数型0漂移检测循环(毫秒),0=关闭

通过 SetConfigSetConfigByKey 配置。

注意事项

  • 仅本地 DLL 进程 有效;远程 ConnectRemote 实例返回失败。
  • 未注册回调、回调返回 -1、或偏差低于阈值时,行为与 未接入本功能前完全一致
  • 非轨迹 MoveTo(未开 EnableRealMouse)当前 使用回调矫正。
  • 销毁对象时自动清除回调,也可手动 ClearMousePosCallback