Skip to content

Instantly share code, notes, and snippets.

@tctony
Created December 10, 2021 01:51
Show Gist options
  • Select an option

  • Save tctony/74011d54a99b40dde352c91da1a8c8da to your computer and use it in GitHub Desktop.

Select an option

Save tctony/74011d54a99b40dde352c91da1a8c8da to your computer and use it in GitHub Desktop.
// shift mapping for KeyboardEvent.key
const lowerToUpper: Record<string, string> = {};
for (let a = 'a'.charCodeAt(0); a <= 'z'.charCodeAt(0); a += 1) {
lowerToUpper[a] = String.fromCharCode(a).toUpperCase();
}
const ShiftMapping: Record<string, string> = {
'`': '~',
'1': '!',
'2': '@',
'3': '#',
'4': '$',
'5': '%',
'6': '&',
'7': '*',
'9': '(',
'0': ')',
'-': '_',
'=': '+',
...lowerToUpper,
'[': '{',
']': '}',
';': ':',
'\\': '|',
"'": '"',
',': '<',
'.': '>',
'/': '?',
};
const ShiftReversMapping = {
...Object.keys(ShiftMapping).reduce<typeof ShiftMapping>((result, key) => {
result[ShiftMapping[key]] = key;
return result;
}, {}),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment