new Key(plugin, keyCode)
Parameters:
Name | Type | Description |
---|---|---|
plugin |
Phaser.Input.Keyboard.KeyboardPlugin | The Keyboard Plugin instance that owns this Key object. |
keyCode |
number | The keycode of this key. |
- Since: 3.0.0
- Source: src/input/keyboard/keys/Key.js (Line 11)
Extends
Members
-
altKey :boolean
-
The down state of the ALT key, if pressed at the same time as this key.
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/input/keyboard/keys/Key.js (Line 92)
-
ctrlKey :boolean
-
The down state of the CTRL key, if pressed at the same time as this key.
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/input/keyboard/keys/Key.js (Line 102)
-
duration :number
-
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.Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/input/keyboard/keys/Key.js (Line 153)
-
emitOnRepeat :boolean
-
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.Type:
- boolean
- Since: 3.16.0
- Default Value:
-
- false
- Source: src/input/keyboard/keys/Key.js (Line 175)
-
enabled :boolean
-
Can this Key be processed?
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- true
- Source: src/input/keyboard/keys/Key.js (Line 62)
-
isDown :boolean
-
The "down" state of the key. This will remain
true
for as long as the keyboard thinks this key is held down.Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/input/keyboard/keys/Key.js (Line 72)
-
isUp :boolean
-
The "up" state of the key. This will remain
true
for as long as the keyboard thinks this key is up.Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- true
- Source: src/input/keyboard/keys/Key.js (Line 82)
-
keyCode :number
-
The keycode of this key.
Type:
- number
- Since: 3.0.0
- Source: src/input/keyboard/keys/Key.js (Line 44)
-
location :number
-
The location of the modifier key. 0 for standard (or unknown), 1 for left, 2 for right, 3 for numpad.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/input/keyboard/keys/Key.js (Line 133)
-
metaKey :boolean
-
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.
Type:
- boolean
- Since: 3.16.0
- Default Value:
-
- false
- Source: src/input/keyboard/keys/Key.js (Line 122)
-
originalEvent :KeyboardEvent
-
The original DOM event.
Type:
- KeyboardEvent
- Since: 3.0.0
- Source: src/input/keyboard/keys/Key.js (Line 53)
-
plugin :Phaser.Input.Keyboard.KeyboardPlugin
-
The Keyboard Plugin instance that owns this Key object.
Type:
- Since: 3.17.0
- Source: src/input/keyboard/keys/Key.js (Line 35)
-
repeats :number
-
If a key is held down this holds down the number of times the key has 'repeated'.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/input/keyboard/keys/Key.js (Line 188)
-
shiftKey :boolean
-
The down state of the SHIFT key, if pressed at the same time as this key.
Type:
- boolean
- Since: 3.0.0
- Default Value:
-
- false
- Source: src/input/keyboard/keys/Key.js (Line 112)
-
timeDown :number
-
The timestamp when the key was last pressed down.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/input/keyboard/keys/Key.js (Line 143)
-
timeUp :number
-
The timestamp when the key was last released.
Type:
- number
- Since: 3.0.0
- Default Value:
-
- 0
- Source: src/input/keyboard/keys/Key.js (Line 165)
Methods
-
addListener(event, fn [, context])
-
Add a listener for a given event.
Parameters:
Name Type Argument Default Description event
string | symbol The event name.
fn
function The listener function.
context
* <optional>
this The context to invoke the listener with.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 111)
Returns:
this
. -
destroy()
-
Removes any bound event handlers and removes local references.
- Since: 3.16.0
- Overrides:
- Source: src/input/keyboard/keys/Key.js (Line 379)
-
emit(event [, args])
-
Calls each of the listeners registered for a given event.
Parameters:
Name Type Argument Description event
string | symbol The event name.
args
* <optional>
<repeatable>
Additional arguments that will be passed to the event handler.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 86)
Returns:
true
if the event had listeners, elsefalse
.- Type
- boolean
-
eventNames()
-
Return an array listing the events for which the emitter has registered listeners.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 55)
Returns:
- Type
- Array.<(string|symbol)>
-
getDuration()
-
Returns the duration, in ms, that the Key has been held down for.
If the key is not currently down it will return zero.
The get the duration the Key was held down for in the previous up-down cycle, use the
Key.duration
property value instead.- Since: 3.17.0
- Source: src/input/keyboard/keys/Key.js (Line 354)
Returns:
The duration, in ms, that the Key has been held down for if currently down.
- Type
- number
-
listenerCount(event)
-
Return the number of listeners listening to a given event.
Parameters:
Name Type Description event
string | symbol The event name.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 75)
Returns:
The number of listeners.
- Type
- number
-
listeners(event)
-
Return the listeners registered for a given event.
Parameters:
Name Type Description event
string | symbol The event name.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 64)
Returns:
The registered listeners.
- Type
- Array.<function()>
-
off(event [, fn] [, context] [, once])
-
Remove the listeners of a given event.
Parameters:
Name Type Argument 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.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 151)
Returns:
this
. -
on(event, fn [, context])
-
Add a listener for a given event.
Parameters:
Name Type Argument Default Description event
string | symbol The event name.
fn
function The listener function.
context
* <optional>
this The context to invoke the listener with.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 98)
Returns:
this
. -
once(event, fn [, context])
-
Add a one-time listener for a given event.
Parameters:
Name Type Argument Default Description event
string | symbol The event name.
fn
function The listener function.
context
* <optional>
this The context to invoke the listener with.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 124)
Returns:
this
. -
onDown(event)
-
Processes the Key Down action for this Key. Called automatically by the Keyboard Plugin.
Parameters:
Name Type Description event
KeyboardEvent The native DOM Keyboard event.
- Since: 3.16.0
- Source: src/input/keyboard/keys/Key.js (Line 249)
Fires:
-
onUp(event)
-
Processes the Key Up action for this Key. Called automatically by the Keyboard Plugin.
Parameters:
Name Type Description event
KeyboardEvent The native DOM Keyboard event.
- Since: 3.16.0
- Source: src/input/keyboard/keys/Key.js (Line 293)
Fires:
-
removeAllListeners( [event])
-
Remove all listeners, or those of the specified event.
Parameters:
Name Type Argument Description event
string | symbol <optional>
The event name.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 165)
Returns:
this
. -
removeListener(event [, fn] [, context] [, once])
-
Remove the listeners of a given event.
Parameters:
Name Type Argument 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.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 137)
Returns:
this
. -
reset()
-
Resets this Key object back to its default un-pressed state.
- Since: 3.6.0
- Source: src/input/keyboard/keys/Key.js (Line 325)
Returns:
This Key instance.
-
setEmitOnRepeat(value)
-
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).Parameters:
Name Type Description value
boolean Emit
down
events on repeated key down actions, or just once?- Since: 3.16.0
- Source: src/input/keyboard/keys/Key.js (Line 231)
Returns:
This Key instance.
-
shutdown()
-
Removes all listeners.
- Since: 3.0.0
- Inherited From:
- Source: src/events/EventEmitter.js (Line 31)