Reference Source
import {Controller} from 'gamepad/src/controller.mjs'
public class | source

Controller

Static Member Summary

Static Public Members
public static

The range at which the analog is considered to be dropped -0.09 - 0.09

public static

Analog thumb sticks

public static
public static

The range at which axis changes are detected

public static

A button map that maps common button names to the indexes the computer knows them as

public static
public static
public static

Value to indicate a pressed button

public static

A small remapped version of the controllers button_map with PS4 alternatives

public static

The value at which holding a trigger (LT OR RT) will consider it being pressed

public static

Value to indicate a button is not pressed

public static

The base analogs position when it is not in use

Constructor Summary

Public Constructor
public

constructor(pGamepad: Gamepad)

Creates a new controller instance and passes the gamepad it will be created with

Member Summary

Public Members
public

Object of stored callbacks that will call when the axis is changed

public

Configuration of which buttons / analogs map to which indexes

public

gamepad: *

public

The index of the controller.

public

Info about the controller

public
public
public

Object of stored callback that will call when a button is pressed

public

Object full of the currently held down buttons

public

Object of stored callback that will call when a button is released

public

Whether the right analog is currently being held

public

The right analogs position

public

The timestamp of the gamepad.

public

type: *

Method Summary

Public Methods
public

getPressed(): *

Gets the current buttons pressed down on the gamepad.

public

Returns the type the controller is.

public

handleAxisInput(pAxis: number, pValue: number, pRepeat: boolean)

Handles the input on the analogs.

public

handleButtonInput(pButton: number, pValue: number, pRepeat: boolean, pPressed: boolean)

Handles the input on the buttons.

public

Handles the event for when a analog is dropped.

public

Handles the event for when a analog is grabbed.

public

isButtonPressed(pButtonName: string): boolean

Checks whether a button is pressed down or not

public

Whether the left analog is being held

public

Whether the right analog is being held

public

off(pEvent: Event['event']): Controller

Removes a callback from the specified event.

public

on(pEvent: Event['event'], pCallback: Event['callback']): Controller

Attaches a callback to the specified event.

public

pulse(pValue: number, pDuration: number)

The pulse() method of the GamepadHapticActuator interface makes the hardware pulse at a certain intensity for a specified duration.

public

updateState(-: Gamepad, -: Controller)

Update the state of this controller with the latest polled information

public

vibrate(pVibrationType: string, pStartDelay: number, pWeakMagnitude: number, pStrongMagnitude: number)

Vibrate the controller (experimental)

Static Public Members

public static ANALOG_RELEASE_RANGE: number source

The range at which the analog is considered to be dropped -0.09 - 0.09

public static AXES: object source

Analog thumb sticks

public static AXES_REVERSED_MAP: * source

public static AXIS_UPDATE_RANGE: number source

The range at which axis changes are detected

public static BUTTONS_MAP: * source

A button map that maps common button names to the indexes the computer knows them as

public static BUTTONS_REVERSE_MAP: * source

public static GAMEPAD_IDS: * source

public static PRESSED: number source

Value to indicate a pressed button

public static PS4_REMAPPED: object source

A small remapped version of the controllers button_map with PS4 alternatives

public static TRIGGER_PRESSED_VALUE: * source

The value at which holding a trigger (LT OR RT) will consider it being pressed

public static UNPRESSED: number source

Value to indicate a button is not pressed

public static baseAnalogPos: * source

The base analogs position when it is not in use

Public Constructors

public constructor(pGamepad: Gamepad) source

Creates a new controller instance and passes the gamepad it will be created with

Params:

NameTypeAttributeDescription
pGamepad Gamepad

A gamepad object

Public Members

public axisHandlers: Object source

Object of stored callbacks that will call when the axis is changed

public config: object source

Configuration of which buttons / analogs map to which indexes

public gamepad: * source

public index: number source

The index of the controller.

public info: object source

Info about the controller

public leftAnalogHeld: * source

public leftAnalogPos: * source

public pressHandlers: Object source

Object of stored callback that will call when a button is pressed

public pressed: object source

Object full of the currently held down buttons

public releaseHandlers: Object source

Object of stored callback that will call when a button is released

public rightAnalogHeld: boolean source

Whether the right analog is currently being held

public rightAnalogPos: * source

The right analogs position

public timestamp: number source

The timestamp of the gamepad.

public type: * source

Public Methods

public getPressed(): * source

Gets the current buttons pressed down on the gamepad.

Return:

*

public getType(): string source

Returns the type the controller is. PC / PS / Xbox / Android

Return:

string

public handleAxisInput(pAxis: number, pValue: number, pRepeat: boolean) source

Handles the input on the analogs.

Params:

NameTypeAttributeDescription
pAxis number

The axis index that was moved

pValue number

The value of the axis that was moved (0-1 range)

pRepeat boolean

Whether this axes is still the same from a previous frame

public handleButtonInput(pButton: number, pValue: number, pRepeat: boolean, pPressed: boolean) source

Handles the input on the buttons.

Params:

NameTypeAttributeDescription
pButton number

The button index that was pressed

pValue number

The value of the button (0 for unpressed, 1 for pressed) 0-1 for buttons that have a range

pRepeat boolean

Whether this button is still being held from a previous frame

pPressed boolean

Whether this button is being pressed in this current frame.

public handleDropAnalog(pAnalog: string) source

Handles the event for when a analog is dropped.

Params:

NameTypeAttributeDescription
pAnalog string

Analog that was dropped

public handleGrabAnalog(pAnalog: string) source

Handles the event for when a analog is grabbed.

Params:

NameTypeAttributeDescription
pAnalog string

Analog that was grabbed

public isButtonPressed(pButtonName: string): boolean source

Checks whether a button is pressed down or not

Params:

NameTypeAttributeDescription
pButtonName string

The button to check if its pressed

Return:

boolean

public isLeftAnalogHeld(): boolean source

Whether the left analog is being held

Return:

boolean

public isRightAnalogHeld(): boolean source

Whether the right analog is being held

Return:

boolean

public off(pEvent: Event['event']): Controller source

Removes a callback from the specified event.

Params:

NameTypeAttributeDescription
pEvent Event['event']

The event to remove the callback from

Return:

Controller

The Controller instance

public on(pEvent: Event['event'], pCallback: Event['callback']): Controller source

Attaches a callback to the specified event.

Params:

NameTypeAttributeDescription
pEvent Event['event']

The event to attach the callback to

pCallback Event['callback']

The function to be called when the event is triggered

Return:

Controller

The Controller instance

public pulse(pValue: number, pDuration: number) source

The pulse() method of the GamepadHapticActuator interface makes the hardware pulse at a certain intensity for a specified duration. (From MDN)

Params:

NameTypeAttributeDescription
pValue number

A double representing the intensity of the pulse. This can vary depending on the hardware type, but generally takes a value between 0.0 (no intensity) and 1.0 (full intensity).

pDuration number

A double representing the duration of the pulse, in milliseconds.

public updateState(-: Gamepad, -: Controller) source

Update the state of this controller with the latest polled information

Params:

NameTypeAttributeDescription
- Gamepad

The gamepad with the new updated state

- Controller

The gamepad controller instance

public vibrate(pVibrationType: string, pStartDelay: number, pWeakMagnitude: number, pStrongMagnitude: number) source

Vibrate the controller (experimental)

dual-rumble: Dual-rumble describes a haptic configuration with an eccentric rotating mass vibration motor in each handle of a standard gamepad. In this configuration, either motor is capable of vibrating the whole gamepad. The two masses are unequal so that the effects of each can be combined to create more complex haptic effects.

Params:

NameTypeAttributeDescription
pVibrationType string

The type of rumble. "dual-rumble", or "vibration"

pStartDelay number

The start delay before the vibration occurs in ms

pWeakMagnitude number

The magnitude of the weak actuator (between 0 and 1).

pStrongMagnitude number

The magnitude of the strong actuator (between 0 and 1).