I am building a browser interface to a terminal. I need to catch both character (alphanumeric, dot, slash,…) and non-character key presses (arrows, F1-F12,…). Also, if the user holds some key down, it would be nice to get repeated keypresses (the function should be called repeatedly until key is released). The same goes for space key, characters,…
I want this to be as cross-browser as possible (jQuery keypress fails on that account). I have also tried using fork of jquery.hotkeys.js, but if I understand correctly, I can’t catch both special and character keys in a single function (one should use keydown for former and keydown for the latter).
Is there a JS library that would allow me to catch both character and special keys?
I hope I’m not missing something obvious. 🙂
UPDATE To clarify: I am looking for the library that would hide the browser implementation details from me.
I ended up using keycode.js, but am building a whole event-managing system around keydown, keypress and keyup events, because just one of the events (keydown) is not enough to determine which character was entered and which key was pressed if there is no corresponding character. Browser incompatibilities are an added bonus to this challenge. 🙂
Thank you both for your answers, it has helped me understand the problem fully.