A general input handler which handles both mouse and keyboard input assigned to named actions. This allows you to define input handlers separately to defining keyboard/mouse configurations.

Constructors

  • Create a new instance of a Controller.

    Parameters

    • Optionalelement: Element

      Element to attach Controller to.

    • Optionaloptions: {
          gamepads: GamePads;
          keyboard: Keyboard;
          mouse: Mouse;
      } = {}

      Optional arguments.

      • gamepads: GamePads

        A Gamepads object to use.

      • keyboard: Keyboard

        A Keyboard object to use.

      • mouse: Mouse

        A Mouse object to use.

    Returns Controller

    const c = new pc.Controller(document);

    // Register the "fire" action and assign it to both the Enter key and the space bar.
    c.registerKeys("fire", [pc.KEY_ENTER, pc.KEY_SPACE]);

Methods

  • Helper function to append an action.

    Parameters

    • action_name: string

      The name of the action.

    • action: {
          button: number;
          keys: number[];
          pad: number;
          type: "mouse" | "keyboard" | "gamepad";
      }

      An action object to add.

      • button: number

        Mouse: e.g. pc.MOUSEBUTTON_LEFT - Gamepad: e.g. pc.PAD_FACE_1

      • keys: number[]

        Keyboard: A list of keycodes e.g. [pc.KEY_A, pc.KEY_ENTER].

      • pad: number

        Gamepad: An index of the pad to register (use PAD_1, etc).

      • type: "mouse" | "keyboard" | "gamepad"

        The name of the action.

    Returns void

  • Register an action against a controller axis.

    Parameters

    • Optionaloptions: {
          pad: number;
      }

      Optional options object.

      • pad: number

        The index of the game pad to register for (use PAD_1, etc).

    Returns void

  • Create or update a action which is enabled when the supplied keys are pressed.

    Parameters

    • action: string

      The name of the action.

    • keys: number[]

      A list of keycodes.

    Returns void

  • Create or update an action which is enabled when the supplied mouse button is pressed.

    Parameters

    • action: string

      The name of the action.

    • button: number

      The mouse button.

    Returns void

  • Create or update an action which is enabled when the gamepad button is pressed.

    Parameters

    • action: string

      The name of the action.

    • pad: number

      The index of the pad to register (use PAD_1, etc).

    • button: number

      The pad button.

    Returns void

  • Returns true if the action was enabled this since the last update.

    Parameters

    • actionName: string

      The name of the action.

    Returns boolean

    True if the action was enabled this since the last update.