Skip to content

Instantly share code, notes, and snippets.

@SilencerWeb
Created October 26, 2018 11:23
Show Gist options
  • Save SilencerWeb/9ac5d670f03045147767b9fb8515b77c to your computer and use it in GitHub Desktop.
Save SilencerWeb/9ac5d670f03045147767b9fb8515b77c to your computer and use it in GitHub Desktop.
handleKeyUp = (e) => {
let shortcut = '';
let modifiersCount = 0;
if (e.ctrlKey) {
shortcut += 'Ctrl ';
modifiersCount++;
}
if (e.metaKey) {
shortcut += 'Command ';
modifiersCount++;
}
if (e.shiftKey) {
shortcut += 'Shift ';
modifiersCount++;
}
if (e.altKey) {
shortcut += 'Alt ';
modifiersCount++;
}
shortcut += e.key;
shortcut = shortcut.split(' ').join('+');
if (modifiersCount === 0 || modifiersCount > 2) return;
if (e.keyCode < 65 || e.keyCode > 90) return;
console.log('valid shortcut');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment