[Project_owners] capturing keypress and handing to default listener

Eric H. Jung eric.jung at yahoo.com
Mon Sep 25 15:40:52 EDT 2006


Hi,

I capture keypress events in a dialog. If the keypress is a number, my listener performs an action. If it's not a number, I want the default keypress event listener to process the event. No matter what I've tried, I can't get the default event listener to process the event once my listener has the keypress.

I've tried window.addEventListener("myListener", onKeyPress, false), window.addEventListener("myListener", onKeyPress, true) where myListener is:

function myListener(evt) {
   if (!isNaN(evt.charCode)) { // if user typed a number, select the corresponding tree row
      var row = parseInt(evt.charCode-KeyboardEvent.DOM_VK_0)-1;
      row <= accountsTree.view.rowCount-1 && accountsTree.view.selection.select(row);
  // Shouldn't other event listeners now be called?
}

I've also tried the non-DOMEvent way:

var origOnKeyPress;
function onLoad() {
  origOnKeyPress = window.keypress;
  window.onKeyPress = myListener;
}

function myListener(evt) {
    if (!isNaN(evt.charCode)) { // if user typed a number, select the corresponding tree row
      var row = parseInt(evt.charCode-KeyboardEvent.DOM_VK_0)-1;
      if (row <= accountsTree.view.rowCount-1)
          accountsTree.view.selection.select(row);
      else
          origOnKeyPress(evt);
    }
     else
          origOnKeyPress(evt);    
}

Thanks for any ideas,
Eric




More information about the Project_owners mailing list