Onkeydown Event Not Working On Canvas?
I've got a canvas and an onkeydown event assigned to it. When any key is pressed, the console is supposed to log the keyCode of the key. But it's not outputting anything, not even
Solution 1:
Instead if using canvas.onkeydown
use window.onkeydown
otherwise you will need to focus on to the canvas for it to work.
window.onkeydown = function() {};
Attaching to the canvas element will only work if your focused in on that element. The window object is the whole browser.
Post a Comment for "Onkeydown Event Not Working On Canvas?"