Key
Class: Phaser.Key
Constructor
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 code: input/Key.js (Line 15)
Public Properties
- Source code: input/Key.js (Line 51)
- Source code: input/Key.js (Line 57)
- Source code: input/Key.js (Line 76)
- Source code: input/Key.js (Line 33)
- Source code: input/Key.js (Line 20)
- Source code: input/Key.js (Line 39)
- Default Value
- true
- Source code: input/Key.js (Line 45)
- Source code: input/Key.js (Line 93)
- Source code: input/Key.js (Line 98)
- Source code: input/Key.js (Line 103)
- Source code: input/Key.js (Line 108)
- Source code: input/Key.js (Line 113)
- Source code: input/Key.js (Line 88)
- Source code: input/Key.js (Line 63)
- Source code: input/Key.js (Line 68)
- Source code: input/Key.js (Line 82)
altKey : boolean
The down state of the ALT key, if pressed at the same time as this key.
ctrlKey : boolean
The down state of the CTRL key, if pressed at the same time as this key.
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.
[readonly] event : Object
Stores the most recent DOM event.
game : Phaser.Game
A reference to the currently running game.
isDown : boolean
The "down" state of the key. This will remain true
for as long as the keyboard thinks this key is held down.
isUp : boolean
The "up" state of the key. This will remain true
for as long as the keyboard thinks this key is up.
keyCode : number
The keycode of this key.
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).
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.
onHoldContext : Object
The context under which the onHoldCallback will be called.
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).
repeats : number
If a key is held down this holds down the number of times the key has 'repeated'.
shiftKey : boolean
The down state of the SHIFT key, if pressed at the same time as this key.
timeDown : number
The timestamp when the key was last pressed down. This is based on Game.time.now.
timeUp : number
The timestamp when the key was last released. This is based on Game.time.now.
Public Methods
- Source code: input/Key.js (Line 253)
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source code: input/Key.js (Line 154)
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source code: input/Key.js (Line 191)
- Source code: input/Key.js (Line 222)
- Internal:
- This member is internal (protected) and may be modified or removed in the future.
- Source code: input/Key.js (Line 131)
- Source code: input/Key.js (Line 269)
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
True if the key was pressed down within the given duration.
<internal> processKeyDown(event)
Called automatically by Phaser.Keyboard.
Parameters
Name | Type | Description |
---|---|---|
event | KeyboardEvent | The DOM event that triggered this. |
<internal> processKeyUp(event)
Called automatically by Phaser.Keyboard.
Parameters
Name | Type | Description |
---|---|---|
event | KeyboardEvent | The DOM event that triggered this. |
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. |
<internal> update()
Called automatically by Phaser.Keyboard.
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
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