Workshop › Typing Rain › Step 32 of 33

Tap the keys

What we are doing

A tap on a key calls the same type(key) as the real keyboard, so every rule works the same on both. After the game, a tap plays again.

```js
canvas.addEventListener('pointerdown', (event) => {
  const rect = canvas.getBoundingClientRect()
  const x = ((event.clientX - rect.left) * canvas.width) / rect.width
  const y = ((event.clientY - rect.top) * canvas.height) / rect.height
  if (state === 'over') return reset()
  ROWS.forEach((keys, row) => {
    for (let i = 0; i < keys.length; i++) {
      const k = keyRect(row, i)
      if (x >= k.x && x < k.x + KEY_W && y >= k.y && y < k.y + KEY_H) type(keys[i])
    }
  })
})

    ctx.fillText('Press Enter or tap to play again', canvas.width / 2, 205)
```

What it means

Your turn

  1. Above function draw() { write the pointerdown listener, with an empty line after it.
  2. Change the last panel text to 'Press Enter or tap to play again'.

Skills: Keyboard and mouse input

All steps

  1. A sky for the words
  2. The ground
  3. A word on the canvas
  4. A function that draws
  5. A list of words
  6. Make them fall
  7. The game loop
  8. A new word from the list
  9. Let it rain
  10. Gone past the ground
  11. Lock on to a word
  12. Listen to the keyboard
  13. Letter by letter
  14. Half a word in yellow
  15. Let go of a lost word
  16. Lives
  17. Hearts
  18. Score
  19. Out of lives
  20. Freeze the game
  21. The game over panel
  22. Play again
  23. Levels
  24. Faster and faster
  25. Best score
  26. Accuracy
  27. Words per minute
  28. Your speed at the end
  29. Where the keys go
  30. Draw the keyboard
  31. Light up the next key
  32. Tap the keys
  33. Build it yourself: change your mind