InputHandler

Abstract input handler. Used for handling input events.

Constructor

(abstract) new InputHandler(parentHandler, prefix, condition)

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

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