A generic Key object which can be passed to the Process functions (and so on) keycode must be an integer
new Key(plugin, keyCode)
name | type | description |
---|---|---|
plugin | Phaser.Input.Keyboard.KeyboardPlugin |
The Keyboard Plugin instance that owns this Key object. |
keyCode | number |
The keycode of this key. |
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.
The number of milliseconds this key was held down for in the previous down - up sequence.
This value isn't updated every game step, only when the Key changes state.
To get the current duration use the getDuration
method.
When a key is held down should it continuously fire the down
event each time it repeats?
By default it will emit the down
event just once, but if you wish to receive the event
for each repeat as well, enable this property.
Can this Key be processed?
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.
The location of the modifier key. 0 for standard (or unknown), 1 for left, 2 for right, 3 for numpad.
The down state of the Meta key, if pressed at the same time as this key. On a Mac the Meta Key is the Command key. On Windows keyboards, it's the Windows key.
The original DOM event.
The Keyboard Plugin instance that owns this Key object.
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.
The timestamp when the key was last released.
Add a listener for a given event.
name | type | arguments | Default | description |
---|---|---|---|---|
event | string | symbol |
The event name. |
||
fn | function |
The listener function. |
||
context | * | <optional> | this |
The context to invoke the listener with. |
this
.
Removes any bound event handlers and removes local references.
Calls each of the listeners registered for a given event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol |
The event name. |
|
args | * | <optional> |
Additional arguments that will be passed to the event handler. |
true
if the event had listeners, else false
.
Return an array listing the events for which the emitter has registered listeners.
Returns the duration, in ms, that the Key has been held down for.
If the key is not currently down it will return zero.
To get the duration the Key was held down for in the previous up-down cycle,
use the Key.duration
property value instead.
The duration, in ms, that the Key has been held down for if currently down.
Return the number of listeners listening to a given event.
name | type | description |
---|---|---|
event | string | symbol |
The event name. |
The number of listeners.
Return the listeners registered for a given event.
name | type | description |
---|---|---|
event | string | symbol |
The event name. |
The registered listeners.
Remove the listeners of a given event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol |
The event name. |
|
fn | function | <optional> |
Only remove the listeners that match this function. |
context | * | <optional> |
Only remove the listeners that have this context. |
once | boolean | <optional> |
Only remove one-time listeners. |
this
.
Add a listener for a given event.
name | type | arguments | Default | description |
---|---|---|---|---|
event | string | symbol |
The event name. |
||
fn | function |
The listener function. |
||
context | * | <optional> | this |
The context to invoke the listener with. |
this
.
Processes the Key Down action for this Key. Called automatically by the Keyboard Plugin.
name | type | description |
---|---|---|
event | KeyboardEvent |
The native DOM Keyboard event. |
Processes the Key Up action for this Key. Called automatically by the Keyboard Plugin.
name | type | description |
---|---|---|
event | KeyboardEvent |
The native DOM Keyboard event. |
Add a one-time listener for a given event.
name | type | arguments | Default | description |
---|---|---|---|---|
event | string | symbol |
The event name. |
||
fn | function |
The listener function. |
||
context | * | <optional> | this |
The context to invoke the listener with. |
this
.
Remove all listeners, or those of the specified event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol | <optional> |
The event name. |
this
.
Remove the listeners of a given event.
name | type | arguments | description |
---|---|---|---|
event | string | symbol |
The event name. |
|
fn | function | <optional> |
Only remove the listeners that match this function. |
context | * | <optional> |
Only remove the listeners that have this context. |
once | boolean | <optional> |
Only remove one-time listeners. |
this
.
Resets this Key object back to its default un-pressed state.
As of version 3.60.0 it no longer resets the enabled
or preventDefault
flags.
This Key instance.
Controls if this Key will continuously emit a down
event while being held down (true),
or emit the event just once, on first press, and then skip future events (false).
name | type | description |
---|---|---|
value | boolean |
Emit |
This Key instance.
Removes all listeners.