How addEventListener works for keydown on HTML 5 Canvas ?
The canvas needs to be in focus on to catch key events. It is not possible to assign the keydown event to canvas because it is not possible to focus the canvas with the cursor. So, a workaround for this problem is to bring the canvas to focus.
Below example illustrates the working approach of addEventListner for keydown on canvas:
Output: First, the canvas is brought to focus on using the mousedown event. After the canvas is brought to focus, the keydown event is fired.