Capture the events of 2 or more keyboards in JavaScript/Web Browser

心不动则不痛 提交于 2019-11-29 11:02:35

No, with current browser environments you can not support multiple distinct input devices of a particular type. I am also not aware of any upcoming specs that would enable something like this. Generally it is assumed that a browser has only one user at at time. I don't think anything like this will be supported.

That said, there is a spec for gamepad support that is currently being developed. It is not supported by non-dev builds of browsers yet but both Firefox and Chrome are working on it. There is already an interesting library called gamepad.js if you are interested in this technology.

For now, to support multiple players you will probably have to do what most games do to support multiple keyboard based players, map each player to a different cluster of keys.

Update 2015-05-04

Support for the Gamepad API has gotten better since this answer, both Firefox and Chrome have support going back several versions now, and Opera supports it too. But not all browsers do, Safari and IE do not. Microsoft's new browser Edge looks like it will have support for the Gamepad API but it will probably take a long time to get most of the IE users to migrate to Edge or another browser.

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