-
Notifications
You must be signed in to change notification settings - Fork 1
Controller Layouts
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"
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
.
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
LEFT_ANALOG_STICK
RIGHT_ANALOG_STICK
The base Controller.js library defines one controller layout—the Standard Layout—which is based on the W3C's Standard Gamepad.
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.
(this list is incomplete)
- Playstation 3 Controller
- Playstation 4 Controller
- Xbox One Wired Controller1 — Windows
Controller.layouts.js offers the following additional layouts:
- Wired PS2 Buzz Controller
- Xbox One Wired Controller1 — Mac (using the XBox 360 Controller Driver)
Documentation on creating layouts for other non-standard gamepads will be coming in the future.
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.
The MIT License (MIT)
Copyright © 2022 Jack Carey
Setup
Buttons & Analog Sticks
Controller Layouts
Configuring Settings
Controller Events
Button Events
Analog Stick Events
Controller.supported
Controller.controllers
Controller.controllerCount
Controller.search()
Controller.getController()
Controller.watchAll()
Controller.unwatchAll()
.connectedTimestamp
.id
.index
.inputs
.layoutInfo
.name
.watch()
.unwatch()
Settings Objects
List of Settings
settings.list()
settings.clear()
settings.update()
→ Grunt Tasks
→ Registering Settings
→ Creating Layout Maps