iceshrimp-161sh/packages/client/src/scripts/keycode.ts

36 lines
713 B
TypeScript
Raw Normal View History

2018-09-18 05:34:41 +02:00
export default (input: string): string[] => {
2023-01-13 05:40:33 +01:00
if (
Object.keys(aliases).some((a) => a.toLowerCase() === input.toLowerCase())
) {
2018-09-18 05:34:41 +02:00
const codes = aliases[input];
return Array.isArray(codes) ? codes : [codes];
} else {
return [input];
}
};
export const aliases = {
2023-01-13 05:40:33 +01:00
esc: "Escape",
enter: ["Enter", "NumpadEnter"],
up: "ArrowUp",
down: "ArrowDown",
left: "ArrowLeft",
right: "ArrowRight",
plus: ["NumpadAdd", "Semicolon"],
};
/*!
2023-01-13 05:40:33 +01:00
* Programatically add the following
*/
// lower case chars
for (let i = 97; i < 123; i++) {
2018-09-18 05:34:41 +02:00
const char = String.fromCharCode(i);
aliases[char] = `Key${char.toUpperCase()}`;
}
// numbers
2018-09-18 05:34:41 +02:00
for (let i = 0; i < 10; i++) {
aliases[i] = [`Numpad${i}`, `Digit${i}`];
}