-
Notifications
You must be signed in to change notification settings - Fork 16
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_1FACE_2FACE_3FACE_4LEFT_SHOULDERRIGHT_SHOULDERLEFT_SHOULDER_BOTTOMRIGHT_SHOULDER_BOTTOMSELECTSTARTLEFT_ANALOG_BUTTONRIGHT_ANALOG_BUTTONDPAD_UPDPAD_DOWNDPAD_LEFTDPAD_RIGHTHOME
LEFT_ANALOG_STICKRIGHT_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 layout (with a goal of adding more over time):
- 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 © 2016 Samir Zahran
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