BlogjQuery Plugin: Keycode jQuery Plugin

Sick of looking up what the charcode for escape is so that you can close your dialog box with escape. Well I have the perfect medicine, a new plugin called Keycodes.

Functions Added

$.charcode

$.charcode(input, returnInt = false)

Returns: mixed, if returnInt is false, this returns a string containing the English version of the keycode (‘alt’ instead of 18)

input mixed

This can be an integer containing a keycode, a string containing a keycode or an event object.

returnInt boolean
If this is true, input should be a string that contains the name of a key (ex: ‘alt’). This will return the keycode for the key specified in input.

$.isKey

$.isKey(e, input)

Returns: boolean, if e is one of the keys listed in input then it returns true. Otherwise it returns false.

e mixed

This is either a keycode, or an event object.

input mixed

This should be a comma seperated list of keys (ex: alt,tab,escape) or a Javascript object containing the keys (ex: {‘alt’,'tab’,'escape’})

Examples

$('#exampleSearch').keyup(function (e) {
     $('#oupt').html('');
     $('#oupt').append('You pressed: '+$.charcode(e)+', which is keycode: '+(e.keyCode ? e.keyCode : e.which));
     $('#oupt').append("\nThe key alt is keyCode: "+$.charcode('alt', true));
     if($.isKey(e,'a,b,c,d'))
           $('#oupt').append("\nYou pressed A, B, C or D");
});

Try it!

Download

Download!

Related PostsExtra Credit Reading.

Related posts:

  1. jQuery Plugin: Tooltips
  2. jQuery Plugin: Tooltips Revisited

What others saidComments. (2)

  1. Lu November 16, 2009

    Hi, the German Umlaute like ä ö ü do not work in Firefox 3.5.5 on Mac OS X 10.6. KeyCode is undefined/0. This seems to be a common problem. Any idea how to fix this?

  2. Ramblingwood November 24, 2009

    Sorry for my delay, Wordpress wasn’t emailing me with comments.

    As, an English speaker, I didn’t even think of this.

    How do you input an umlauted u, a or o? If it requires more than one keystroke, the way plugin picks up the characters won’t work here.

    Can you give me the steps to reproduce?

    I have also emailed you to make sure you are notified of this.

Leave Your MarkComment.