If you need more fine-grained control over the handling of specific keys you can create and use Phaser.Key objects.
Name | Type | Description |
---|---|---|
game | Phaser.Game | Current game instance. |
keycode | integer | The key code this Key is responsible for. See Phaser.KeyCode. |
The down state of the ALT key, if pressed at the same time as this key.
The down state of the CTRL key, if pressed at the same time as this key.
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.
Stores the most recent DOM event.
A reference to the currently running game.
The "down" state of the key. This will remain true
for as long as the keyboard thinks this key is held down.
The "up" state of the key. This will remain true
for as long as the keyboard thinks this key is up.
The keycode of this key.
This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again).
A callback that is called while this Key is held down. Warning: Depending on refresh rate that could be 60+ times per second.
The context under which the onHoldCallback will be called.
This Signal is dispatched every time this Key is released. It is only dispatched once (until the key is pressed and released again).
If a key is held down this holds down the number of times the key has 'repeated'.
The down state of the SHIFT key, if pressed at the same time as this key.
The timestamp when the key was last pressed down. This is based on Game.time.now.
The timestamp when the key was last released. This is based on Game.time.now.
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.
Name | Type | Argument | Default | Description |
---|---|---|---|---|
duration | number | <optional> | 50 | The duration within which the key is considered as being just pressed. Given in ms. |
True if the key was pressed down within the given duration.
Called automatically by Phaser.Keyboard.
Name | Type | Description |
---|---|---|
event | KeyboardEvent | The DOM event that triggered this. |
Called automatically by Phaser.Keyboard.
Name | Type | Description |
---|---|---|
event | KeyboardEvent | The DOM event that triggered this. |
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.
Name | Type | Argument | Default | Description |
---|---|---|---|---|
hard | boolean | <optional> | true | A soft reset won't reset any events or callbacks; a hard reset will. |
Called automatically by Phaser.Keyboard.
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.
Name | Type | Argument | Default | Description |
---|---|---|---|---|
duration | number | <optional> | 50 | The duration within which the key is considered as being just released. Given in ms. |
True if the key was released within the given duration.
© 2016 Richard Davey, Photon Storm Ltd.
Licensed under the MIT License.
http://phaser.io/docs/2.6.2/Phaser.Key.html