Why is Keyboard.GetState(index) obsolete ?

Hi ! I’m new to Monogame and I’d like to use multiple keyboards for a little splitscreen game. For that, I have to know which keyboard is used for each key that I’m typing. I found a method that could be of use but it’s seem deprecated and I’d like to know why :

[Obsolete("Use GetState() instead. In future versions this method can be removed.")]
public static KeyboardState GetState(PlayerIndex playerIndex) { ... }

I also found a similar method in OpenTK : OpenTK.Input.Keyboard.GetState(int). So that’s my second question : is it a good idea to use the OpenTK method instead ? I didn’t found any other solution except diving into Windows Raw Input API, but that wouldn’t be cross-platform at all.

There is no need to dive any deeper. As it says, use Keyboard.GetState() rather than Keyboard.GetState(PlayerIndex). It was obsoleted because the PlayerIndex parameter has no meaning for the keyboard device.

I just saw the bit about wanting to use multiple keyboards. For that you may need to go lower. I, and almost every other developer, have never tried multiple keyboards so we’re not going to be much help here I’m afraid. The OpenTK API may work for you. Give it a try.

The OpenTK method seems to work fine so I’ll use it. Thanks for your reply !

Multiple keyboards plugged into ONE PC ??? is this even possible - in over 30 years with PCs I’ve never actually plugged in more than one keyboard so I understood why the PlayerIndex is now obsolete from Monogame KeyboardState.

I’ll have to try and plug 2 keyboards into windows to see what happens. Can’t both players play on the same keyboard? e.g. ASDW for player one and cursor/numpad keys for player two ?

Well it is possible ! Actually, I know only one game in which we can use multiple keyboard and mouse on the same PC : “Trine 2”. We can up to 3 players, each with 1 keyboard and 1 mouse for controlling 1 character. It was a little buggy but it worked. There was up to 3 cursors in the menu !

By default, Windows (and Monogame) treat all the keyboards you plug as one. Same for the mouse : if you plug two mouses (mice ? sorry i’m french ^^), both will control the same cursor. For most applications, it’s not useful to have multiple keyboard/mouse, except for the very special case of a splitscreen-PC-game ! Ah … I miss the time when we could play most console games with splitscreen rather than through network.

I didn’t even think multiple keyboards and mice were possible…

The reason MonoGame has the PlayerIndex option is for the chatpads you connect to Xbox gamepads.

Is it possible to have multiple keyboards and mice in MonoGame? Obviously that is ideal for split-screen games.

Multiple keyboards and mice are indeed possible, but a lot of effort and compatibility testing will be required for the very small number of people who might use it.

@JohnK Ahh thanks for letting us know. this is new to me. Have you through about making it a network game instead so the other user can use his own PC, I hate touching my brothers keyboard… :slightly_smiling:

Look at the Lidgren network library that is shipped with monogame, it looks really easy to use/learn and might be the ideal solution for you (still learning it myself).

as for Mouse, it’s Mouse for one and Mice for multiple. :slightly_smiling: