API Docs for: 1.0.1

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 optional

    Options

    • [reservedKeys] Array optional

      keys for which browser's default action will be prevented. The Game class passes this property when instantiating the input.

Methods

isDown

(
  • key
)
Boolean

Tells whether the user is holding a key.

Parameters:

  • key String

    Key id

Returns:

Boolean:

true, if held.

isPressed

(
  • {String
)
Boolean

Tells whether the given key was pressed since the previous frame.

Parameters:

  • {String Object

    key Key id

Returns:

Boolean:

true, if the key wasn't held in the last frame but now is.

isReleased

(
  • key
)
Boolean

Tells whether the given key was released since the last frame.

Parameters:

  • key String

    Key id

Returns:

Boolean:

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 Array

    Key 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 is held in the current frame.

keyPress.<key>

Fires when the was pressed since the last frame.

keyRelease.<key>

Fires when the was released since the last frame.

mouseMove

When the mouse moves, this is the second event emitted. The parameter is the mouse property of the input instance.