'I have (if(e.repeat) return) in a function. I press+hold key1. No repeat. I press+hold key2. No repeat. I release key1. key2 repeats
I have a function called on keydown events.
I have if(e.repeat) return at the start of that function to prevent the rest of it running if I hold down a given key down.
So I press and hold key1. No repeat.
I press and hold key2. No repeat.
I release key1. Key2 repeats.
Also: I press and hold key1. No repeat.
I press and hold key2. No repeat.
I press and hold key3. No repeat.
I press and hold keys4 - 10 (because I only have 10 fingers) without releasing any of the keys. No repeats.
I release any of the keys. Key 10 repeats every time I release any other key.
Conversely, if I release key 10 before releasing any of the other keys: no repeat.
What's happening to make the last key that I press+hold to repeat when I release previously held keys and how do I stop it? I'm clearly missing something, but I have no idea what.
document.addEventListener('keydown', pressKey)
function pressKey(e) {
if (e.repeat) return
console.log(`press key ${e.key}`)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
