Event Listener - problem listening to key combinations

Discussion in 'Javascript' started by carlos, Feb 15, 2008.

  1. carlos

    carlos Guest

    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);
    }


    });
    carlos, Feb 15, 2008
    #1
    1. Advertising

  2. carlos

    Paul Wilkins Guest

    Paul Wilkins, Feb 16, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SaintSpeak

    how to add double key listener

    SaintSpeak, Dec 23, 2004, in forum: Java
    Replies:
    1
    Views:
    425
    ByteCoder
    Dec 23, 2004
  2. Jeremy Watts
    Replies:
    1
    Views:
    2,500
    John B. Matthews
    Feb 2, 2009
  3. KevinSimonson

    What Is the Listener for Key Presses?

    KevinSimonson, Nov 29, 2010, in forum: Java
    Replies:
    2
    Views:
    312
    Roedy Green
    Dec 2, 2010
  4. Mombiatch

    Determining which handlers are listening for an event

    Mombiatch, Jun 18, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    101
    DalePres
    Jun 19, 2004
  5. Mike Scirocco
    Replies:
    4
    Views:
    249
    Mike Scirocco
    Apr 5, 2007
Loading...

Share This Page