Last active
March 2, 2018 13:06
-
-
Save rasy-js/54466d82f69359f06a72b77bd76d7760 to your computer and use it in GitHub Desktop.
keypress calback (ctrl+enter)
This file contains 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
(function() { | |
var k_a = []; | |
document.body.addEventListener('keydown', function(e) { | |
var k = e.keyCode; | |
// if esc | |
if (k == 27) { | |
// some act ... | |
} else { | |
if (k == 17) { | |
k_a[0] = k; | |
setTimeout(function() { | |
k_a = []; | |
}, 500); | |
} | |
// if ctrl+enter | |
if (k == 13 && k_a[0] == 17) { | |
// some act ... | |
console.log('pressed ctrl+enter'); | |
k_a = []; | |
} | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment