Home > SYS_ShortcutKey > registerShortcutKey
SYS_ShortcutKey.registerShortcutKey() method
This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Warning: This API is now obsolete.
since EDA v4.2
Register shortcut key
Signature
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
Parameters
Parameter | Type | Description |
|---|---|---|
shortcutKey | Shortcut key. If the array contains multiple elements, it is parsed as a combined shortcut key and sorted by rules before being stored in the cache | |
title | string | Shortcut key title, the friendly name of the shortcut key |
callbackFn | (shortcutKey: TSYS_ShortcutKeys) => void | Promise<void> | Callback function |
documentType | (Optional) | |
scene | (Optional) |
Returns
Promise<boolean>
Register whether the operation is successful
Example
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