Constructor
new Keyboard(optionsopt)
Creates a new instance of the Keyboard class.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
options |
Object |
<optional> |
Keyboard settings. |
- Source:
Members
(static, constant) NUM_KEYS :number
Number of keys.
Type:
- number
- Source:
enabled :boolean
Whether the keyboard should be activated or not. An inactive (false)
keyboard, registers no input.
Type:
- boolean
- Source:
Methods
axis(negativeKey, positiveKey) → {number}
Reads two keys as a directional axis. The negative key contributes -1 and
the positive key contributes 1. Returns zero when both or neither are pressed.
Unknown keys are treated as released, using the same lookup as pressed().
Parameters:
| Name | Type | Description |
|---|---|---|
negativeKey |
string | Key for the negative direction, such as "LEFT". |
positiveKey |
string | Key for the positive direction, such as "RIGHT". |
- Source:
Returns:
The axis value: -1, 0 or 1.
- Type
- number
justPressed(key) → {boolean}
Checks if the specified key was just pressed.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | A valid key, such as "SPACE". |
- Source:
Returns:
- Type
- boolean
justReleased(key) → {boolean}
Checks if the specified key has just been released.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | A valid key, such as "SPACE". |
- Source:
Returns:
- Type
- boolean
pressed(key) → {boolean}
Checks if the specified key is pressed.
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | A valid key, such as "SPACE". |
- Source:
Returns:
- Type
- boolean
reset() → {undefined}
Resets the state of all keyboard keys.
- Source:
Returns:
- Type
- undefined