Strange behavior of javascript events after pressing two keys at the same time -


i'm coding little javascript app , need control screen events (images appearance). example if image_1 appear on screem need press 1 key (for example right arrow) , if image_2 appear need press key (for instance left arrow). if both of them appear @ same time need press both keys.

the problem if press both keys @ same time, no more key events launched, mean when next image appear press key there not javascript event.

i make code simple try:

<html lang="es">   <head>     <meta charset="utf-8">     <title>test1</title>     <script>      function adde () {         if (document.addeventlistener)  {// standard w3c                 document.addeventlistener("keydown",test1,false);         }     }      // ejemplo equivalente para quitar el evento     function removee () {         if (document.removeeventlistener)  {// standard w3c dom                 document.removeeventlistener("keydown",test1,false);          }     }       function test1 (e) {         alert('test');         if (!e) var e = window.event;         switch (e.keycode) {             case 39:                alert(e.keycode);             break;             case 37:                 alert(e.keycode);             break;             default:               alert(e.keycode);         }     }       window.onload = function() {         adde();         alert('listener added');     }      </script>   </head> <body>  </body> </html> 

thanks in advance

as gonçalo vieira , andy e suggested me, problem no code debugging alert using. when changed better debuggin solution, console.log(), worked ok


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -