Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.