Workshop › Typing Rain › Step 12 of 33
Every key from a to z, small or capital, goes to type. Other keys (Shift, arrows, numbers) are ignored.
```js
document.addEventListener('keydown', (event) => {
const key = event.key.toLowerCase()
if (key.length === 1 && key >= 'a' && key <= 'z') {
event.preventDefault()
type(key)
}
})
```keydown runs the arrow function every time a key goes down; event.key is its name ('c', 'Shift',
'ArrowUp')..toLowerCase() makes capitals small. A letter is one character long and between 'a' and 'z'.preventDefault() stops the browser's own action for that key.Write the listener above function draw() { (under update), with an empty line after it.
Skills: Keyboard and mouse input
← Lock on to a word Letter by letter →