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

YAHOO.util.KeyListener doesn't fire key up on ctrl key?

Expand Messages
  • w.davidow
    I m messing around with some code to trap ctrl key presses and i m unable to trap the keyup event for the ctrl key... here is the code I ve got:
    Message 1 of 1 , Oct 1, 2008
    • 0 Attachment
      I'm messing around with some code to trap 'ctrl' key presses and i'm
      unable to trap the keyup event for the ctrl key... here is the code
      I've got:

      YAHOO.examples.ctrlListener = {
      init: function() {
      var dn = new YAHOO.util.KeyListener(document, {keys: 17},
      this.handleKeyDown, YAHOO.util.KeyListener.KEYDOWN);
      dn.enable();
      var up = new YAHOO.util.KeyListener(document, {keys: 17},
      this.handleKeyUp, YAHOO.util.KeyListener.KEYUP);
      up.enable();
      },
      handleKeyDown: function(e) {
      alert('ctrl down');
      },
      handleKeyUp: function(e) {
      alert('ctrl up');
      }
      };


      the handleKeyDown method works fine and alerts when the ctrl key (17)
      is pressed, but the up even does not work. but if i switch keys {keys:
      49} (the '1' key) it works for both.

      is this a bug? I also created the following code to see if there just
      is no key up event that gets fired for the ctrl key, but that's not
      the case - this works perfectly:


      YAHOO.examples.ctrlListener = {
      init: function() {
      Event.on(document, "keydown", this.handleKeyDown, this, true);
      Event.on(document, "keyup", this.handleKeyUp, this, true);
      },
      handleKeyDown: function(e) {
      var kc = Event.getCharCode(e);
      if(kc == '17') { // ctrl
      alert('down');
      }
      },
      handleKeyUp: function(e) {
      var kc = Event.getCharCode(e);
      if(kc == '17') { // ctrl
      alert('up')
      }
      }
      };
    Your message has been successfully submitted and would be delivered to recipients shortly.