Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

  • InputManager

Index

Properties

MOUSE_BACK_BUTTON: number = 3
MOUSE_FORWARD_BUTTON: number = 4
MOUSE_LEFT_BUTTON: number = 0
MOUSE_MIDDLE_BUTTON: number = 2
MOUSE_RIGHT_BUTTON: number = 1
MOUSE_TOUCH_ID: number = 1

Methods

  • anyKeyPressed(): boolean
  • Return true if any key is pressed.

    Returns boolean

    true if any key is pressed.

  • anyKeyReleased(): boolean
  • Return true if any key is released.

    Returns boolean

    true if any key is released.

  • getAllTouchIdentifiers(): number[]
  • Update and return the array containing the identifiers of all touches.

    Returns number[]

  • getCursorX(): number
  • Get the cursor X position. The cursor is moved by mouse and touch events.

    Returns number

    the cursor X position, relative to the game view.

  • getCursorY(): number
  • Get the cursor Y position. The cursor is moved by mouse and touch events.

    Returns number

    the cursor Y position, relative to the game view.

  • getLastPressedKey(): number
  • Return the location-aware code of the last key that was pressed.

    Returns number

    The location-aware code of the last key pressed.

  • getMouseWheelDelta(): number
  • Return the mouse wheel delta

    Returns number

  • getMouseX(): number
  • Get the mouse X position.

    Returns number

    the mouse X position, relative to the game view.

  • getMouseY(): number
  • Get the mouse Y position.

    Returns number

    the mouse Y position, relative to the game view.

  • getStartedTouchIdentifiers(): number[]
  • Returns number[]

  • getTouchX(publicIdentifier: number): number
  • Get a touch X position.

    Parameters

    • publicIdentifier: number

    Returns number

    the touch X position, relative to the game view.

  • getTouchY(publicIdentifier: number): number
  • Get a touch Y position.

    Parameters

    • publicIdentifier: number

    Returns number

    the touch Y position, relative to the game view.

  • hasTouchEnded(publicIdentifier: number): boolean
  • Parameters

    • publicIdentifier: number

      the touch identifier

    Returns boolean

    true if the touch has just ended.

  • isKeyPressed(locationAwareKeyCode: number): boolean
  • Return true if the key corresponding to the location-aware keyCode is pressed.

    Parameters

    • locationAwareKeyCode: number

      The location-aware key code to be tested.

    Returns boolean

  • isMouseButtonPressed(buttonCode: number): boolean
  • Return true if the mouse button corresponding to buttonCode is pressed.

    Parameters

    • buttonCode: number

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

    Returns boolean

  • isMouseButtonReleased(buttonCode: number): boolean
  • Return true if the mouse button corresponding to buttonCode was just released.

    Parameters

    • buttonCode: number

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

    Returns boolean

  • isMouseInsideCanvas(): boolean
  • Returns boolean

    true when the mouse is inside the canvas.

  • isScrollingDown(): boolean
  • Return true if the mouse wheel scroll to down

    Returns boolean

  • isScrollingUp(): boolean
  • Return true if the mouse wheel scroll to up

    Returns boolean

  • isSimulatingMouseWithTouch(): boolean
  • Returns boolean

    true if the touch events are used to simulate mouse events.

  • onFrameEnded(): void
  • 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.

    Returns void

  • onKeyPressed(keyCode: number, location?: number): void
  • 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

    • keyCode: number

      The raw key code associated to the key press.

    • Optional location: number

      The location of the event.

    Returns void

  • onKeyReleased(keyCode: number, location?: number): void
  • 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

    • keyCode: number

      The raw key code associated to the key release.

    • Optional location: number

      The location of the event.

    Returns void

  • onMouseButtonPressed(buttonCode: number): void
  • Should be called whenever a mouse button is pressed.

    Parameters

    • buttonCode: number

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

    Returns void

  • onMouseButtonReleased(buttonCode: number): void
  • Should be called whenever a mouse button is released.

    Parameters

    • buttonCode: number

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

    Returns void

  • onMouseEnter(): void
  • Should be called when the mouse enter the canvas.

    Returns void

  • onMouseLeave(): void
  • Should be called when the mouse leave the canvas.

    Returns void

  • onMouseMove(x: number, y: number): void
  • Should be called when the mouse is moved.

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

    Parameters

    • x: number

      The mouse new X position

    • y: number

      The mouse new Y position

    Returns void

  • onMouseWheel(wheelDelta: number): void
  • Should be called whenever the mouse wheel is used

    Parameters

    • wheelDelta: number

      The mouse wheel delta

    Returns void

  • onTouchCancel(rawIdentifier: number): void
  • Parameters

    • rawIdentifier: number

    Returns void

  • onTouchEnd(rawIdentifier: number): void
  • Parameters

    • rawIdentifier: number

    Returns void

  • onTouchMove(rawIdentifier: number, x: number, y: number): void
  • Parameters

    • rawIdentifier: number
    • x: number
    • y: number

    Returns void

  • onTouchStart(rawIdentifier: number, x: number, y: number): void
  • Parameters

    • rawIdentifier: number
    • x: number
    • y: number

    Returns void

  • popEndedTouch(): undefined | number
  • deprecated

    Returns undefined | number

  • popStartedTouch(): undefined | number
  • deprecated

    Returns undefined | number

  • touchSimulateMouse(enable: boolean): void
  • 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

    • enable: boolean

      true to simulate mouse events, false to disable it.

    Returns void

  • wasKeyReleased(locationAwareKeyCode: number): boolean
  • Return true if the key corresponding to the location-aware keyCode was released during the last frame.

    Parameters

    • locationAwareKeyCode: number

      The location-aware key code to be tested.

    Returns boolean

  • getPublicTouchIdentifier(rawIdentifier: number): number
  • Add 2 to the identifier to avoid identifiers taking the GDevelop default variable value which is 0 and reserve 1 for the mouse.

    Parameters

    • rawIdentifier: number

      The identifier given by the browser.

    Returns number

    The identifier used in events.

Constructors

Generated using TypeDoc