Event Listener - problem listening to key combinations

C

carlos

The below code listens to key combinations in my app. I am using
prototype (not my decision), but I am open to using other
alternatives. The problem i'm having is that when using Event.observe
to listen for key combinations it doesn't always catch my key strokes.
If I press on one of the tabs in my app, it listens again. These tabs
represent the content pages in my app, which are dynamically
generated, and are iframe elements. I believe that has
somethign to do with it, but i'm not familiar with prototype or the
Event Model all that much. Any help would be appreciated! See my code
example below.

Event.observe(window, 'load', function() {
Event.observe(document, 'keypress', function(e){


//listen for key events
var targ = e ? e : window.event;
key = targ.keyCode ? targ.keyCode : targ.charCode;


//handle combination
if(targ.altKey == true && (key == 67)) {
HandleEvent(key);
}


});
 

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,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top