Unlike controllers for a single game console, USB Human Interface Device game controllers for a PC have their buttons in different layouts. Even if the buttons are in the same layout, they may be presented to the application in a different order. So unlike a console game, a PC game cannot assume that, say, "button 1 = jump".
This section describes how various controllers are seen by Pygame, a wrapper around SDL. Most tests were performed with a program under Xubuntu 12.04 "Precise Pangolin". Section headings represent the device name as seen through the test program, under Linux if not otherwise specified. Results on Windows 8 were similar, except SDL under Windows 8 omits the manufacturer name from the device name, and devices without a name show up as a less informative "2 axis 10 button joystick" instead of the hexadecimal vendor and product IDs.
The original iMac was the first popular personal computer to have USB as its only connection for external input, storage, and output devices. USB ports became common on other brands of PC starting in 1999. Once USB became standard and sound cards stopped carrying the 15-pin game ports to which joysticks had previously connected, companies started producing USB game controllers specifically for the PC.
One of the first USB game controllers, with the same physical layout as the original PlayStation controller.
A controller with the same layout as Sony's Dual Shock, except the sticks' restrictors are square, not circular. When the "mode" switch is turned on, the left stick is swapped with the digital Control Pad. Surprisingly, buttons 1-10 are in the same order as on the Gravis.
This controller is essentially the same thing as the Dual Action, except with no analog sticks and the "mode" switch always on. It's similar to the original PlayStation controller with larger L2 and R2 buttons like those of the Dual Shock.
The SteelSeries 3GC Controller is mapped quite oddly. The name of this device, as seen by SDL on Linux, has a lot of spaces:
DragonRise Inc. Generic USB Joystick
Buttons 1-10 have silk-screened numbers. Shoulder buttons 5-8 have the number silk-screened next to an engraved 1 or 2, showing that the manufacturer uses the same mold for PlayStation controllers. A "mode" button at the bottom center of the face switches between two modes, signaled by green and red LEDs next to the button. Green appears to be designed for games expecting only digital controls, while red makes all analog controls available.
This one has a flat, retractable USB cable. Its Control Pad is severely diagonal-biased, making it next to unusable for anything but isometric games like Q*bert, Snake Rattle 'n' Roll, and other games designed for a 4-way diagonal joystick. Its face buttons are in PlayStation order and have 1, 2, 3, and 4 symbols colored like PlayStation buttons.
Axes (4):
Buttons (4):
Hats (1)
This is a Chinese no-name clone of the Super NES controller, except with lighter plastic and a USB HID protocol instead of the SPI-like protocol that the NES and Super NES controllers use.
Evidently a lot of people are dissatisfied with the Control Pad on no-name and Gravis controllers, preferring that of a Nintendo or Sony console. Several companies have produced adapters to use controllers for classic game consoles with any PC game that supports USB HID controllers.
Adapter to use Nintendo 64 controllers on a USB HID host. As with the Dual Analog, there is a way to swap the Control Pad and Control Stick. While holding L, R, and Z, press Up on the Control Pad three times to enable swapping or move the Control Stick up three times to disable it.
The EMS USB2 adapter can be switched between two modes. One mode allows the use of an original Namco Guncon with PS2 software designed for the Guncon 2. The other mode, described here, allows using one or two PlayStation, Dual Shock, or Dual Shock 2 controllers on a USB HID host. Some people report it works better when plugged into a hub than when plugged directly into the PC. It has become popular among StepMania users because Control Pad directions are always returned as buttons, even in digital mode, so that Left+Right and Up+Down presses on a dance pad work correctly. An original PlayStation controller or a Dual Shock or Dual Shock 2 with the Analog button turned off will replace all joystick axes with the corresponding direction on the Control Pad. The buttons on a Dual Shock 2 are not pressure-sensitive; it is treated as an original Dual Shock.
The Xbox 360 controller's native protocol is not the standard USB Human Interface Device protocol.
This is a wired Xbox 360 Controller. Its Linux driver misspells "Xbox". The layout below is for SDL on the Linux driver.
Under Windows, SDL uses DirectInput, not XInput, for Xbox 360 controllers. The Windows DirectInput driver for the Xbox 360 controller produce the difference RT - LT as one axis, with no second axis for LT + RT, in order to encourage developers to switch from DirectInput to XInput, which is exclusive to Xbox 360 controllers. (Another thing to encourage use of XInput is the fact that Windows Store applications cannot use DirectInput and thus cannot use any controller other than the Xbox 360 Controller.)
Microsoft makes a receiver for Xbox 360 wireless controllers that plugs into a PC's USB port, but I haven't had a chance to test it. One of my testers reports that it calls itself a "Controller (Xbox 360 Wireless Receiver for Windows)".
The primary axes are either the Control Pad or the left stick. Buttons come in a rough order: face buttons, then shoulder buttons, then Select and Start, then buttons under sticks, and finally Control Pad directions if not assigned to a hat. But the order and number of buttons within a category are unpredictable, as is which button the user expects to use for each action.
MUST SHOULD MAY |
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119. (what's this?) |
An application that doesn't recognize a particular controller brand SHOULD do the following:
To make things easier for the user, the form SHOULD be preloaded with layouts for the most widespread controllers. All XInput controllers use the layout for Xbox 360, and the layout for Gravis GamePad Pro USB, Logitech Precision, and Logitech Dual Action appears to be fairly widespread as well. If the user selects "Custom", ask the user to press the button for each game action in sequence. Assigning multiple buttons to a given action can be done later, after the basic configuration is in place.
The player may end up starting a game with the wrong controls and not knowing how to get back to the menu to configure the controls. Such a player would have to press all the buttons on the controller but would eventually end up pressing the button whose number is the same as that of the Back or Start button on the Xbox 360 controller, or in the case of a controller with few buttons, the last button. (Based in part on recommendation by Belial6.)
An analog joystick returns displacements along two axes: X (horizontal) and Y (vertical). These readings include a small amount of noise. So the way axes are mapped SHOULD have a dead zone, or an area at the center of the range where the stick is considered centered.
There are two ways to convert the X and Y axes to a direction: separable and polar. A "separable" interpretation treats the X and Y axes independently, giving each axis its own dead zone. The size of the dead zone controls how easy it is to hit the straight and diagonal areas, and it's next to impossible to go directly from centered to diagonal. Separable interpretation is useful for side-view games, where the X axis moves left and right and the Y axis looks up and down or jumps and crouches.
A "polar" interpretation first determines how far and at what angle the stick is moved. The straight sectors can be the same size as the diagonals (45 degrees), or it can be biased toward straight movement (60 degrees). The angle measurement need not use time-consuming trigonometry or square roots. It takes only two multiplies and three adds to calculate whether the squared displacement is greater than the square of the dead zone radius (x2 + y2 > r2), and then calculate whether min(|x|, |y|) > m * max(|x|, |y|), where the slope threshold m (0 < m < 1) is the tangent of half the width of the straight sector.
Here are plots of the nine possible zones for the six combinations of separable, polar with 45 degree straight sectors, and polar with 60 degree sectors, at both 25% and 50% dead zone radius.
Some games allow no diagonal movement at all, such as top-down games with 4-way movement (Pac-Man; Pokemon) and block puzzle games that don't let the user move a piece sideways and drop it at the same time. The best way I've found to handle this is to use a bit of hysteresis: if the diagonal is pressed, use the most recent straight sector (if it's adjacent). This works with separable interpretation or with 60-degree straight sectors.
Even on controllers with a digital Control Pad, some cheaper controllers may make it too easy for the player to accidentally press diagonally. This might make the character in a platformer suddenly switch from a run (Right) into a crawl (Down+Right). This can be prevented with a similar technique to the diagonal: only allow Down+Right to be entered from Down. Holding Right and pressing Down would continue moving to the right; to roll or crawl, the player would first have to roll the Control Pad to Down then back to Down+Right, as if performing a Dragon Punch. But games SHOULD still offer a way to turn this compensation off in case the user is using a higher-quality controller, such as a keyboard, an N64 controller through an Adaptoid, a Dual Shock through an EMS USB2, or a Wii Classic Controller through a Mayflash PC045.
And don't depend on the player being able to reach the four corners with the joystick. The thumb sticks on the Xbox 360 and PlayStation controllers, for example, have a circular restrictor. So scale each joystick's dead zone size relative to the maximum displacement that the program has seen on that joystick in this play session.
Categories: Human-computer interaction, Articles with RFC 2119 verbs