主题
设置键鼠监听回调 - SetInputMonitor
函数简介
注册或清除键鼠事件监听回调。回调类型见 InputMonitorCallback。
仅本地进程有效(与 SetMousePosCallback 相同限制)。需要 InputSync 权限。
接口名称
SetInputMonitorDLL调用
c
int SetInputMonitor(long instance, InputMonitorCallback callback, long user_data);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| instance | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| callback | 回调函数 | InputMonitorCallback;传 NULL 表示清除。 |
| user_data | 长整数型 | 透传给回调的上下文,可为 0。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
void OLA_CALL_TYPE OnInput(int64_t instance, int32_t type, int32_t source, int32_t vk,
int32_t x, int32_t y, int32_t wheel, int32_t flags, int64_t seq,
int64_t t_ms, int64_t user_data) {
(void)instance; (void)source; (void)vk; (void)x; (void)y; (void)wheel;
(void)flags; (void)seq; (void)t_ms; (void)user_data;
// 快进快出
}
OLAPlugServer ola;
ola.EnableInputSync(1);
ola.SetInputMonitor((int64_t)(void*)&OnInput, 0);csharp
using System;
using System.Runtime.InteropServices;
using OLAPlug;
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
delegate void InputMonitorCallback(long instance, int type, int source, int vk,
int x, int y, int wheel, int flags, long seq, long tMs, long userData);
void OnInput(long instance, int type, int source, int vk, int x, int y, int wheel,
int flags, long seq, long tMs, long userData) { }
var ola = new OLAPlugServer();
InputMonitorCallback cb = OnInput;
ola.EnableInputSync(1);
ola.SetInputMonitor(Marshal.GetFunctionPointerForDelegate(cb).ToInt64(), 0);python
from ctypes import CFUNCTYPE, c_int64, c_int32
from OLAPlugServer import OLAPlugServer
InputMonitorCallback = CFUNCTYPE(
None, c_int64, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int64, c_int64, c_int64
)
@InputMonitorCallback
def on_input(instance, type_, source, vk, x, y, wheel, flags, seq, t_ms, user_data):
pass # 快进快出
ola = OLAPlugServer()
ola.EnableInputSync(1)
ola.SetInputMonitor(on_input, 0)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
ola.EnableInputSync(1);
// 回调指针由本地绑定传入;传 0 表示清除
ola.SetInputMonitor(0, 0);go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ola.EnableInputSync(1)
// 回调指针由本地绑定传入;传 0 表示清除
ola.SetInputMonitor(0, 0)rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
ola.enable_input_sync(1);
// 回调指针由本地绑定传入;传 0 表示清除
ola.set_input_monitor(0, 0);cpp
var ola = com("OlaPlug.OlaSoft")
ola.EnableInputSync(1);
ola.SetInputMonitor(0, 0);vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.EnableInputSync(1)
ola.SetInputMonitor(0, 0)text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.EnableInputSync(1)
ola.SetInputMonitor(0, 0)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.EnableInputSync(1);
ola.SetInputMonitor(0, 0);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.EnableInputSync(1);
ola.SetInputMonitor(0, 0);cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
ola.EnableInputSync(1);
ola.SetInputMonitor(0, 0);原生 DLL 调用
cpp
void OLA_CALL_TYPE OnInput(int64_t instance, int32_t type, int32_t source, int32_t vk,
int32_t x, int32_t y, int32_t wheel, int32_t flags, int64_t seq,
int64_t t_ms, int64_t user_data) {
// 快进快出
}
long instance = CreateCOLAPlugInterFace();
EnableInputSync(instance, 1);
SetInputMonitor(instance, OnInput, 0);csharp
using System;
using System.Runtime.InteropServices;
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
delegate void InputMonitorCallback(long instance, int type, int source, int vk,
int x, int y, int wheel, int flags, long seq, long tMs, long userData);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int EnableInputSync(long instance, int enable);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int SetInputMonitor(long instance, IntPtr callback, long user_data);
void OnInput(long instance, int type, int source, int vk, int x, int y, int wheel,
int flags, long seq, long tMs, long userData) { }
long instance = CreateCOLAPlugInterFace();
InputMonitorCallback cb = OnInput;
EnableInputSync(instance, 1);
SetInputMonitor(instance, Marshal.GetFunctionPointerForDelegate(cb), 0);python
from ctypes import CDLL, CFUNCTYPE, c_int64, c_int32
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
InputMonitorCallback = CFUNCTYPE(
None, c_int64, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int32, c_int64, c_int64, c_int64
)
@InputMonitorCallback
def on_input(instance, type_, source, vk, x, y, wheel, flags, seq, t_ms, user_data):
pass
instance = ola.CreateCOLAPlugInterFace()
ola.EnableInputSync(instance, 1)
ola.SetInputMonitor(instance, on_input, 0)返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
0 | 失败(无效实例或无权限)。 |
注意事项
| 项目 | 说明 |
|---|---|
| 仅本地进程有效 | 仅本地 DLL 进程 有效;远程实例不支持函数指针。 |
| 快进快出 | 回调可能在工作线程触发,须快进快出;禁止在回调内重入同实例同步 API。 |
