JSFiddle - React, Tailwind, and code Playground
by AustinBrunkhorst
HTML
<canvas id="canvas"></canvas>
CSS
#canvas {
background: red;
width: 100px;
height: 100px;
}
JavaScript
var lastDownTarget, canvas;
window.onload = function() {
canvas = document.getElementById('canvas');
document.addEventListener('mousedown', function(event) {
lastDownTarget = event.target;
alert('mousedown');
}, false);
document.addEventListener('keydown', function(event) {
if(lastDownTarget == canvas) {
alert('keydown');
}
}, false);
}