script.jsconst range = (i, j) => [...Array(j + 1).keys()].slice(i, j + 1);
export const KEYCODE_MAP = {
Backspace:8,
Tab: 9,
Enter: 13,
Delete: 46,
Escape: 27,
' ': 32,
PageUp: 33,
PageDown: 34,
End: 35,
Home: 36,
ArrowLeft: 37,
ArrowUp: 38,
ArrowRight: 39,
ArrowDown: 40,
// alphabets
...Object.fromEntries(
range('a'.charCodeAt(0), 'z'.charCodeAt(0))
.flatMap((code, i) => [
[String.fromCodePoint(code), 65 + i],
[String.fromCodePoint(code).toUpperCase(), 65 + i],
])
),
// number
...Object.fromEntries([...Array(10).keys()].map(i => [i, i + 48])),
// function keys
...Object.fromEntries(range(1, 12).map(i => [`F${i}`, 112 + i])),
// 記号
':': 186, '*': 186,
';': 187, '+': 187,
'-': 189, '=': 189,
'.': 190, '>': 190,
'/': 191, '?': 191,
'@': 192, '`': 192,
'[': 219, '{': 219,
'\\': 220, '|': 220,
']': 221, '}': 221,
'^': 222, '~': 222,
'_': 226, // Shiftなしの226は\で、\と区別がつかない
};