Grape.Input Class
Handles which key is down, just pressed or just released in a game. A Game Also handles mouse. The following keys are available:
any(matches any key)nonemouseLeftmouseMiddlemouseRighta...z(letter keys)0...9(digit keys)num0...num9(numpad keys)f1...f12(function keys)backspacetabenterlshift(left shift)rshift(right shift)ctrlaltpauseclearescspacepageuppagedownendhomeleftrightupdown</li>insertdeletewindowscontextmenu+-*./numlock
Constructor
Grape.Input
-
[opts]
Parameters:
-
[opts]Object optionalOptions
-
[reservedKeys]Array optionalkeys for which browser's default action will be prevented. The Game class passes this property when instantiating the input.
-
Item Index
Methods
isDown
-
key
Tells whether the user is holding a key.
Parameters:
-
keyStringKey id
Returns:
true, if held.
isPressed
-
{String
Tells whether the given key was pressed since the previous frame.
Parameters:
-
{StringObjectkey Key id
Returns:
true, if the key wasn't held in the last frame but now is.
isReleased
-
key
Tells whether the given key was released since the last frame.
Parameters:
-
keyStringKey id
Returns:
true, if the key was held in the last frame and now isn't.
resetKeys
()
Resets the status of the input system. Since this point all key is considered as it wasn't held. When a key is released when the document is not in focus (like during an alert call), it can be used.
setReservedKeys
-
keys
Sets the keys which would prevent the browser's default action to be triggered.
Parameters:
-
keysArrayKey ids
Properties
mouse
Object
static
An object which stores the mouse position relative to the page. In the most cases you want to use the instance level mouse property instead.
mouse
Object
The x and y coordinates of the mouse relative to the game screen.
mouse.x
Number
static
Mouse x relative to document.
mouse.y
Number
static
Mouse y relative to document.
Events
afterMouseMove
When the mouse moves, this is the third event emitted. The parameter is the mouse property of the input instance.
beforeMouseMove
When the mouse moves, this is the first event emitted. The parameter is the mouse property of the input instance.
keyDown.<key>
Fires when the
keyPress.<key>
Fires when the
keyRelease.<key>
Fires when the
mouseMove
When the mouse moves, this is the second event emitted. The parameter is the mouse property of the input instance.
