Home > SYS_ShortcutKey > registerShortcutKey
SYS_ShortcutKey.registerShortcutKey() method
此 API 当前处于 BETA 预览状态,希望得到开发者的反馈。它的任何功能都可能在接下来的开发进程中被修改,请不要将它用于任何正式环境。
警告:此 API 现已弃用。
since EDA v4.2
注册快捷键
签名
typescript
function registerShortcutKey(
shortcutKey: TSYS_ShortcutKeys,
title: string,
callbackFn: (shortcutKey: TSYS_ShortcutKeys) => void | Promise<void>,
documentType?: Array<ESYS_ShortcutKeyEffectiveEditorRange>,
scene?: Array<ESYS_ShortcutKeyEffectiveEditorScene>,
): Promise<boolean>;1
2
3
4
5
6
7
2
3
4
5
6
7
参数名
参数 | 类型 | 描述 |
|---|---|---|
shortcutKey | 快捷键,数组中包含多个元素则解析为组合快捷键,将按规则排序后存入缓存 | |
title | string | 快捷键标题,快捷键的友好名称 |
callbackFn | (shortcutKey: TSYS_ShortcutKeys) => void | Promise<void> | 回调函数 |
documentType | (Optional) | |
scene | (Optional) |
返回值
Promise<boolean>
注册操作是否成功
示例
javascript
// 1. 注册冷门组合键 Ctrl+Alt+Shift+F9,避免占用常用键位
// documentType 传 2(原理图图页)与 4(PCB);scene 传 4(画布绘制)
const ok = await eda.sys_ShortcutKey.registerShortcutKey(
['CONTROL', 'ALT', 'SHIFT', 'F9'],
'嘉立创示例_演示快捷键',
(shortcutKey) => {
// 用户实际按键时才触发,自动化测试不按键,此处仅演示回调写法
console.log('快捷键被按下:', JSON.stringify(shortcutKey));
},
[2, 4],
[4]
);
console.log('注册快捷键返回:', ok);
// 2. 查询验证:新注册的快捷键出现在非系统快捷键列表中
const list = await eda.sys_ShortcutKey.getShortcutKeys();
const found = list.some(item => item.title === '嘉立创示例_演示快捷键');
console.log('已注册到快捷键列表:', found);
// 3. 反注册还原键位,保证案例可重复运行且不残留全局快捷键
const removed = await eda.sys_ShortcutKey.unregisterShortcutKey(['CONTROL', 'ALT', 'SHIFT', 'F9']);
console.log('反注册还原返回:', removed);1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22