Class: InputManager

InputManager

InputManager

new gdjs.InputManager()

Store input made on a canvas: mouse position, key pressed and touches states.

See bindStandardEvents method for connecting the input manager to a canvas and onFrameEnded for signaling the end of a frame (necessary for proper touches events handling).

Members

static,constantgdjs.InputManager.MOUSE_LEFT_BUTTONnumber

static,constantgdjs.InputManager.MOUSE_MIDDLE_BUTTONnumber

static,constantgdjs.InputManager.MOUSE_RIGHT_BUTTONnumber

Methods

anyKeyPressed()

Return true if any key is pressed

getAllTouchIdentifiers()

Update and return the array containing the identifiers of all touches.

getLastPressedKey(){number}

Return the code of the last key that was pressed.

Returns:
Type Description
number The code of the last key pressed.

getMouseWheelDelta()

Return the mouse wheel delta

getMouseX()

Get the mouse X position

Returns:
the mouse X position, relative to the game view.

getMouseY()

Get the mouse Y position

Returns:
the mouse Y position, relative to the game view.

getTouchX()

Get a touch X position

Returns:
the touch X position, relative to the game view.

getTouchY()

Get a touch Y position

Returns:
the touch Y position, relative to the game view.

isKeyPressed(keyCode)

Return true if the key corresponding to keyCode is pressed.

Name Type Description
keyCode number

The key code to be tested.

isMouseButtonPressed(buttonCode)

Return true if the mouse button corresponding to buttonCode is pressed.

Name Type Description
buttonCode number

The mouse button code (0: Left button, 1: Right button).

isMouseButtonReleased(buttonCode)

Return true if the mouse button corresponding to buttonCode was just released.

Name Type Description
buttonCode number

The mouse button code (0: Left button, 1: Right button).

isScrollingDown()

Return true if the mouse wheel scroll to down

isScrollingUp()

Return true if the mouse wheel scroll to up

onFrameEnded()

Notify the input manager that the frame ended, so anything that last only for one frame (started/ended touches) should be reset.

This method should be called in the game loop (see gdjs.RuntimeGame.startGameLoop).

onKeyPressed(keyCode)

Should be called whenever a key is pressed

Name Type Description
keyCode number

The key code associated to the key press.

onKeyReleased(keyCode)

Should be called whenever a key is released

Name Type Description
keyCode number

The key code associated to the key release.

onMouseButtonPressed(buttonCode)

Should be called whenever a mouse button is pressed

Name Type Description
buttonCode number

The mouse button code associated to the event. See gdjs.InputManager.MOUSE_LEFT_BUTTON, gdjs.InputManager.MOUSE_RIGHT_BUTTON, gdjs.InputManager.MOUSE_MIDDLE_BUTTON

onMouseButtonReleased(buttonCode)

Should be called whenever a mouse button is released

Name Type Description
buttonCode number

The mouse button code associated to the event. (see onMouseButtonPressed)

onMouseMove(x, y)

Should be called when the mouse is moved.
Please note that the coordinates must be expressed relative to the view position.

Name Type Description
x number

The mouse new X position

y number

The mouse new Y position

onMouseWheel(wheelDelta)

Should be called whenever the mouse wheel is used

Name Type Description
wheelDelta number

The mouse wheel delta

touchSimulateMouse(enable)

Set if touch events should simulate mouse events.

If true, any touch will move the mouse position and set mouse buttons as pressed/released.

Name Type Description
enable Boolean

true to simulate mouse events, false to disable it.

wasKeyReleased(keyCode)

Return true if the key corresponding to keyCode was released during the last frame.

Name Type Description
keyCode number

The key code to be tested.