KeyboardHandler

Keyboard input handler.

Constructor

new KeyboardHandler(parentHandler, condition)

Create a new keyboard input handler.
Parameters:
NameTypeDescription
parentHandlerEventHandler | EventHandlerLayerParent event handler or layer
conditionfunctionFunction for checking whether events should run

Extends

Methods

(protected) _doDown(key, args)

Fire a specific key if there are events listening for it.
Parameters:
NameTypeDefaultDescription
keyanyKey to fire
argsanynullOptional arguments to pass into function

(protected) _doPress(key, args)

Fire a specific key if there are events listening for it.
Parameters:
NameTypeDefaultDescription
keyanyKey to fire
argsanynullOptional arguments to pass into function

(protected) _doRelease(key, args)

Fire a specific key if there are events listening for it.
Parameters:
NameTypeDefaultDescription
keyanyKey to fire
argsanynullOptional arguments to pass into function

destructor()

Handle deletion of the handler and its input listeners.

gameFocused() → {boolean}

Check if the game is in focus (user is not focused on input).
Returns:
Whether the game is focused
Type: 
boolean

isDown(key) → {boolean}

Check if a key is currently being held down.
Parameters:
NameTypeDescription
keyanyKey to check for
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:
NameTypeDescription
keyany | Array.<any>Key(s) to listen for
funcfunctionFunction to run upon firing

onRelease(key, func)

Add an event to listen for a specific key release. Will fire once.
Parameters:
NameTypeDescription
keyany | Array.<any>Key(s) to listen for
funcfunctionFunction to run upon firing

whileDown(key, func)

Add an event to fire while a key is pressed down. Fires continuously.
Parameters:
NameTypeDescription
keyany | Array.<any>Key(s) to listen for
funcfunctionFunction to run upon firing