API Docs for: v0.1.0
Show:

Keyboard Class

Extends Input

Controls keyboard input

Constructor

Keyboard

(
  • game
)

Parameters:

  • game Game

    The game instance this input belongs to

Methods

_clearSequence

() private

Clears the current sequence so that a new one can start

_getEventData

(
  • event
  • down
)
Object private

Generates an event data object for a keyboard event

Parameters:

  • event DOMEvent

    The original DOMEvent that was passed into the raw event handler

  • down Boolean

    Is this a keydown event

Returns:

Object:

The event object

emit

(
  • type
  • data
)
Mixed chainable

Emits an event which will run all registered listeners for the event type

Parameters:

  • type String

    The event name to emit

  • data Mixed

    Any data you want passed along with the event

Returns:

Mixed:

Returns itself.

modifyKey

(
  • event
  • key
  • down
)
private

Called when a key state has changed, updates current sequence and emits events

Parameters:

  • event DOMEvent
  • key Number

    The key code that has changed

  • down Boolean

    Whether the key has been pressed or not

off

(
  • type
  • listener
)
Mixed chainable

Removes a listener function for an event type

Parameters:

  • type String

    The event name to emit

  • listener Function

    The function to remove

Returns:

Mixed:

Returns itself.

on

(
  • type
  • listener
)
Mixed chainable

Registers a listener function to be run on an event occurance

Parameters:

  • type String

    The event name to listen for

  • listener Function

    The function to execute when the event happens

Returns:

Mixed:

Returns itself.

once

(
  • type
  • listener
)
Mixed chainable

Registers a one-time callback for an event

Parameters:

  • type String

    The event name to listen for

  • listener Function

    the callback to call when the event occurs

Returns:

Mixed:

Returns itself.

onKeyDown

(
  • event
  • override
)
private

Called when a key is pressed down

Parameters:

  • event DOMEvent
  • override Number

    The key code to use instead of checking event data

onKeyUp

(
  • event
  • override
)
private

Called when a key is released

Parameters:

  • event DOMEvent
  • override Number

    The key code to use instead of checking event data

Properties

_clearSq

Number private

The timeout ID for the wait to clear the input sequence

game

Game

Inherited from Input: src\input\Input.js:16

The game instance this input belongs to

KEY

Object static

Bindable keycodes

sequence

Array

The current sequence of keys that have been pressed

sequenceTimeout

Number

The amount of time it takes for the sequence to clear out, in ms

Default: 500