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

attachAttach Controller to a Element, this is required before you can monitor for key/mouse inputs.
detachDetach Controller from an Element, this should be done before the Controller is destroyed
disableContextMenuDisable the context menu usually activated with the right mouse button.
enableContextMenuEnable the context menu usually activated with the right mouse button.
isPressedReturn true if the current action is enabled
registerAxis
registerKeysCreate or update a action which is enabled when the supplied keys are pressed.
registerMouseCreate or update an action which is enabled when the supplied mouse button is pressed
registerPadButtonCreate or update an action which is enabled when the gamepad button is pressed
updateUpdate the Keyboard and Mouse handlers
wasPressedReturns 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

elementElementElement to attach Controller to.
optionsObjectOptional arguments.
options.keyboardpc.KeyboardA Keyboard object to use.
options.mousepc.MouseA Mouse object to use.
options.gamepadspc.GamePadsA Gamepads object to use.

Methods

attach(element)

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

Parameters

elementElementThe 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(action)

Return true if the current action is enabled

Parameters

actionStringThe name of the action

registerAxis([options])

Parameters

optionsObject
options.padObjectThe 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

actionStringThe 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

actionStringThe name of the action
buttonNumberThe mouse button

registerPadButton(action, pad, button)

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

Parameters

actionStringThe name of the action
padNumberThe index of the pad to register (use pc.PAD_1, etc)
buttonNumberThe pad button

update(dt)

Update the Keyboard and Mouse handlers

Parameters

dtObjectThe time since the last frame

wasPressed(action)

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

Parameters

actionStringThe name of the action

Returns

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