I've been struggling for a while trying to figure out the best way to map two players on a single keyboard. Let's consider something generic:

  • Arrows
  • Validation
  • Cancel (optional)
  • Some common actions shared between the two players (start, reset, etc.)

So far, I used:

  • P1: WASD + [Space or Tab]
  • P2: Arrows + [Enter or Return]
  • Common: R for reset

The problem is that some configuration can be uncomfortable on certain keyboards (especially when there is no keypad). Plus some players like to have the direction on left hand (FPS style) and others on right hand (platformer style). Also SHIFT is usually not a good choice on windows because of the sticky keys feature.

Also I'd like to avoid using a settings screen (kind of heavy for a small game). I guess a config file would be OK, but is there another way to handle this problem that would make every one happy?

  • 1
    \$\begingroup\$ It sounds like you're asking for other mapping layouts, instead of how to do the mapping. What exactly is your question? Are you having trouble mapping inputs to actions? \$\endgroup\$ – MichaelHouse Oct 27 '14 at 13:42

Let the user configure the bindings from an options menu in the application. Players might be using QWERTZ (German) or AZERTY (French) layout keyboards, Dvorak layout keyboards, joysticks, etc., and they don't want to have to learn Yet Another Config File Language.

But still, a lot of players will want to jump in and play without changing any settings. So you still have to choose good defaults and show them to the player when the game starts. Consider this:

  • Right player moves with arrow keys and does actions with apostrophe and Enter.
  • Left player moves with RDFG and does actions with Z and X. Do not straddle the line between TGB and YHN because a lot of "ergonomic" keyboards split the left hand and right hand keys here.
  • Single player mode should allow input from either side, so that players used to the common emulator default of arrows and ZX can jump in.
  • Common actions can be done while the game is paused. Common back/pause is Esc.
  • Show these keys to the players at the bottom of the first screen of the game, so that the player can get used to them before being in any real danger.

As Christian pointed out in this question, a lot of keyboards can't handle a lot of simultaneous presses. USB keyboards in particular are limited to no more than six, which isn't enough for a diagonal press and both actions on both sides. So I strongly encourage you to also support USB joysticks, be they Xbox 360 controllers or USB Human Interface Device (HID) class joysticks. SDL and SDL-wrapper libraries such as Pygame will recognize either, but if you're developing a Windows Store game, only Xbox 360 controllers will work because Microsoft forbids DirectInput in Windows Runtime. When you save the input configuration file, also save the VID/PID or name of all connected joysticks. This way, when the application starts with a different set of joysticks than were plugged in last time the application started, it can notify the player that joysticks were added or removed and ask the player to reconfigure the joysticks by pressing a button for each action in turn.

  • \$\begingroup\$ Thanks, lots of good advices in here! My only concern is about the apostrophe which won't work on special layouts. Wouldn't "O" and "P" be a better choice? (btw, I'm using pygame and developing my own library on top of it, so a flexible default configuration is definitely what I'm looking for) \$\endgroup\$ – Vincent Oct 28 '14 at 11:51
  • \$\begingroup\$ (and Z as action doesn't work for AZERTY and QWERTZ keyboard either) \$\endgroup\$ – Vincent Oct 28 '14 at 15:13

The best way to solve your concerns for flexibility and comfort of the user is to certainly allow them to define their bindings as you have described.

Whether you opt to do this through a configuration file they manually edit or an in-game screen that allows them to select the action and then press the key configurations for said binding is entirely up to you. If it were me, I would prefer the latter mainly because it avoids human error in creating the file and reusing a lot of the existing logic you'll need to decode the file into some internal representation as well (aka text to actual keys).


It depends on the keyboard in question. There are certain combinations of keys that don't result in all the keys registering as pressed. For example, pressing A and Q at the same time might only register Q.

Since this depends on hardware details, there's no one solution for you.

One good solution I saw was the KeyJam for Star Control 2's Super Melee mode. It allowed the user to hold down a bunch of keys, and the program would tell you which keys it thought were held. That way, each user could find a set of keys that worked for his setup.

  • 1
    \$\begingroup\$ It might help to elaborate on that with most keyboards, there are several combinations of keys that just cannot be detected at the same time. It's only lightly alluded to as it currently stands. \$\endgroup\$ – Lars Viklund Oct 27 '14 at 14:33

You could have the users configure their settings when they choose to start for the first time. Some games have you manually set your gamma and screen size, as I am sure you have experienced before. You could prompt each player to select what key they would want to use for the functions you have in your game. A Config file seems less intuitive. A options menu would be ideal, where the user sets the sounds/video options and sets key functions. Since your game consists of 9 keys, it would be a very small amount of work to incorporate, and take care of any keyboard setup the users may be using.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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