Controller Layouts

Samir Zahran edited this page Aug 30, 2016 · 1 revision

Controller.js simplifies working with different gamepads by trying to normalize gamepad layouts.

Upon initialization, gamepads are mapped against known layouts to assign names to each input that can be used to identity them.

window.addEventListener('gc.button.press', function(event) {
    console.log(event.detail.name);
}, false);

>> "DPAD_RIGHT"

Input Names

Inputs are split into Buttons and Analog Sticks.

It is possible for controllers to have more buttons than are listed here. In that case they will be named MISCBUTTON_1, MISCBUTTON_2, … MISCBUTTON_N.

Buttons

  • FACE_1
  • FACE_2
  • FACE_3
  • FACE_4
  • LEFT_SHOULDER
  • RIGHT_SHOULDER
  • LEFT_SHOULDER_BOTTOM
  • RIGHT_SHOULDER_BOTTOM
  • SELECT
  • START
  • LEFT_ANALOG_BUTTON
  • RIGHT_ANALOG_BUTTON
  • DPAD_UP
  • DPAD_DOWN
  • DPAD_LEFT
  • DPAD_RIGHT
  • HOME

Analog Sticks

  • LEFT_ANALOG_STICK
  • RIGHT_ANALOG_STICK

Layouts

The base Controller.js library defines one controller layout—the Standard Layout—which is based on the W3C's Standard Gamepad.

Standard Layout

The Standard layout is the default for any controller who's Gamepad API Gamepad object has it's mapping attribute's value set to "standard".

Most controllers conforming to this layout will support most of the named inputs, but that is not guaranteed. They may also report extra buttons.

Gamepads known to conform to the Standard layout:

(this list is incomplete)

  • Playstation 3 Controller
  • Playstation 4 Controller
  • Xbox One Wired Controller1Windows

Other Layouts

Controller.layouts.js offers the following additional layout (with a goal of adding more over time):

Documentation on creating layouts for other non-standard gamepads will be coming in the future.

Notes:

1 Microsoft provides official support for Xbox Controllers on Windows but not Mac. The provided Xbox One Wired Controller layout for Mac is only tested with one specific third-party driver and likely doesn't work correctly with any others, although support could be added.