Need to check that eventTrap is a direct child of canvasElement first ("if (eventTrap.parentNode === canvasElement)")... or, if there is no harm, at least a comment would be good. Due to interactions with the IME, it is not valid to assume eventTrap is always directly below the canvas.