Class Controller

Constructors

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

    Parameters

    • pGamepad: Gamepad

      A gamepad object

    Returns Controller

Properties

config: {
    buttons: {
        [key: string]: number;
    };
} = ...

Configuration of which buttons / analogs map to which indexes

Type declaration

  • buttons: {
        [key: string]: number;
    }
    • [key: string]: number
leftAnalogHeld: boolean = false

Whether the left analog is currently being held

rightAnalogHeld: boolean = false

Whether the right analog is currently being held

baseAnalogPos: Point2D = ...

The base analogs position when it is not in use

AXES: {
    [key: string]: number;
} = ...

Analog thumb sticks

Type declaration

  • [key: string]: number
AXES_REVERSED_MAP: {
    [key: number]: string;
} = ...

Type declaration

  • [key: number]: string
deadZone: number = 0.0

User-configurable dead zone threshold (0.0 - 1.0) Default is 0.0 (no dead zone) following industry standards. Developers should configure this based on their application needs. Typical pValues: 0.0 (none), 0.15 (light), 0.25 (medium)

leftAnalogDeadZone: number = 0.0

Separate dead zones for left and right analog sticks

rightAnalogDeadZone: number = 0.0
stickDriftCompensation: {
    [pAxisIndex: number]: number;
} = {}

Stick drift compensation pValues per axis

Type declaration

  • [pAxisIndex: number]: number
TRIGGER_PRESSED_VALUE: number = 0.12

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

VIBRATION_PRESETS: {
    [key: string]: VibrationPreset;
} = ...

Vibration presets for common haptic effects

Type declaration

  • [key: string]: VibrationPreset
PRESSED: number = 1.0

Value to indicate a pressed button

UNPRESSED: number = 0.0

Value to indicate a button is not pressed

BUTTONS_MAP: {
    [key: string]: number;
} = ...

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

Type declaration

  • [key: string]: number
BUTTONS_REVERSE_MAP: {
    [key: number]: string;
} = ...

A reverse map of the button names

Type declaration

  • [key: number]: string
PS4_REMAPPED: {
    [key: string]: string;
} = ...

A small remapped version of the controllers button_map with PS4 alternatives

Type declaration

  • [key: string]: string
GAMEPAD_IDS: {
    [key: string]: string;
} = ...

PS: Playstation vendor Xbox: XBOX vendor PC: Computer PC vendor Android: Android device vendor

Type declaration

  • [key: string]: string
info: {
    axes: null | readonly number[];
    buttons: null | readonly GamepadButton[];
    previousButtonState: boolean[];
    previousAxesState: number[];
    initialAxesStickDrift: number[];
} = ...

Info about the controller

Type declaration

  • axes: null | readonly number[]
  • buttons: null | readonly GamepadButton[]
  • previousButtonState: boolean[]
  • previousAxesState: number[]
  • initialAxesStickDrift: number[]
timestamp: number = 0

The timestamp of the gamepad.

index: number = 0

The index of the controller.

gamepad: Gamepad

The gamepad object

type: string

The type of controller

Methods

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

    Returns string

    The controller type

  • Applies circular dead zone filtering with proper scaling to an analog stick

    Parameters

    • pX: number

      Raw X axis pValue (-1 to 1)

    • pY: number

      Raw Y axis pValue (-1 to 1)

    • pDeadZone: number

      Dead zone threshold (0.0 - 1.0)

    Returns AnalogPosition

    Object with filtered x, y pValues and magnitude

  • Applies dead zone filtering to an axis pValue (legacy method for individual axes)

    Parameters

    • pValue: number

      Raw axis pValue (-1 to 1)

    • pAxisIndex: number

      Index of the axis

    Returns number

    Filtered pValue (0 if within dead zone, otherwise compensated pValue)

  • Gets the current left analog stick position with metadata

    Returns AnalogPosition

    Object containing x, y, magnitude, and angle

  • Gets the current right analog stick position with metadata

    Returns AnalogPosition

    Object containing x, y, magnitude, and angle

  • Update the state of this controller with the latest polled information

    Parameters

    • pGamepad: Gamepad

      The gamepad with the new updated state

    Returns void

  • Checks if this controller supports haptic feedback

    Returns boolean

    True if haptic feedback is supported

  • Checks if this controller supports motion sensors

    Returns boolean

    True if motion sensors are supported

  • Checks if this controller supports touchpad

    Returns boolean

    True if touchpad is supported

  • Gets the controller's display name

    Returns string

    Human-readable controller name

  • Gets the current buttons pressed down on the gamepad.

    Returns string[]

  • Adds an event listener with optional configuration

    Parameters

    • pEvent: string

      The event name (case agnostic)

    • pCallback: Function

      The callback function

    • Optional pOptions: EventListenerOptions

      Optional configuration (once, priority)

    Returns Controller

    The Controller instance

  • Removes an event listener

    Parameters

    • pEvent: string

      The event name (case agnostic)

    • pCallback: Function

      The callback function to remove

    Returns Controller

    The Controller instance

  • Sets the dead zone threshold for this controller

    Dead zones ignore small analog stick movements to prevent drift and unwanted input. Values below the threshold are treated as 0. Higher values = more input ignored.

    Parameters

    • pDeadZone: number

      The dead zone threshold (0.0 to 1.0, where 0.15 = 15% dead zone)

    Returns void

    Throws

    Error if deadZone is not between 0 and 1

  • Sets the dead zone threshold for the left analog stick

    Dead zones ignore small analog stick movements to prevent drift and unwanted input. Values below the threshold are treated as 0. Higher values = more input ignored.

    Parameters

    • pDeadZone: number

      The dead zone threshold (0.0 to 1.0, where 0.15 = 15% dead zone)

    Returns void

    Throws

    Error if deadZone is not between 0 and 1

  • Sets the dead zone threshold for the right analog stick

    Dead zones ignore small analog stick movements to prevent drift and unwanted input. Values below the threshold are treated as 0. Higher values = more input ignored.

    Parameters

    • pDeadZone: number

      The dead zone threshold (0.0 to 1.0, where 0.15 = 15% dead zone)

    Returns void

    Throws

    Error if deadZone is not between 0 and 1

  • Gets the current dead zone threshold

    Returns number

    The current dead zone pValue

  • Gets the current left analog dead zone threshold

    Returns number

    The current left analog dead zone pValue

  • Gets the current right analog dead zone threshold

    Returns number

    The current right analog dead zone pValue

  • Gets the current state of all buttons (cached for performance - no object churn)

    Returns ButtonStates

    Object with button states and pValues (reuses existing objects)

  • Gets the current state of all analog inputs (cached for performance - no object churn)

    Returns AnalogStates

    Object with analog stick states (reuses existing objects)

  • Gets the complete controller state (optimized - no object churn)

    Returns ControllerState

    Object with all controller state information (reuses existing objects)

  • Whether the left analog is being held

    Returns boolean

    True if left analog is held

  • Whether the right analog is being held

    Returns boolean

    True if right analog is held

  • Checks whether a button is pressed down or not

    Parameters

    • pButtonName: string

      The button to check if its pressed (case agnostic)

    Returns boolean

    True if button is pressed

    Throws

    Error if buttonName is not a valid button

  • Vibrates the controller using a preset pattern

    Parameters

    • pPreset: string | number

      The preset name from VIBRATION_PRESETS (case agnostic)

    • pStartDelay: number = 0

      Optional start delay in ms

    Returns Promise<void>

    Promise that resolves when vibration completes

  • Vibrates the controller with a sequence of patterns

    Parameters

    • pPattern: VibrationStep[]

      Array of vibration patterns

    Returns Promise<void>

    Promise that resolves when all vibrations complete

  • Stops all ongoing vibrations

    Returns void

  • Vibrate the controller with validation and Promise support

    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.

    Parameters

    • pVibrationType: string = 'dual-rumble'

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

    • pStartDelay: number = 0

      The start delay before the vibration occurs in ms

    • pDuration: number = 1000

      The duration of the vibration in ms

    • pWeakMagnitude: number = 1

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

    • pStrongMagnitude: number = 1

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

    Returns Promise<void>

    Promise that resolves when vibration completes