6

I am writing some test applications that perform simple keyboard event capture.

I have no problem with this basic approach.

But now I need a better experience with my application and I want to connect at least two or more USB or PS/2 keyboards, distinguishing what keyboard is the source of the key events, and so being able to use the web browser locally with JavaScript (and HTML5), as if it was a game console with several controllers for more than one player, simultaneously.

I know that even under Windows or Linux, the normal behavior is to make several keyboards fire the same events. However, I also know that it would be perfectly possible to know what particular keyboard hardware device fired that event.

Is it possible or is it a limitation in JavaScript? Will probably be support in the future to support the distinction of multiple input devices of the same basic type, is there some alternative, at least with HTML5, or would it be an almost lost hope, talking in the context of a web browser, JavaScript and HTML5?

1 Answer 1

4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.