How to combine pressing two keys at the same time to move diagonally?
Alas, the example below does not work.
let block = document.getElementById("test"); let left = 0; let top1 = 0; document.onkeydown = function(event) { if (event.key == "ArrowRight" && event.key == "ArrowUp") { block.style.left = left + "px"; block.style.top = top1 + "px"; top1--; left++; } }; #test { width: 50px; height: 50px; background: orange; position: absolute; left: 0; top: 0; } <div id="test"></div> Need a solution on pure js.
canvasyet, to give a specific example. But I saw an example where this is implemented ... - Air