A jQuery plugin that will make you handle the keyboard like a Pro

easykey 1.0.0

easykey 1.0.0 minified

To use it, just add it after jQuery:

<script type="text/javascript" src="js/jquery-1.12.0.min.js"></script>
<script type="text/javascript" src="js/easykey-1.0.0.min.js"></script>	


Use left and right arrows to move between paged results


Press Control + S to save and on release print "saved" message

 .onSKeyDown(save, $.easyKey.options.withControlPressed)
 .onSKeyUp(displaySaved, $.easyKey.options.withControlPressed));

Handle F11 on an element with id="#myInput" while preventing the browser from going full screen

$('#myInput').onF11KeyDown(function(e) {
 //do something in response to F11 being pressed

 //prevent the browser from going full screen

 //prevent the event from bubbling up, 
 //if you want to do both, just return false;

Register an event handler for Control + Shift + S

 | $.easyKey.options.withShiftPressed);						

Find more examples here

List of the keys that have a KeyUp/KeyDown method

  • Backspace
  • Tab
  • Enter
  • Shift
  • Ctrl
  • Alt
  • PauseBreak
  • CapsLock
  • Escape
  • Space
  • PageUp
  • PageDown
  • End
  • Home
  • LeftArrow
  • UpArrow
  • RightArrow
  • DownArrow
  • Insert
  • Delete
  • 0 .. 9
  • A .. Z
  • LeftWindow
  • RightWindow
  • Select
  • Numpad0 .. Numpad9
  • Multiply
  • Add
  • Subtract
  • DecimalPoint
  • Divide
  • F1 .. F12
  • NumLock
  • ScrollLock
  • SemiColon
  • EqualSign
  • Comma
  • Dash
  • Period
  • ForwardSlash
  • GraveAccent
  • OpenBracket
  • BackSlash
  • CloseBraket
  • SingleQuote

NOTE: If you need to handle a key that is not in the list, you can do this:

$(document).onKey(keyCode, function(e) { /* handle key here*/ }, options);

Where keyCode is a key code number, or a member of $.easyKey.keyCodes (for example $.easyKey.keyCodes.F11)

options allows you to specify if you want to handle key down ($.easyKey.options.onKeyDown), key up ($.easyKey.options.onKeyUp) or require that Alt, Control or Shift is pressed along with the key.

Here's how you combine several options, for example to handle pressing Control + F:

$(document).onKey($.easyKey.keyCodes.f, function(e) {/* handle key here*/}, $.easyKey.options.onKeyDown | $.easyKey.options.withControlPressed);						

In this case, because F is in the list of the handled keys you can simply write:

$(document).onFKeyDown(function(e) {/* handle key here*/}, $.easyKey.options.withControlPressed);						

Find more examples here

Try it here: