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!
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!