Workshop › Wordle-style Word Guess › Step 21 of 26
A tap finds the key under the pointer in the same keyRects() list and types it. A tap anywhere else after the game
starts a new word.
```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
const hit = keyRects().find((k) => x >= k.x && x < k.x + k.w && y >= k.y && y < k.y + k.h)
if (hit) type(hit.key)
else if (state !== 'playing') reset()
})
```pointerdown fires for a mouse button or a finger.find returns the first key whose rectangle holds the point, or undefined.Above function draw() {, write the listener and leave an empty line. Press Run and tap the keys.
Skills: Keyboard and mouse input
← Draw the keyboard Enter and Delete keys →