API Docs for: 1.4.0
Show:

Kiwi.Input.Keyboard Class

Module: Input
Parent Module: Kiwi

Handles and manages the dispatching of keyboard events. When the user presses a button a new Key object is created.

Constructor

Kiwi.Input.Keyboard

(
  • game
)
Kiwi.Input.Keyboard

Parameters:

Returns:

Kiwi.Input.Keyboard:

This object

Methods

_keyPressed

(
  • event.
)
private

Is executed when a key is pressed/is down. This then either creates a new Key (if one does not currently exist) for that keycode, or it updates the key that was pressed (if one does exist).

Parameters:

  • event. KeyboardEvent

_keyReleased

(
  • event.
)
private

Is executed when a key is release/is now up. This then either creates a new Key (if one does not currently exist) for that keycode, or it updates the key that was released (if one does exist).

Parameters:

  • event. KeyboardEvent

addKey

(
  • keycode
  • [preventDefault=false]
)
Kiwi.Input.Key public

Creates a new Key object for a keycode that is specified. Not strictly needed (as one will be created once an event occurs on that keycode) but can be good for setting the game up and choosing whether to prevent default action on that key.

Parameters:

  • keycode Number

    The keycode of the key that you want to add.

  • [preventDefault=false] Boolean optional

    If the default action for that key should be prevented or not when an event fires.

Returns:

boot

() public

Is executed when the DOMElements that are need to get the game going are loaded and thus the game can 'boot'

isDown

(
  • keycode
)
Boolean public

Returns a boolean indicating whether a key (that you pass via its keycode) is down or not.

Parameters:

  • keycode Number

    The keycode of the key that you are checking.

Returns:

Boolean:

isUp

(
  • keycode
)
Boolean public

Returns a boolean indicating whether a key (that you pass via its keycode) is up or not.

Parameters:

  • keycode Number

    The keycode of the key that you are checking.

Returns:

Boolean:

justPressed

(
  • keycode
  • [duration=this.justPressedRate]
)
public

Returns a boolean indicating if a key (that you pass via a keycode) was just pressed or not.

Parameters:

  • keycode Number

    The keycode of the key that you would like to check against.

  • [duration=this.justPressedRate] Number optional

    The duration which determines if a key was 'just' pressed or not. If not specified defaults to the justPressedRate

justReleased

(
  • keycode
  • [duration=this.justReleasedRate]
)
public

Returns a boolean indicating if a key (that you pass via a keycode) was just released or not.

Parameters:

  • keycode Number

    The keycode of the key that you would like to check against.

  • [duration=this.justReleasedRate] Number optional

    The duration which determines if a key was 'just' released or not. If not specified defaults to the justReleasedRate

objType

() String public

Type of object that this is

Returns:

String:

"Keyboard"

reset

() public

Executes the reset method on every Key that currently exists.

start

() public

Adds the event listeners to the browser to listen for key events.

stop

() public

Removes the event listeners and so effectively stops all keyboard events.

update

() public

The update loop that is executed every frame.

Properties

_keys

Key private

Contains a reference to each Key object when they are either added to this Keyboard manager (by the developer), or when an event fires with that keycode.

game

Kiwi.Game public

Game that this Keyboard belongs to

justPressedRate

Number public

The time in milliseconds which determines if a key was just pressed or not.

Default: 200

justReleasedRate

Number public

The time in milliseconds which determines if a key was just released or not.

Default: 200

keys

Keys public

Returns all of the Key objects that currently exist. This is READ ONLY.

onKeyDown

Kiwi.Signal public

A Signal that dispatches events when a key is pressed/is down. This mimics the natural keydown event listener, so it will keep dispatching events if the user holds the key down.

Note: This fires after the 'onKeyDownOnce' signal.

Callbacks fired by this Signal will contain two parameters: the keyCode and key object. 1) KeyCode - The keyCode of the key that was just released. 2) Key - The key object for that keycode.

onKeyDownOnce

Kiwi.Signal public

A Signal that dispatches events when a key is pressed/ is down initially. This event only fires the first time that the key is pressed, so it won't dispatch events if the user is holding the key down.

Note: This fires before the 'onKeyDown' signal.

Callbacks fired by this Signal will contain two parameters: the keyCode and key object. 1) KeyCode - The keyCode of the key that was just released. 2) Key - The key object for that keycode.

onKeyUp

Kiwi.Signal public

A Signal that dispatches events when a key is released/is now up.

Callbacks fired by this Signal will contain two parameters: the keyCode and key object. 1) KeyCode - The keyCode of the key that was just released. 2) Key - The key object for that keycode.