Workshop › Tetris-style Blocks › Step 12 of 32
The arrow keys move the piece left, right and down. Each is tryMove with a different (dx, dy). Afterwards we
redraw, because nothing redraws the screen by itself yet.
```js
document.addEventListener('keydown', (event) => {
if (event.key === 'ArrowLeft') tryMove(-1, 0)
if (event.key === 'ArrowRight') tryMove(1, 0)
if (event.key === 'ArrowDown') tryMove(0, 1)
draw()
})
```addEventListener('keydown', ...) runs the function every time a key goes down; event.key is its name.if checks one arrow and tries the matching move.draw() shows the result.Write the listener above function drawCell(, then Run, click the game and use the arrows.
Skills: Keyboard and mouse input
← Try, then move Turn a matrix →