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
element | Element | Element to attach Controller to. |
options | Object | Optional arguments. |
options.keyboard | pc.Keyboard | A Keyboard object to use. |
options.mouse | pc.Mouse | A Mouse object to use. |
options.gamepads | pc.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
element | Element | 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
actionName | String | The name of the action. |
Returns
Boolean True if the action is enabled.registerAxis([options])
Parameters
options | Object | Optional options object. |
options.pad | Object | 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
action | String | The name of the action |
keys | Number[] | A list of keycodes |
registerMouse(action, button)
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 |
registerPadButton(action, pad, button)
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 pc.PAD_1, etc) |
button | Number | The pad button |