DWQA QuestionsCategory: ProgramAbout delays in keydown?
Du grassland asked 4 weeks ago

Keyboard keys are held down and Keydown events are triggered repeatedly.
But there seems to be a clear time interval between the first trigger of Keydown and the subsequent repeated trigger.

document.body.addEventListener("keydown",function(){
    console.time("keydown");
    console.timeEnd("keydown");
})

About delays in keydown?
After the first trigger, it will take about half a second to execute again.
Previously thought it was browser differences, but it was still the same with multiple browsers.
How to solve it?

2 Answers
Best Answer
eph answered 4 weeks ago

Operating system is designed to trigger for the first time for a period of time to trigger continuously, so as to avoid two characters when you want to type a character. If it’s Windows, it’s corresponding.Control Panel Keyboard Properties Repetitive DelayThe settings are set, but the interval between the first settings is longer than the later settings anyway.

eph replied 4 weeks ago

You can change the way Keydown starts moving and Keyup stops moving.

dctxf answered 4 weeks ago

It’s estimated that it’s related to computer performance. I’ve always been 0.003ms.