From 7a8e2b2e4bcfb9a607bc853a4e07553a94720033 Mon Sep 17 00:00:00 2001 From: Lokesh Pathrabe Date: Wed, 2 Aug 2023 13:44:23 +0530 Subject: [PATCH] Add getAllKeyCodes method to API (#439) --- src/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/index.js b/src/index.js index 9cd697e..363c1b2 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,21 @@ function getPressedKeyString() { return _downKeys.map((c) => getKey(c) || getModifier(c) || String.fromCharCode(c)); } +function getAllKeyCodes() { + return [] + .concat(...Object.values(_handlers)) + .map(({ key, scope, mods, shortcut }) => { + return { + scope, + shortcut, + mods, + keys: key.split('+').map((k) => { + return code(k); + }), + }; + }); +} + // 表单控件控件判断 返回 Boolean // hotkey is effective only when filter return true function filter(event) { @@ -414,6 +429,7 @@ const _api = { getScope, deleteScope, getPressedKeyCodes, + getAllKeyCodes, isPressed, filter, trigger,