主题
注册鼠标点击快捷键 - RegisterMouseButton
函数简介
注册鼠标点击快捷键监听,可监听鼠标点击及点击次数。
接口名称
RegisterMouseButtonDLL调用
int RegisterMouseButton(long ola, int button, int type, MouseCallback callback);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| button | 整数型 | 按键类型。鼠标左键(1)、鼠标右键(2)、鼠标中间(3)、拓展键1(4)、拓展键2(5)。 |
| type | 整数型 | 按键状态。鼠标点击(0)、鼠标按下(1)、鼠标释放(2)。 |
| callback | 回调函数 | 回调函数 void MouseCallback(int button, int x, int y, int clicks),button 为按键类型,x/y 为坐标,clicks 为点击次数。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int ret = ola.StartHotkeyHook();
if (ret == 1) {
// button=1 左键, type=0 点击
int mouseRet = ola.RegisterMouseButton(1, 0, [](int button, int x, int y, int clicks) {});
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
int ret = ola.StartHotkeyHook();
if (ret == 1)
{
int mouseRet = ola.RegisterMouseButton(1, 0, (button, x, y, clicks) => { });
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ret = ola.StartHotkeyHook()
if ret == 1:
def on_mouse(button, x, y, clicks):
pass
mouse_ret = ola.RegisterMouseButton(1, 0, on_mouse)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
int ret = ola.StartHotkeyHook();
if (ret == 1) {
int mouseRet = ola.RegisterMouseButton(1, 0, null);
}cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.StartHotkeyHook()
if(ret == 1) {
var mouseRet = ola.RegisterMouseButton(1, 0, 0)
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.StartHotkeyHook()
If ret = 1 Then
mouseRet = ola.RegisterMouseButton(1, 0, 0)
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.StartHotkeyHook ()
.如果真 (ret = 1)
mouseRet = ola.RegisterMouseButton (1, 0, 0)
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.StartHotkeyHook();
if(ret == 1){
var mouseRet = ola.RegisterMouseButton(1, 0, function(button,x,y,clicks){});
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.StartHotkeyHook()
如果真 (ret = 1)
{
整数 mouseRet = ola.RegisterMouseButton(1, 0, 0)
}cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int32_t ret = ola.StartHotkeyHook();
if (ret == 1) {
int32_t mouseRet = ola.RegisterMouseButton(1, 0, nullptr);
}原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
StartHotkeyHook(instance);
RegisterMouseButton(instance, 1, 0, 0);csharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int StartHotkeyHook(long ola);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int RegisterMouseButton(long ola, int button, int type, long callback);
long instance = CreateCOLAPlugInterFace();
StartHotkeyHook(instance);
RegisterMouseButton(instance, 1, 0, 0);python
from ctypes import CDLL, c_int, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
StartHotkeyHook(instance);
RegisterMouseButton(instance, 1, 0, 0);返回值
整数型。1 成功,0 失败。
注意事项
- 注册前需先调用 StartHotkeyHook 安装键盘鼠标钩子。
- 参考 Windows 函数 SetWindowsHookExW 实现。
