summaryrefslogtreecommitdiff
path: root/packages/client/src/scripts/keycode.ts
blob: 69f6a82803470349e148609354f221af166260fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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'],
};

/*!
* Programmatically 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}`];
}