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

enabled :boolean

An enabled key processes its update and dispatches events.
A key can be disabled momentarily at runtime instead of deleting it.

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

<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

justDown :boolean

The justDown value allows you to test if this Key has just been pressed down or not.
When you check this value it will return true if the Key is down, otherwise false.
You can only call justDown once per key press. It will only return true once, until the Key is released and pressed down again.
This allows you to use it in situations where you want to check if this key is down without using a Signal, such as in a core game loop.

Default Value:
  • false
Source - input/Key.js, line 287

justUp :boolean

The justUp value allows you to test if this Key has just been released or not.
When you check this value it will return true if the Key is up, otherwise false.
You can only call justUp once per key release. It will only return true once, until the Key is pressed down and released again.
This allows you to use it in situations where you want to check if this key is up without using a Signal, such as in a core game loop.

Default Value:
  • false
Source - input/Key.js, line 310

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-2016 Photon Storm Ltd.
Documentation generated by JSDoc 3.4.3 on Mon Dec 05 2016 10:04:35 GMT+0000 (GMT Standard Time) using the DocStrap template.