Engine API Reference - v2.6.1
    Preparing search index...

    Class Controller

    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.

    Index

    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.

        • Optionalgamepads?: GamePads

          A Gamepads object to use.

        • Optionalkeyboard?: Keyboard

          A Keyboard object to use.

        • Optionalmouse?: 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.

        • Optionalbutton?: number

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

        • Optionalkeys?: number[]

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

        • Optionalpad?: number

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

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

          The name of the action.

      Returns void

    • Attach Controller to an Element. This is required before you can monitor for key/mouse inputs.

      Parameters

      • element: Element

        The element to attach mouse and keyboard event handler too.

      Returns void

    • Detach Controller from an Element. This should be done before the Controller is destroyed.

      Returns void

    • Enable the context menu usually activated with the right mouse button. This is enabled by default.

      Returns void

    • Returns true if the current action is enabled.

      Parameters

      • actionName: string

        The name of the action.

      Returns boolean

      True if the action is enabled.

    • Register an action against a controller axis.

      Parameters

      • Optionaloptions: { pad?: number }

        Optional options object.

        • Optionalpad?: 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

    • Update the Keyboard and Mouse handlers.

      Parameters

      • dt: any

        The time since the last frame.

      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.