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. Advertising

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:
    755
    Damien
    Feb 22, 2007
  2. cjl
    Replies:
    1
    Views:
    153
  3. Martin Rinehart

    Robust, Cross-Browser setAttribute()?

    Martin Rinehart, Nov 23, 2008, in forum: Javascript
    Replies:
    10
    Views:
    221
    Martin Rinehart
    Nov 25, 2008
  4. Gelonida N
    Replies:
    11
    Views:
    468
    Chris Angelico
    Jul 24, 2012
  5. Jerry Hill
    Replies:
    0
    Views:
    207
    Jerry Hill
    Jul 24, 2012
Loading...

Share This Page