Workshop › Simon Says Colors › Step 17 of 27
Q W on the top row and A S below mirror the pads; 1 to 4 work too. A lookup table, KEYS, turns a key name into a pad
number, and a keydown listener presses that pad.
```js
const KEYS = { q: 0, w: 1, a: 2, s: 3, 1: 0, 2: 1, 3: 2, 4: 3 }
document.addEventListener('keydown', (event) => {
if (event.repeat) return
if (event.key in KEYS) press(KEYS[event.key])
})
```KEYS is an object used as a lookup table: key name → pad number.keydown fires when a key goes down; event.key is its name, like 'w'.keydowns with event.repeat true; we ignore those.event.key in KEYS asks whether the table has that key; KEYS[event.key] reads its pad number.PADS, write KEYS.press, leave an empty line and write the keydown listener.Skills: Keyboard and mouse input
← Check each press Which pad is at a point? →