kick.core.KeyInput Class
Key Input manager.
This class encapsulates keyboard input and makes it easy to
test for key input.
Example code:
Constructor
kick.core.KeyInput
()
Example:
function KeyTestComponent(){
var keyInput, thisObj = this;
// registers listener (invoked when component is registered)
this.activated = function (){
var engine = kick.core.Engine.instance;
keyInput = engine.keyInput;
};
this.update = function(){
var keyCodeForA = "A".charCodeAt(0);
if (keyInput.isKeyDown(keyCodeForA)){
console.log("A key is down");
}
if (keyInput.isKey(keyCodeForA)){
console.log("A key is being held down");
}
if (keyInput.isKeyUp(keyCodeForA)){
console.log("A key is up");
}
};
}
Pressing the 'a' key should result in one frame with 'A key is down', multiple frames with 'A key is being held down' and finally one frame with 'A key is up'
Item Index
Methods
isAnyKey
()
Boolean
Returns:
Boolean:
true if any key is down
isAnyKeyDown
()
Boolean
Returns:
Boolean:
true if any key is pressed down in this frame
isAnyKeyUp
()
Boolean
Returns:
Boolean:
true if any key is release in this frame
isKey
(
Boolean
-
keyCode
Parameters:
-
keyCode
Number
Returns:
Boolean:
true if key is down
isKeyDown
(
Boolean
-
keyCode
Parameters:
-
keyCode
Number
Returns:
Boolean:
true if key is pressed down in this frame
isKeyUp
(
Boolean
-
keyCode
Parameters:
-
keyCode
Number
Returns:
Boolean:
true if key is release in this frame
update
()
private
This method clears key up and key downs each frame (leaving key unmodified)