Skip to content

Instantly share code, notes, and snippets.

@ccondry
Created May 2, 2016 22:07
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 ccondry/327ca0947848c7a4326f1803d9fa6622 to your computer and use it in GitHub Desktop.
Save ccondry/327ca0947848c7a4326f1803d9fa6622 to your computer and use it in GitHub Desktop.
Detect keypress for keyboard combination CTRL + any key.
/*
Originally from http://www.gmarwaha.com/blog/2009/06/16/ctrl-key-combination-simple-jquery-plugin/
*/
$.ctrl = function(key, callback, args) {
$(document).keydown(function(e) {
if(!args) args=[]; // IE barks when args is null
if(e.keyCode == key.charCodeAt(0) && e.ctrlKey) {
callback.apply(this, args);
return false;
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment