Constructor
new KeyboardHandler(parentHandler, condition)
Create a new keyboard input handler.
Parameters:
Name | Type | Description |
---|---|---|
parentHandler | EventHandler | | Parent event handler or layer |
condition | function | Function for checking whether events should run |
Extends
Methods
(protected) _doDown(key, args)
Fire a specific key if there are events listening for it.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
key | any | Key to fire | |
args | any | null | Optional arguments to pass into function |
- Overrides
(protected) _doPress(key, args)
Fire a specific key if there are events listening for it.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
key | any | Key to fire | |
args | any | null | Optional arguments to pass into function |
- Overrides
(protected) _doRelease(key, args)
Fire a specific key if there are events listening for it.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
key | any | Key to fire | |
args | any | null | Optional arguments to pass into function |
- Overrides
destructor()
Handle deletion of the handler and its input listeners.
- Overrides
gameFocused() → {boolean}
Check if the game is in focus (user is not focused on input).
- Overrides
Returns:
Whether the game is focused
- Type:
- boolean
isDown(key) → {boolean}
Check if a key is currently being held down.
Parameters:
Name | Type | Description |
---|---|---|
key | any | Key to check for |
- Overrides
Returns:
Whether key is being held down
- Type:
- boolean
onPress(key, func)
Add an event to listen for a specific key press. Will fire once.
Parameters:
Name | Type | Description |
---|---|---|
key | any | | Key(s) to listen for |
func | function | Function to run upon firing |
- Overrides
onRelease(key, func)
Add an event to listen for a specific key release. Will fire once.
Parameters:
Name | Type | Description |
---|---|---|
key | any | | Key(s) to listen for |
func | function | Function to run upon firing |
- Overrides
whileDown(key, func)
Add an event to fire while a key is pressed down. Fires continuously.
Parameters:
Name | Type | Description |
---|---|---|
key | any | | Key(s) to listen for |
func | function | Function to run upon firing |
- Overrides