Call directly when using:
JQuery (document). bind ('keylow', 'k', function (evt ){
// Write the function code executed by pressing the shortcut key here
});
The complete code is as follows:
/*
* JQuery Hotkeys Plugin
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Based upon the plugin by Tzury Bar Yochay:
* Http://github.com/tzuryby/hotkeys
*
* Original idea:
* Binny v a, http://www.openjs.com/scripts/events/keyboard_shortcuts/
*/
(Function (jQuery ){
JQuery. hotkeys = {
Version: "0.8 ",
SpecialKeys :{
8: "backspace", 9: "tab", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause ",
20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home ",
37: "left", 38: "up", 39: "right", 40: "down", 45: "insert", 46: "del ",
96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7 ",
104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110 :". ", 111 :"/",
112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8 ",
120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 191: "/", 224: "meta"
},
ShiftNums :{
"'":"~ "," 1 ":"! "," 2 ":" @ "," 3 ":" # "," 4 ":" $ "," 5 ":" % "," 6 ": "^", "7 ":"&",
"8": "*", "9": "(", "0": ")", "-": "_", "=": "+ ", ";": ":", "'": "\" ",", ":" <",
".": "> ","/":"? "," \ ":" |"
}
};
Function keyHandler (handleObj ){
// Only care when a possible input has been specified
If (typeof handleObj. data! = "String "){
Return;
}
Var origHandler = handleObj. handler,
Keys = handleObj. data. toLowerCase (). split ("");
HandleObj. handler = function (event ){
// Don't fire in text-accepting inputs that we didn't directly bind
If (this! = Event.tar get & (/textarea | select/I. test (event.tar get. nodeName) |
Event.tar get. type = "text ")){
Return;
}
// Keypress represents characters, not special keys
Var special = event. type! = "Keypress" & jQuery. hotkeys. specialKeys [event. which],
Character = String. fromCharCode (event. which). toLowerCase (),
Key, modif = "", possible = {};
// Check combinations (alt | ctrl | shift + anything)
If (event. altKey & special! = "Alt "){
Modif + = "alt + ";
}
If (event. ctrlKey & special! = "Ctrl "){
Modif + = "ctrl + ";
}
// TODO: Need to make sure this works consistently implements SS platforms
If (event. metaKey &&! Event. ctrlKey & special! = "Meta "){
Modif + = "meta + ";
}
If (event. shiftKey & special! = "Shift "){
Modif + = "shift + ";
}
If (special ){
Possible [modif + special] = true;
} Else {
Possible [modif + character] = true;
Possible [modif + jQuery. hotkeys. shiftNums [character] = true;
// "$" Can be triggered as "Shift + 4" or "Shift + $" or just "$"
If (modif = "shift + "){
Possible [jQuery. hotkeys. shiftNums [character] = true;
}
}
For (var I = 0, l = keys. length; I <l; I ++ ){
If (possible [keys [I]) {
Return origHandler. apply (this, arguments );
}
}
};
}
JQuery. each (["keydown", "keyup", "keypress"], function (){
JQuery. event. special [this] = {add: keyHandler };
});
}) (JQuery );
Excerpted from code swallowed