Skip to content

Instantly share code, notes, and snippets.

@jswanner
Created June 13, 2014 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jswanner/9d074601ce72922f025b to your computer and use it in GitHub Desktop.
Save jswanner/9d074601ce72922f025b to your computer and use it in GitHub Desktop.
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