[Project_owners] capturing keypress and handing to default listener

HJ van Rantwijk bugs4hj at aim.com
Mon Sep 25 17:16:29 EDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Eric H. Jung wrote:
> 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 use onkeydown and onkeyup and that works for me in five managers.

window.document.addEventListener("keydown", keydownHandler, false);
window.document.addEventListener("keyup", keyupHandler, false);

keyupHandler(aEvent) {
  if (aEvent.keyCode == aEvent.DOM_VK_ESCAPE)
    callFunction();
}

> 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
> 
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFGGNNRrb6S73JMeYRApUSAJ0WxutZ3qtI1qYYX/b45Lsob/ugMQCgyAf6
Gizbsy7we6ps54sCf/KLiJg=
=sbyW
-----END PGP SIGNATURE-----


More information about the Project_owners mailing list