Loading ...
Sorry, an error occurred while loading the content.

7970RE: [ydn-javascript] KeyListener problems

Expand Messages
  • Steven Peterson
    Dec 29, 2006
    • 0 Attachment

      In your function, e does not represent an event, so using the Event utility against it will not work. KeyListener uses a CustomEvent, so the arguments are (type, args, obj), so you should look in the args array to get both the DOM event (the first arg) and the code for the key that was pressed (the second arg). When you pass your handler to the KeyListener, it is subscribed to the internal “keyEvent” CustomEvent, and all of the abstract differences between keyCode and charCode are handled under the hood.

       

      Steven Peterson

      Web Developer, Platform Engineering

      Yahoo!

       

       

       

      From: ydn-javascript@yahoogroups.com [mailto:ydn-javascript@yahoogroups.com] On Behalf Of itsallaboutyui
      Sent: Friday, December 29, 2006 3:36 PM
      To: ydn-javascript@yahoogroups.com
      Subject: [ydn-javascript] KeyListener problems

       

      I have an object containing the following code

      var kl2 = new YAHOO.util.KeyListener(document, {
      keys:[74,175,170,171,172,174,176] },
      {
      fn:this.kp},correctScope:true } );
      kl2.enable();

      //this.kp is a function within the object which calls
      kp : function(e){

      YAHOO.log('pressed: ' + $E.getCharCode(e));
      }

      but the charCode is always 0. I'm stumped. 74 is a keypress for J.

    • Show all 7 messages in this topic