- Source:
Example
kb.onKeyUp(this, this.myListenerFn, 'ENTER', 'q', 32);
// ...
myListenerFn(key, keyCode, ev){
if (keyCode == 13){
// ENTER pressed
} else if (key == 'SPACE'){
// SPACE PRESSED
}
}
// ...
kb.off(this);
Extends
- PIXI.utils.EventEmitter
Methods
isDown(key, caseInsensitive) → {boolean}
Returns the down state of given key.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
key |
integer | string | kb.KeyConstant | "*" | May be an integer key code, Key constant or single character string. | |
caseInsensitive |
boolean | false | If true and supplied a single char string will check for both upper and lower case variations. |
- Source:
Returns:
isDown - Key down state.
- Type
- boolean
off(contextopt, listeneropt, …keyopt)
Unregisters key up and key down listeners.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
context |
* |
<optional> |
null | Optional context for callback. If only supplied argument then all events registered with the supplied context will be unregistered. |
listener |
kb.KeyEventCallback |
<optional> |
null | Callback function. If supplied without any keys specified (or `*` key) then all key listeners associated with the given listener will be removed. |
key |
integer | string | kb.KeyConstant | "*" |
<optional> <repeatable> |
null | An integer key code, a single character string or a key constant. Can be an asterix for all (`*`). |
- Source:
Example
kb.off(this); // Removes all keyboard event listeners for instance
offKeyDown(contextopt, listeneropt, …keyopt)
Unregisters key down callback with matching criteria.
- Same as `off()` though only targets up events.
- Same as `off()` though only targets up events.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
context |
* |
<optional> |
null | Optional context for callback. |
listener |
kb.KeyEventCallback |
<optional> |
null | Callback function. |
key |
integer | string | kb.KeyConstant | "*" |
<optional> <repeatable> |
null | An integer key code, a single character string or a key constant. Can be an asterix for all (`*`). |
- Source:
offKeyUp(contextopt, listeneropt, …keyopt)
Unregisters key up callback with matching criteria.
- Same as `off()` though only targets up events.
- Same as `off()` though only targets up events.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
context |
* |
<optional> |
null | Optional context for callback. |
listener |
kb.KeyEventCallback |
<optional> |
null | Callback function. |
key |
integer | string | kb.KeyConstant | "*" |
<optional> <repeatable> |
null | An integer key code, a single character string or a key constant. Can be an asterix for all (`*`). |
- Source:
onceKeyDown(contextopt, listener, …key)
Registers callback on key down event for provided key/s.
- Will only be fired once.
- Will only be fired once.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
context |
* |
<optional> |
null | Optional context for callback. |
listener |
kb.KeyEventCallback | Callback function. | ||
key |
integer | string | kb.KeyConstant | "*" |
<repeatable> |
An integer key code, a single character string or a key constant. Can be an asterix for all (`*`). |
- Source:
onceKeyUp(contextopt, listener, …key)
Registers callback on key up event for provided key/s.
- Will only be fired once.
- Will only be fired once.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
context |
* |
<optional> |
null | Optional context for callback. |
listener |
kb.KeyEventCallback | Callback function. | ||
key |
integer | string | kb.KeyConstant | "*" |
<repeatable> |
An integer key code, a single character string or a key constant. Can be an asterix for all (`*`). |
- Source:
onKeyDown(contextopt, listener, …key)
Registers callback on key down event for provided key/s.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
context |
* |
<optional> |
null | Optional context for callback. |
listener |
kb.KeyEventCallback | Callback function. | ||
key |
integer | string | kb.KeyConstant | "*" |
<repeatable> |
An integer key code, a single character string or a key constant. Can be an asterix for all (`*`). |
- Source:
onKeyUp(contextopt, listener, …key)
Registers callback on key up event for provided key/s.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
context |
* |
<optional> |
null | Optional context for callback. |
listener |
kb.KeyEventCallback | Callback function. | ||
key |
integer | string | kb.KeyConstant | "*" |
<repeatable> |
An integer key code, a single character string or a key constant. Can be an asterix for all (`*`). |
- Source:
Type Definitions
KeyConstant
A string constant representing a specific key.
-"META" is the command key on Mac.
-"META" is the command key on Mac.
Type:
- "ENTER" | "SPACE" | "ESC" | "LEFT" | "RIGHT" | "UP" | "META" | "CNTRL"
- Source:
KeyEventCallback(key, keyCode, ev)
A callback fired after a registered keyboard event fires.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | Key represented as a string. |
keyCode |
integer | The key code. |
ev |
Event | Event that triggered the callback. |
- Source: