Workshop › Connect Four › Step 16 of 38
The keyboard can play too: the left and right arrows move the next disc, and Space or Enter drops it.
```js
document.addEventListener('keydown', (event) => {
if (event.key === 'ArrowLeft') hoverCol = Math.max(0, hoverCol - 1)
if (event.key === 'ArrowRight') hoverCol = Math.min(COLS - 1, hoverCol + 1)
if (event.key === ' ' || event.key === 'Enter') {
event.preventDefault()
play(hoverCol)
}
})
```event.key is the name of the key: 'ArrowLeft', ' ' (Space), 'Enter'...hoverCol by one, kept between 0 and 6 with Math.max and Math.min.|| means "or". preventDefault() stops Space from scrolling the page.Under the pointerdown listener write the keydown listener.
Skills: Keyboard and mouse input