Phaser. Key

new Key(game, keycode)

If you need more fine-grained control over the handling of specific keys you can create and use Phaser.Key objects.

Parameters:
Name Type Description
game Phaser.Game

Current game instance.

keycode integer

The key code this Key is responsible for. See Phaser.KeyCode.

Source - input/Key.js, line 15

Members

altKey :boolean

The down state of the ALT key, if pressed at the same time as this key.

Source - input/Key.js, line 51

ctrlKey :boolean

The down state of the CTRL key, if pressed at the same time as this key.

Source - input/Key.js, line 57

duration :number

If the key is down this value holds the duration of that key press and is constantly updated. If the key is up it holds the duration of the previous down session. The number of milliseconds this key has been held down for.

Source - input/Key.js, line 76

<readonly> event :object

Stores the most recent DOM event.

Source - input/Key.js, line 33

game :Phaser.Game

A reference to the currently running game.

Source - input/Key.js, line 20

isDown :boolean

The "down" state of the key. This will remain true for as long as the keyboard thinks this key is held down.

Source - input/Key.js, line 39

isUp :boolean

The "up" state of the key. This will remain true for as long as the keyboard thinks this key is up.

Default Value:
  • true
Source - input/Key.js, line 45

keyCode :number

The keycode of this key.

Source - input/Key.js, line 93

onDown :Phaser.Signal

This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again).

Source - input/Key.js, line 98

onHoldCallback :function

A callback that is called while this Key is held down. Warning: Depending on refresh rate that could be 60+ times per second.

Source - input/Key.js, line 103

onHoldContext :object

The context under which the onHoldCallback will be called.

Source - input/Key.js, line 108

onUp :Phaser.Signal

This Signal is dispatched every time this Key is released. It is only dispatched once (until the key is pressed and released again).

Source - input/Key.js, line 113

repeats :number

If a key is held down this holds down the number of times the key has 'repeated'.

Source - input/Key.js, line 88

shiftKey :boolean

The down state of the SHIFT key, if pressed at the same time as this key.

Source - input/Key.js, line 63

timeDown :number

The timestamp when the key was last pressed down. This is based on Game.time.now.

Source - input/Key.js, line 68

timeUp :number

The timestamp when the key was last released. This is based on Game.time.now.

Source - input/Key.js, line 82

Methods

downDuration(duration) → {boolean}

Returns true if the Key was pressed down within the duration value given, or false if it either isn't down, or was pressed down longer ago than then given duration.

Parameters:
Name Type Argument Default Description
duration number <optional>
50

The duration within which the key is considered as being just pressed. Given in ms.

Returns:
boolean -

True if the key was pressed down within the given duration.

Source - input/Key.js, line 253

<internal> processKeyDown(event)

Called automatically by Phaser.Keyboard.

Parameters:
Name Type Description
event KeyboardEvent

The DOM event that triggered this.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - input/Key.js, line 154

<internal> processKeyUp(event)

Called automatically by Phaser.Keyboard.

Parameters:
Name Type Description
event KeyboardEvent

The DOM event that triggered this.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - input/Key.js, line 191

reset(hard)

Resets the state of this Key.

This sets isDown to false, isUp to true, resets the time to be the current time, and enables the key. In addition, if it is a "hard reset", it clears clears any callbacks associated with the onDown and onUp events and removes the onHoldCallback.

Parameters:
Name Type Argument Default Description
hard boolean <optional>
true

A soft reset won't reset any events or callbacks; a hard reset will.

Source - input/Key.js, line 222

<internal> update()

Called automatically by Phaser.Keyboard.

Internal:
  • This member is internal (protected) and may be modified or removed in the future.
Source - input/Key.js, line 131

upDuration(duration) → {boolean}

Returns true if the Key was pressed down within the duration value given, or false if it either isn't down, or was pressed down longer ago than then given duration.

Parameters:
Name Type Argument Default Description
duration number <optional>
50

The duration within which the key is considered as being just released. Given in ms.

Returns:
boolean -

True if the key was released within the given duration.

Source - input/Key.js, line 269
Phaser Copyright © 2012-2015 Photon Storm Ltd.
Documentation generated by JSDoc 3.3.2 on Thu Feb 18 2016 14:41:02 GMT+0000 (GMT Standard Time) using the DocStrap template.