Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

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.

http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/de8f3244-d4ae-4c23-85d7-b6a7a365b3ec/

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)

share|improve this answer
    
I see. Oh well, too bad I guess. –  Sunius Aug 13 '12 at 10:41
1  
It would still easily work as long as the 2 players map different keys –  Brendan May 23 '13 at 1:03

Better later than never answer:
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.

share|improve this answer

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?

share|improve this answer
1  
Hi there! Please post comments, as comments to the questions rather than as an "answer". Thanks! –  Vaughan Hilts May 23 '13 at 1:32
    
@VaughanHilts I don't think DevilBlackDeath's rep is high enough to comment on anything –  congusbongus May 23 '13 at 4:57
    
Oops sorry, first time, just created an account, I'll do this now ;) And if I have a potential answer, should I post it as answer or comment? :) I edited my answer so that it's a real answer, however, by editing, is the thread author notified of my edit or should I repost? –  DevilBlackDeath May 23 '13 at 9:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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