Skip to content

卸载键盘快捷键 - UnregisterHotkey

函数简介

卸载已注册的键盘快捷键监听。

接口名称

UnregisterHotkey

DLL调用

int UnregisterHotkey(long ola, int keycode, int modifiers);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
keycode整数型按键码。
modifiers整数型修饰键组合,使用位或组合,见下表。

modifiers 修饰键

将需要的修饰键 按位或(|)相加 后传入 modifiers 参数(须与注册时一致):

说明
1左 Shift
2左 Ctrl
4左 Meta(Win 键)
8左 Alt
16右 Shift
32右 Ctrl
64右 Meta
128右 Alt

位运算组合示例

csharp
// 卸载 Ctrl + Alt + F9(与注册时 modifiers 一致)
int modifiers = 2 | 8;  // 10
ola.UnregisterHotkey(0x78, modifiers);
cpp
// 卸载 Ctrl + Alt 组合键
int modifiers = 2 | 8;
ola.UnregisterHotkey(120, modifiers);
python
# 卸载 Ctrl + Alt + F9
modifiers = 2 | 8
ola.UnregisterHotkey(0x78, modifiers)

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int ret = ola.StartHotkeyHook();
if (ret == 1) {
    ola.RegisterHotkey(120, 10, nullptr);
    ola.UnregisterHotkey(120, 10);
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
int ret = ola.StartHotkeyHook();
if (ret == 1)
{
    ola.RegisterHotkey(120, 10, (k, m) => 0);
    ola.UnregisterHotkey(120, 10);
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ret = ola.StartHotkeyHook()
if ret == 1:
    ola.RegisterHotkey(120, 10, lambda k, m: 0)
    ola.UnregisterHotkey(120, 10)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
int ret = ola.StartHotkeyHook();
if (ret == 1) {
    ola.UnregisterHotkey(120, 10);
}
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
ret := ola.StartHotkeyHook()
if ret == 1 {
    ola.RegisterHotkey(120, 10, nullptr)
    ola.UnregisterHotkey(120, 10)
}
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let ret = ola.start_hotkey_hook();
if ret == 1 {
    ola.register_hotkey(120, 10, nullptr);
    ola.unregister_hotkey(120, 10);
}
cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.StartHotkeyHook()
if(ret == 1) {
    ola.RegisterHotkey(120, 10, 0)
    ola.UnregisterHotkey(120, 10)
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.StartHotkeyHook()
If ret = 1 Then
    ola.RegisterHotkey(120, 10, 0)
    ola.UnregisterHotkey(120, 10)
End If
text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.StartHotkeyHook ()
.如果真 (ret = 1)
    ola.RegisterHotkey (120, 10, 0)
    ola.UnregisterHotkey (120, 10)
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.StartHotkeyHook();
if(ret == 1){
    ola.RegisterHotkey(120, 10, function(k,m){return 0;});
    ola.UnregisterHotkey(120, 10);
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.StartHotkeyHook()
如果真 (ret = 1)
{
    ola.RegisterHotkey(120, 10, 0)
    ola.UnregisterHotkey(120, 10)
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int32_t ret = ola.StartHotkeyHook();
if (ret == 1) {
    ola.UnregisterHotkey(120, 10);
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
StartHotkeyHook(instance);
RegisterHotkey(instance, 120, 10, 0);
UnregisterHotkey(instance, 120, 10);
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 RegisterHotkey(long ola, int keycode, int modifiers, long callback);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int UnregisterHotkey(long ola, int keycode, int modifiers);

long instance = CreateCOLAPlugInterFace();
StartHotkeyHook(instance);
RegisterHotkey(instance, 120, 10, 0);
UnregisterHotkey(instance, 120, 10);
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
StartHotkeyHook(instance);
RegisterHotkey(instance, 120, 10, 0);
UnregisterHotkey(instance, 120, 10);

返回值

返回值说明
1成功。
0失败。