Skip to content

Instantly share code, notes, and snippets.

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