Seeking robust cross-browser keyboard event handler

M

Matt Kruse

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top