API Reference

Class List

pc.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.

var c = new pc.Controller(document);

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

Summary

Methods

attach

Attach Controller to a Element, this is required before you can monitor for key/mouse inputs.

detach

Detach Controller from an Element, this should be done before the Controller is destroyed.

disableContextMenu

Disable the context menu usually activated with the right mouse button.

enableContextMenu

Enable the context menu usually activated with the right mouse button.

isPressed

Returns true if the current action is enabled.

registerAxis
registerKeys

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

registerMouse

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

registerPadButton

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

update

Update the Keyboard and Mouse handlers.

wasPressed

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

Details

Constructor

Controller([element], [options])

Create a new instance of a Controller.

var c = new pc.Controller(document);

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

Parameters

elementElement

Element to attach Controller to.

optionsobject

Optional arguments.

options.keyboardpc.Keyboard

A Keyboard object to use.

options.mousepc.Mouse

A Mouse object to use.

options.gamepadspc.GamePads

A Gamepads object to use.

Methods

attach(element)

Attach Controller to a Element, this is required before you can monitor for key/mouse inputs.

Parameters

elementElement

The element to attach mouse and keyboard event handler too.

detach()

Detach Controller from an Element, this should be done before the Controller is destroyed.

disableContextMenu()

Disable the context menu usually activated with the right mouse button.

enableContextMenu()

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

isPressed(actionName)

Returns true if the current action is enabled.

Parameters

actionNamestring

The name of the action.

Returns

boolean

True if the action is enabled.

registerAxis([options])

Parameters

optionsobject

Optional options object.

options.padobject

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

registerKeys(action, keys)

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

Parameters

actionstring

The name of the action.

keysnumber[]

A list of keycodes.

registerMouse(action, button)

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

Parameters

actionstring

The name of the action.

buttonnumber

The mouse button.

registerPadButton(action, pad, button)

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

Parameters

actionstring

The name of the action.

padnumber

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

buttonnumber

The pad button.

update(dt)

Update the Keyboard and Mouse handlers.

Parameters

dtobject

The time since the last frame.

wasPressed(actionName)

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

Parameters

actionNamestring

The name of the action.

Returns

boolean

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