new Key(game, keycode)
Parameters:
| Name | Type | Description |
|---|---|---|
game |
Phaser.Game | Current game instance. |
keycode |
number | The key code this Key is responsible for. |
- Source:
Members
-
altKey
-
- Default Value:
- false
- Source:
Properties:
Name Type Description altKeyboolean The down state of the ALT key, if pressed at the same time as this key.
-
ctrlKey
-
- Default Value:
- false
- Source:
Properties:
Name Type Description ctrlKeyboolean The down state of the CTRL key, if pressed at the same time as this key.
-
duration
-
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.
- Default Value:
- 0
- Source:
Properties:
Name Type Description durationnumber The number of milliseconds this key has been held down for.
-
enabled
-
- Default Value:
- true
- Source:
Properties:
Name Type Description enabledboolean An enabled key processes its update and dispatches events. You can toggle this at run-time to disable a key without deleting it.
-
<readonly> event
-
- Source:
Properties:
Name Type Description eventobject Stores the most recent DOM event.
-
game
-
- Source:
Properties:
Name Type Description gamePhaser.Game A reference to the currently running game.
-
isDown
-
- Default Value:
- false
- Source:
Properties:
Name Type Description isDownboolean The "down" state of the key.
-
isUp
-
- Default Value:
- true
- Source:
Properties:
Name Type Description isUpboolean The "up" state of the key.
-
keyCode
-
- Source:
Properties:
Name Type Description keyCodenumber The keycode of this key.
-
onDown
-
- Source:
Properties:
Name Type Description onDownPhaser.Signal This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again).
-
onHoldCallback
-
- Source:
Properties:
Name Type Description onHoldCallbackfunction A callback that is called while this Key is held down. Warning: Depending on refresh rate that could be 60+ times per second.
-
onHoldContext
-
- Source:
Properties:
Name Type Description onHoldContextobject The context under which the onHoldCallback will be called.
-
onUp
-
- Source:
Properties:
Name Type Description onUpPhaser.Signal This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again).
-
repeats
-
- Default Value:
- 0
- Source:
Properties:
Name Type Description repeatsnumber If a key is held down this holds down the number of times the key has 'repeated'.
-
shiftKey
-
- Default Value:
- false
- Source:
Properties:
Name Type Description shiftKeyboolean The down state of the SHIFT key, if pressed at the same time as this key.
-
timeDown
-
- Source:
Properties:
Name Type Description timeDownnumber The timestamp when the key was last pressed down. This is based on Game.time.now.
-
timeUp
-
- Source:
Properties:
Name Type Description timeUpnumber The timestamp when the key was last released. This is based on Game.time.now.
Methods
-
justPressed(duration) → {boolean}
-
Returns the "just pressed" state of the Key. Just pressed is considered true if the key was pressed down within the duration given.
Parameters:
Name Type Argument Default Description durationnumber <optional>
50 The duration below which the key is considered as being just pressed.
- Source:
Returns:
True if the key is just pressed otherwise false.
- Type
- boolean
-
justReleased(duration) → {boolean}
-
Returns the "just released" state of the Key. Just released is considered as being true if the key was released within the duration given.
Parameters:
Name Type Argument Default Description durationnumber <optional>
50 The duration below which the key is considered as being just released.
- Source:
Returns:
True if the key is just released otherwise false.
- Type
- boolean
-
<protected> processKeyDown()
-
Called automatically by Phaser.Keyboard.
Parameters:
Name Type Description event.KeyboardEvent - Source:
-
<protected> processKeyUp()
-
Called automatically by Phaser.Keyboard.
Parameters:
Name Type Description event.KeyboardEvent - Source:
-
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 clears any callbacks associated with the onDown and onUp events and nulls the onHoldCallback if set.
Parameters:
Name Type Argument Default Description hardboolean <optional>
true A soft reset won't reset any events or callbacks that are bound to this Key. A hard reset will.
- Source: