Pressing 2 keys, release 1, produces keydown of other key again

陌路散爱 提交于 2019-12-22 05:43:13

问题


I press S, followed by D, on my keyboard, and release S. Why does the following code trigger a key down event for D once again, after I release S? Is there some way to find out that the second down event for D was caused by a key up of another key?

function handler(event) {
  if (!event.repeat) console.log(event.code, event.type);
}

window.addEventListener('keydown', handler);
window.addEventListener('keyup', handler);

Output:

KeyS keydown - S pressed
KeyD keydown - D pressed
KeyS keyup   - S released
KeyD keydown - WHY???

The strange keydown event only happens in Chrome (I'm using Chromium 66.0.3359.139 on Linux Mint), this does not happen in Firefox.

Might this actually be a bug, or is it intended behavior?

来源:https://stackoverflow.com/questions/50372849/pressing-2-keys-release-1-produces-keydown-of-other-key-again

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!