Kiwi.Input.Keyboard Class
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
Parameters:
-
game
Kiwi.Game
Returns:
This object
Item Index
Methods
Methods
_keyPressed
-
event.
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.
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]
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
NumberThe keycode of the key that you want to add.
-
[preventDefault=false]
Boolean optionalIf 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
Returns a boolean indicating whether a key (that you pass via its keycode) is down or not.
Parameters:
-
keycode
NumberThe keycode of the key that you are checking.
Returns:
isUp
-
keycode
Returns a boolean indicating whether a key (that you pass via its keycode) is up or not.
Parameters:
-
keycode
NumberThe keycode of the key that you are checking.
Returns:
justPressed
-
keycode
-
[duration=this.justPressedRate]
Returns a boolean indicating if a key (that you pass via a keycode) was just pressed or not.
Parameters:
-
keycode
NumberThe keycode of the key that you would like to check against.
-
[duration=this.justPressedRate]
Number optionalThe duration which determines if a key was 'just' pressed or not. If not specified defaults to the
justPressedRate
justReleased
-
keycode
-
[duration=this.justReleasedRate]
Returns a boolean indicating if a key (that you pass via a keycode) was just released or not.
Parameters:
-
keycode
NumberThe keycode of the key that you would like to check against.
-
[duration=this.justReleasedRate]
Number optionalThe 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:
"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.
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.