Seeking robust cross-browser keyboard event handler

Discussion in 'Javascript' started by Matt Kruse, Aug 15, 2006.

  1. Matt Kruse

    Matt Kruse Guest

    I am seeking an example of a robust keyboard-event-handling strategy that
    will work cross-browser and capture as many keys as possible.

    As most of you probably know, there are difficulties because some keys are
    captured onkeydown and some onkeypress, for example, and the codes returned
    by each may be different even for the same key. Further, mozilla browsers
    may return different values for keyCode and charCode. The problem has been
    identified in various web sites (like quirksmode) but I've not found a
    single approach which handles as many cases as possible.
    (For reference, I don't care to support ancient browsers like NN4)

    As an example, consider a textarea. I would like to be able to capture any
    key press, arrow press, tab, enter, escape, F1-F12 (if possible), etc. As an
    output, I just want the character pressed to be passed to a handling
    function - either "a" or "A" or "ESC" or "TAB" so that I can take action on
    that key.

    Does code already exist which handles as many conditions and
    browser-differences as possible? Keyboard event handling is not something
    I've ever ventured very far into, so I'm learning some of these quirks as I
    go...

    Thanks!

    --
    Matt Kruse
    http://www.JavascriptToolbox.com
    http://www.AjaxToolbox.com
     
    Matt Kruse, Aug 15, 2006
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    545
    S. Justin Gengo
    Nov 29, 2005
  2. Replies:
    1
    Views:
    940
    Damien
    Feb 22, 2007
  3. cjl
    Replies:
    1
    Views:
    241
  4. Replies:
    3
    Views:
    301
  5. Ciaran

    simple cross browser key handler

    Ciaran, May 21, 2007, in forum: Javascript
    Replies:
    0
    Views:
    149
    Ciaran
    May 21, 2007
  6. Ciaran

    Cross browser key handler?

    Ciaran, May 21, 2007, in forum: Javascript
    Replies:
    6
    Views:
    165
    Ciaran
    May 24, 2007
  7. Martin Rinehart

    Robust, Cross-Browser setAttribute()?

    Martin Rinehart, Nov 23, 2008, in forum: Javascript
    Replies:
    10
    Views:
    309
    Martin Rinehart
    Nov 25, 2008
  8. Gelonida N
    Replies:
    11
    Views:
    562
    Chris Angelico
    Jul 24, 2012
Loading...