Created
June 13, 2014 19:34
-
-
Save jswanner/9d074601ce72922f025b to your computer and use it in GitHub Desktop.
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
var ctrlKey = 17, | |
ctrlDown = false, | |
vKey = 86, | |
allowCtrlPaste, | |
allowPaste, | |
captureCtrl, | |
releaseCtrl; | |
allowCtrlPaste = function(e){ | |
if (ctrlDown && e.keyCode == vKey) { | |
e.stopImmediatePropagation(); | |
return true; | |
} | |
}; | |
allowPaste = function(e){ | |
e.stopImmediatePropagation(); | |
return true; | |
}; | |
captureCtrl = function(e){ | |
if (e.keyCode == ctrlKey) { | |
ctrlDown = true; | |
} | |
}; | |
releaseCtrl = function(e){ | |
if (e.keyCode == ctrlKey) { | |
ctrlDown = false; | |
} | |
}; | |
document.addEventListener('keydown', allowCtrlPaste, true); | |
document.addEventListener('keydown', captureCtrl, true); | |
document.addEventListener('keyup', releaseCtrl, true); | |
document.addEventListener('paste', allowPaste, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment