Created
March 30, 2020 11:48
-
-
Save oboshto/05c556b322fe8c44fde3c01881e90def to your computer and use it in GitHub Desktop.
Keydown hanlder for multikeys pressed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('keydown', multiKeyHandler) | |
const keyMap = {} | |
function multiKeyHandler (e) { | |
if (e.ctrlKey) { | |
keyMap['ctrlKey'] = clearTimeout() | |
keyMap['ctrlKey'] = setTimeout(() => delete keyMap['ctrlKey'], 1500) | |
} | |
if (e.altKey) { | |
keyMap['altKey'] = clearTimeout() | |
keyMap['altKey'] = setTimeout(() => delete keyMap['altKey'], 1500) | |
} | |
if (e.code === 'KeyV') { | |
keyMap['v'] = clearTimeout() | |
keyMap['v'] = setTimeout(() => delete keyMap['v'], 1500) | |
} | |
if (e.code === 'KeyR') { | |
keyMap['r'] = clearTimeout() | |
keyMap['r'] = setTimeout(() => delete keyMap['r'], 1500) | |
} | |
if (keyMap['ctrlKey'] && keyMap['altKey'] && keyMap['v'] && keyMap['r']) { | |
Object.keys(keyMap).forEach(key => { | |
keyMap[key] = clearTimeout() | |
}) | |
// KEYS CTRL+ALT+V+R pressed together | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment