Options
All
  • Public
  • Public/Protected
  • All
Menu

Module gamepad

Index

Type aliases

PollGamepadOptions

PollGamepadOptions: GetGamepadsOptions & object

Functions

cloneGamepad

  • cloneGamepad(original: Gamepad): ClonedGamepad
  • cloneGamepad(original: Gamepad | null): ClonedGamepad | null
  • cloneGamepad(original: Gamepad | undefined): ClonedGamepad | undefined
  • cloneGamepad(original: Gamepad | undefined | null): ClonedGamepad | undefined | null

cloneGamepads

  • cloneGamepads(original: Gamepad[]): ClonedGamepad[]
  • cloneGamepads(original: Gamepad[]): ClonedGamepad[]
  • cloneGamepads(original: Gamepad[]): ClonedGamepad[]
  • cloneGamepads(original: Gamepad[]): ClonedGamepad[]

getGamepads

isSupported

  • isSupported(): boolean
  • Returns true if the browser seems to provide the gamepad APIs mmk.gamepad relies on for actual input. This isn't 100% accurate, Chromium on Linux has been known to define the APIs but not implement them.

    mmk.gamepad methods should generally still "work" (e.g. noop) even if the underlying browser APIs are missing, this method mostly exists to hint that you might not want to bother showing gamepad specific hints, or might want to suggest a gamepad-enabled browser, depending on your game.

    Returns boolean

parseGamepadId

  • Attempt to decompose a Gamepad.id. The exact layout of the Gamepad.id is hideously browser specific, non-portable, brittle, and generally badwrong to rely upon... but it's also my least bad option for identifying specific gamepads and applying gamepad/browser/OS specific workarounds and fixes for the raw navigator.getGamepad() results. Some examples:

    parseGamepadId(undefined) => { name: "unknown", vendor: "", product: "", hint: "unknown" }
    parseGamepadId(""       ) => { name: "unknown", vendor: "", product: "", hint: "unknown" }
    parseGamepadId("asdf"   ) => { name: "asdf",    vendor: "", product: "", hint: "unknown" }
    parseGamepadId("xinput" ) => { name: "xinput",  vendor: "", product: "", hint: "gecko"   }
    
    parseGamepadId("054c-0ba0-DUALSHOCK®4 USB Wireless Adaptor") => {
        name:    "DUALSHOCK®4 USB Wireless Adaptor",
        vendor:  "054c",
        product: "0ba0",
        hint:    "gecko"
    }
    
    parseGamepadId("DUALSHOCK®4 USB Wireless Adaptor (Vendor: 054c Product: 0ba0)") => {
        name:    "DUALSHOCK®4 USB Wireless Adaptor",
        vendor:  "054c",
        product: "0ba0",
        hint:    "blink"
    }

    If you encounter new and exciting Gamepad.id schemas, please send them my way!

    See also:

    Parameters

    • id: string | undefined

      The Gamepad.id to try and parse.

    Returns ParsedGamepadId

pollEvents

  • Poll gamepad state, and dispatch events based on that state. Note that mmk.gamepad will automatically dispatch by default based on one of:

        requestAnimationFrame(...)
        setInterval(..., 10)

    And that calling this method will disable that automatic dispatch mechanism.

    Parameters

    • Optional options: PollGamepadOptions

      Allows some customization of if e.g. deadzones are applied to generated events or not.

    Returns void

tryRemapStdLayout

Generated using TypeDoc