InputManager

InputManager

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

Constructor

new InputManager()

Source:

Methods

anyKeyPressed()

Return true if any key is pressed.

Returns:
Type Description

true if any key is pressed.

Source:

anyKeyReleased()

Return true if any key is released.

Returns:
Type Description

true if any key is released.

Source:

getAllTouchIdentifiers()

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

Source:

getLastPressedKey()

Return the location-aware code of the last key that was pressed.

Returns:
Type Description

The location-aware code of the last key pressed.

Source:

getMouseWheelDelta()

Return the mouse wheel delta

Source:

getMouseX()

Get the mouse X position.

Returns:
Type Description

the mouse X position, relative to the game view.

Source:

getMouseY()

Get the mouse Y position.

Returns:
Type Description

the mouse Y position, relative to the game view.

Source:

getTouchX()

Get a touch X position.

Returns:
Type Description

the touch X position, relative to the game view.

Source:

getTouchY()

Get a touch Y position.

Returns:
Type Description

the touch Y position, relative to the game view.

Source:

isKeyPressed(locationAwareKeyCode)

Return true if the key corresponding to the location-aware keyCode is pressed.

Parameters:
Name Type Description
locationAwareKeyCode

The location-aware key code to be tested.

Source:

isMouseButtonPressed(buttonCode)

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

Parameters:
Name Type Description
buttonCode

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

Source:

isMouseButtonReleased(buttonCode)

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

Parameters:
Name Type Description
buttonCode

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

Source:

isScrollingDown()

Return true if the mouse wheel scroll to down

Source:

isScrollingUp()

Return true if the mouse wheel scroll to up

Source:

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). You don't need to call it otherwise.

Source:

onKeyPressed(keyCode, location)

Should be called whenever a key is pressed. The location corresponds to KeyboardEvent.location, which should be 0 for standard keys, 1 for left keys, 2 for right keys, and 3 for numpad keys.

Parameters:
Name Type Description
keyCode

The raw key code associated to the key press.

location

The location of the event.

Source:

onKeyReleased(keyCode, location)

Should be called whenever a key is released. The location corresponds to KeyboardEvent.location, which should be 0 for standard keys, 1 for left keys, 2 for right keys, and 3 for numpad keys.

Parameters:
Name Type Description
keyCode

The raw key code associated to the key release.

location

The location of the event.

Source:

onMouseButtonPressed(buttonCode)

Should be called whenever a mouse button is pressed.

Parameters:
Name Type Description
buttonCode

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

Source:

onMouseButtonReleased(buttonCode)

Should be called whenever a mouse button is released.

Parameters:
Name Type Description
buttonCode

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

Source:

onMouseMove(x, y)

Should be called when the mouse is moved.

Please note that the coordinates must be expressed relative to the view position.

Parameters:
Name Type Description
x

The mouse new X position

y

The mouse new Y position

Source:

onMouseWheel(wheelDelta)

Should be called whenever the mouse wheel is used

Parameters:
Name Type Description
wheelDelta

The mouse wheel delta

Source:

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.

Parameters:
Name Type Description
enable

true to simulate mouse events, false to disable it.

Source:

wasKeyReleased(locationAwareKeyCode)

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

Parameters:
Name Type Description
locationAwareKeyCode

The location-aware key code to be tested.

Source: