Skip to main content

Gamepad

Gamepad holds state information for a connected controller. See Gamepads for more information on handling controller input.

Index

Constructors

constructor

Properties

publicconnected

connected: boolean = false

publicevents

events: EventEmitter<GamepadEvents> = ...

publicnavigatorGamepad

navigatorGamepad: NavigatorGamepad

Methods

publicemit

  • emit<TEventName>(eventName: TEventName, event: GamepadEvents[TEventName]): void
  • emit(eventName: string, event?: any): void
  • Type parameters

    Parameters

    • eventName: TEventName
    • event: GamepadEvents[TEventName]

    Returns void

publicgetAxes

  • getAxes(axes: Axes): number
  • Gets the given axis value between -1 and 1. Values below MinAxisMoveThreshold are considered 0.


    Parameters

    Returns number

publicgetButton

  • Gets the given button value between 0 and 1


    Parameters

    Returns number

publicisButtonHeld

  • isButtonHeld(button: Buttons, threshold?: number): boolean
  • Tests if a certain button is held down. This is persisted between frames.


    Parameters

    • button: Buttons

      The button to query

    • threshold: number = 1

      The threshold over which the button is considered to be pressed

    Returns boolean

publicisButtonPressed

  • isButtonPressed(button: Buttons, threshold?: number): boolean
  • Whether or not the given button is pressed

    @deprecated

    will be removed in v0.28.0. Use isButtonHeld instead


    Parameters

    • button: Buttons

      The button to query

    • threshold: number = 1

      The threshold over which the button is considered to be pressed

    Returns boolean

publicoff

  • off<TEventName>(eventName: TEventName, handler: Handler<GamepadEvents[TEventName]>): void
  • off(eventName: string, handler: Handler<unknown>): void
  • off(eventName: string): void
  • Type parameters

    Parameters

    • eventName: TEventName
    • handler: Handler<GamepadEvents[TEventName]>

    Returns void

publicon

  • Type parameters

    Parameters

    • eventName: TEventName
    • handler: Handler<GamepadEvents[TEventName]>

    Returns Subscription

publiconce

  • Type parameters

    Parameters

    • eventName: TEventName
    • handler: Handler<GamepadEvents[TEventName]>

    Returns Subscription

publicupdate

  • update(): void
  • Returns void

publicupdateAxes

  • updateAxes(axesIndex: number, value: number): void
  • Parameters

    • axesIndex: number
    • value: number

    Returns void

publicupdateButton

  • updateButton(buttonIndex: number, value: number): void
  • Parameters

    • buttonIndex: number
    • value: number

    Returns void

publicwasButtonPressed

  • wasButtonPressed(button: Buttons, threshold?: number): boolean
  • Tests if a certain button was just pressed this frame. This is cleared at the end of the update frame.


    Parameters

    • button: Buttons

      Test whether a button was just pressed

    • threshold: number = 1

      The threshold over which the button is considered to be pressed

    Returns boolean

publicwasButtonReleased

  • wasButtonReleased(button: Buttons): boolean
  • Tests if a certain button was just released this frame. This is cleared at the end of the update frame.


    Parameters

    • button: Buttons

      Test whether a button was just released

    Returns boolean