jquery.isKey

Add life to the keyboard, because not everyone uses a mouse. Here's a set of lightweight utility functions used for determining which key triggered a jQuery event.

GitHub Project

The Idea

Making sure the web isn't only accessible using the mouse is a critical aspect of universal web accessibility—expected and intuitive keyboard navigation is a must. HTML provides standard keyboard interaction for elements like <a>, <button>, and <input>. However, sometimes there are there are circumstances which require you to develop around the keyboard:

The Keys

I decided to to write these utility functions, because I found myself copying the same code from project to project:
function name returns true for e.which
isEnterKey 13
isDownArrowKey 40
isUpArrowKey 38
isRightArrowKey 39
isLeftArrowKey 37
isEndKey 35
isHomeKey 36

Using isKey

The following example is a code snippet from a Google Maps CodePen that uses $.isKey functions to make Google Maps API keyboard accessible. Simply pass the jQuery event into any of the functions.
$map.on('keydown', function(evt) {
                 if ($.isDownArrowKey(evt)) {
                  $panDown.click();
                  return false;
                 } else if ($.isUpArrowKey(evt)) {
                  $panUp.click();
                  return false;
                 } else if ($.isLeftArrowKey(evt)) {
                  $panLeft.click();
                  return false;
                 } else if ($.isRightArrowKey(evt)) {
                  $panRight.click();
                  return false;
                 }
                });