Skip to content

Instantly share code, notes, and snippets.

@ova2
Last active January 12, 2025 19:54
Show Gist options
  • Save ova2/24c364e3f0799ece554779d5c8f935ac to your computer and use it in GitHub Desktop.
Save ova2/24c364e3f0799ece554779d5c8f935ac to your computer and use it in GitHub Desktop.
export class ShortcutKey {
static readonly A = new ShortcutKey('KeyA');
static readonly B = new ShortcutKey('KeyB');
...
static readonly Digit0 = new ShortcutKey('Digit0');
static readonly Digit1 = new ShortcutKey('Digit1');
...
static readonly F1 = new ShortcutKey('F1');
static readonly F2 = new ShortcutKey('F2');
...
static readonly AltLeft = new ShortcutKey('AltLeft');
static readonly AltRight = new ShortcutKey('AltRight');
static readonly ShiftLeft = new ShortcutKey('ShiftLeft');
static readonly ShiftRight = new ShortcutKey('ShiftRight');
static readonly CtrlLeft = new ShortcutKey('ControlLeft');
static readonly CtrlRight = new ShortcutKey('ControlRight');
static readonly ArrowRight = new ShortcutKey('ArrowRight');
static readonly ArrowUp = new ShortcutKey('ArrowUp');
static readonly ArrowLeft = new ShortcutKey('ArrowLeft');
static readonly ArrowDown = new ShortcutKey('ArrowDown');
static readonly Delete = new ShortcutKey('Delete');
static readonly Home = new ShortcutKey('Home');
...
/**
* The following shortcuts are for convenience. They allow to reduce registering
* shortcuts for left and right keys on keyboard. For instance, instead of registering
* [AltLeft, another key, ...] + [AltRight, another key, ...], you can write
* [Alt, another key, ...], regardless which Alt key was pushed.
*/
static readonly Alt = new ShortcutKey(['AltLeft', 'AltRight']);
static readonly Ctrl = new ShortcutKey(['ControlLeft', 'ControlRight']);
static readonly Shift = new ShortcutKey(['ShiftLeft', 'ShiftRight']);
static readonly Meta = new ShortcutKey(['MetaLeft', 'MetaRight']);
// private to disallow creating other instances of this type
private constructor(public readonly keyCode: string | string[]) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment