Thursday 15 May 2014

javascript - addEventListener keydown not working -


I made some basic pong codes available on the Internet and tried to add keypresses, the code is here:

I added it:

  canvas.addEventListener ("keydown", hand button, true);   

After this current code:

  canvas.addEventListener ("mousemove", trackPosition, true); Canvas.addEventListener ("Masudown", BTNClick, True);   

And I also added:

  Function HandleDown (e) {console.log ("debug"); Console.log ("keycode:" + e.keycode); }   

But the function is never called even though I try to press on different keys, why is it so? I'm pretty sure the canvas is in focus.

You can not assign events in the canvas because you cursor with cursor Can not focus on You will need to assign an event to the window:

  window.addEventListener ("keydown", handle, true);    

No comments:

Post a Comment