From f6154dc0af1a0d65819e87240f4385f9573095cb Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 30 Jan 2020 04:37:25 +0900 Subject: v12 (#5712) Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com> --- src/client/scripts/keycode.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/client/scripts/keycode.ts (limited to 'src/client/scripts/keycode.ts') diff --git a/src/client/scripts/keycode.ts b/src/client/scripts/keycode.ts new file mode 100644 index 0000000000..5786c1dc0a --- /dev/null +++ b/src/client/scripts/keycode.ts @@ -0,0 +1,33 @@ +export default (input: string): string[] => { + if (Object.keys(aliases).some(a => a.toLowerCase() == input.toLowerCase())) { + const codes = aliases[input]; + return Array.isArray(codes) ? codes : [codes]; + } else { + return [input]; + } +}; + +export const aliases = { + 'esc': 'Escape', + 'enter': ['Enter', 'NumpadEnter'], + 'up': 'ArrowUp', + 'down': 'ArrowDown', + 'left': 'ArrowLeft', + 'right': 'ArrowRight', + 'plus': ['NumpadAdd', 'Semicolon'], +}; + +/*! +* Programatically add the following +*/ + +// lower case chars +for (let i = 97; i < 123; i++) { + const char = String.fromCharCode(i); + aliases[char] = `Key${char.toUpperCase()}`; +} + +// numbers +for (let i = 0; i < 10; i++) { + aliases[i] = [`Numpad${i}`, `Digit${i}`]; +} -- cgit v1.2.3-freya