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)none
mouseLeft
mouseMiddle
mouseRight
a
...z
(letter keys)0
...9
(digit keys)num0
...num9
(numpad keys)f1
...f12
(function keys)backspace
tab
enter
lshift
(left shift)rshift
(right shift)ctrl
alt
pause
clear
esc
space
pageup
pagedown
end
home
left
right
up
down<
/li>insert
delete
windows
contextmenu
+
-
*
.
/
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:
-
key
StringKey id
Returns:
true, if held.
isPressed
-
{String
Tells whether the given key was pressed since the previous frame.
Parameters:
-
{String
Objectkey 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:
-
key
StringKey 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:
-
keys
ArrayKey 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.