jQuery Keyz Plugin

February 24, 2010 in jQuery Plugins

The purpose of this plugin is to easily facilitate the end user to create and hook key presses for their own use. Usually you would need to know what key links with which keycode etc.

Usage

It’s as easy as these steps:

  1. Include jquery – either from CDN or local source
  2. Include jquery.keyz.js
  3. call the following within your document ready or after the item exists
$('selector').keyz({
"enter": function(ctl,sft,alt,event) {
alert('you pressed enter!');
}
});

this will hook the enter key and raise an alert when pressed.

If you want to cancel the key either return false from the function or set the value to false like so:

$('selector').keyz({
"enter": function(ctl,sft,alt,event) {
return false;
}
});

OR

$('selector').keyz({
"enter":false
});

You can either use the key names in singular or in a grouping like so:

$('selector').keyz({
"enter": function(ctl,sft,alt,event) {
/* single key */
return false;
},
"F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12": function(ctl,sft,alt,event) {
/* mapped to all F-Keys */
return false;
}
});

Download jquery.keyz.js here: Full Source && Google Closure Compiled version

Visit the demo page here: Full Source

Planned Features

  • support for keypress chains .. passing a sequence of keys and an event firing upon completion
  • support for all three key states – presently only triggers on key down – Added in 1.0.2
  • to add some duck punching to add the keyname to the event for the three standard events

Supported Keys

The keys listed below are the current ones supported by the plugin.
They also support the hyphenated name eg numpad-1 or in upper case like “F1″ or “f1″

  • enter
  • return
  • esc
  • escape
  • numerics
  • upper
  • lower
  • alphanumeric
  • tab
  • shift
  • alt
  • ctrl
  • f1
  • f2
  • f3
  • f4
  • f5
  • f6
  • f7
  • f8
  • f9
  • f10
  • f11
  • f12
  • caps
  • capslock
  • numlock
  • winflag
  • winkey
  • windows
  • scrolllock
  • left
  • up
  • right
  • down
  • volumeup
  • volumedown
  • menu
  • contextmenu
  • backspace
  • pause
  • break
  • pausebreak
  • pageup
  • pagedown
  • end
  • home
  • insert
  • del
  • delete
  • numpad0
  • numpad1
  • numpad2
  • numpad3
  • numpad4
  • numpad5
  • numpad6
  • numpad7
  • numpad8
  • numpad9
  • *
  • multiply
  • +
  • add
  • -
  • subtract
  • .
  • fullstop
  • decimal
  • /
  • divide
  • ;
  • semicolon