Robust JavaScript manipulation

What is the most reliable way to create a global keyboard shortcut handler for a web application using JavaScript, that is, which event (s) should handle and what should the event handler bind to?

I want something like a system in Gmail that can handle both individual shortcut keys and shortcuts with modifier keys, for example. Ctrl + B, etc. The code should work in IE 6, as well as in modern browsers.

I have a Prototype platform available for use, but not jQuery, so please do not respond to jQuery answers!

+5
source share
5 answers

The HotKey library, available in the LivePipe management pack, works with Prototype and is compatible with IE.

http://livepipe.net/extra/hotkey

+5
source

I just thought that I would throw another into the mix. I recently released a library called Mousetrap. Check it out at http://craig.is/killing/mice

+6
source

, onKeyUp document.body. Element.fire . , , , , .

$(document.body).observe("keyup", function() {
    if(/* key + modifier match */) {
        $(document.body).fire("myapp:mycoolevent");
    }
});

$(document.body).observe("myapp:mycoolevent", function() {
    // Handle event.
});

, :

$(button).observe("click", function() {
    $(document.body).fire("myapp:mycoolevent");
});

-, ( , - ) .

+3

There is also a new JavaScript library called jwerty , it is easy to use and does not rely on jQuery.

+2
source

All Articles