Skip to content

Instantly share code, notes, and snippets.

@rasy-js
Last active March 2, 2018 13:06
Show Gist options
  • Save rasy-js/54466d82f69359f06a72b77bd76d7760 to your computer and use it in GitHub Desktop.
Save rasy-js/54466d82f69359f06a72b77bd76d7760 to your computer and use it in GitHub Desktop.
keypress calback (ctrl+enter)
(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