# SDL Multiple keyboard support

I am making a game with multiplayer split screen mode using SDL. Basically, I like the idea of having each player plug in his own keyboard to the PC, set custom controls via options and being able to play it with controls that he likes.

However, there's a problem. This code gets the keyboard event:

SDL_Event event;
SDL_PollEvent(&event);


SDL_Event has member SDL_KeyboardEvent key, which has member Uint8 which. In short:

event.key.which;


According to this, it should represent keyboard device index, however, I've tried connecting three keyboards to my PC and press the buttons at the same time and the result wasn't satisfying: they all had same keyboard indexes. Is there a solution to this? Or am I missing something?

I'm assuming you're using Windows so I did some digging and I found this answer on a question on the Microsoft forums about if it is possible to discern multiple keyboards:

No, this is dealt with at the device driver level. Beyond those, it can no longer tell where the keystroke came from.

I know this question was asked on a .NET related forum, not an SDL forum, but since he's talking about driver level I assume that SDL can't detect it either and that it's merely an artifact of SDL's multi-platform support.

(Please note that I do make a lot of assumptions here so this might not be the definitive answer)

• I see. Oh well, too bad I guess. Aug 13, 2012 at 10:41
• It would still easily work as long as the 2 players map different keys May 23, 2013 at 1:03

SDL is still blind to this, even though, it was promised to be implemented in v1.3 -after Windows XP came out with supporting multiple keyboard/mice-.
FYI when I write this we are at SDL 2.0.3. Found only some puffing comments that say "SDL will not support this!". It's a shame as (e.g.) openFL uses SDL too (in Haxe lang).
The feature, though, is still available in Windows (and it hopefully will remain like that) through Raw Input API.

Sorry to contribute a bit late right now, but I'm looking for something similar, and since the topic is less than a year old I figured I should not create a new one, correct me if I'm wrong. Anyway, They're clearly wrong, for a simple reason, Serious Sam 3 does it, on Windows, Linux and Mac, but I still didn't find out how... But it's possible then! If anyone has any news about multiple keyboards and mice support, go along :D

PS : I realize that the goal is to it with SDL but unfortunately, it seems they have gave up on this feature 1 or 2 versions ago, it was a WIP but it's impossible to find any "concrete" help on this feature anywhere, and some posts on the official SDL forum stated this feature as incomplete, and apparently not in the works =/

Well I may have found an alternative solution, which specifically adresses the issue expressed by Microsoft (aren't they programmers in the first place, and try to figure out that kind of things? anyway...).

So the thing is you have to communicate with the HID(Humain Interface Device) directly, this way you interact at a level lower than the driver level, and on top of this, each device has its own unique ID (all issues adressed ;) ). The only problem will be that you'll have to rewrite input classes yourself, because HIDs send raw inputs, as signals and codes, so you'll have to find a table of standard keyboard and mouse signals anAd IDs. Other than that, I think it's a viable solution. What do you guys think?