Interface Input


public interface Input
Read-only mouse and keyboard state for the current frame.

Down methods remain true while a key or button is held. JustPressed and JustReleased report the corresponding transition for one rendered frame. Use held state for continuous movement and a press transition for an action that should happen only once:


 if (in.keyDown('a')) x -= 200 * f.dt();  // move while held
 if (in.keyJustPressed(' ')) jump();      // jump once per press
 

Character-key queries are case-insensitive: keyDown('a') also recognizes A, including Shift+A. Non-character keys use the Input.Key overloads.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    Non-character keys supported by the input API.
    static enum 
    Mouse buttons supported by the input API.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    keyDown(char key)
    Tests whether a character key is held, ignoring letter case.
    boolean
    Tests whether a special key is held.
    boolean
    keyJustPressed(char key)
    Tests whether a character key was pressed during this frame, ignoring letter case.
    boolean
    Tests whether a special key was pressed during this frame.
    boolean
    keyJustReleased(char key)
    Tests whether a character key was released during this frame, ignoring letter case.
    boolean
    Tests whether a special key was released during this frame.
    default boolean
    Tests whether the left mouse button is held.
    boolean
    Tests whether a mouse button is held.
    default boolean
    Tests whether the left mouse button is dragging.
    boolean
    Tests whether a mouse-drag event occurred during this frame while the specified button was held.
    default int
    Returns horizontal mouse movement since the previous frame.
    default int
    Returns vertical mouse movement since the previous frame.
    default boolean
    Tests whether the left mouse button was just pressed.
    boolean
    Tests whether a mouse button was pressed during this frame.
    default boolean
    Tests whether the left mouse button was just released.
    boolean
    Tests whether a mouse button was released during this frame.
    default Vec2
    Returns the mouse position in viewport coordinates.
    int
    Returns scroll-wheel movement accumulated during this frame.
    int
    Returns the current mouse x-coordinate.
    int
    Returns the current mouse y-coordinate.
    int
    Returns the previous frame's mouse x-coordinate.
    int
    Returns the previous frame's mouse y-coordinate.
  • Method Details

    • mouseX

      int mouseX()
      Returns the current mouse x-coordinate.
      Returns:
      x-coordinate in viewport pixels
    • mouseY

      int mouseY()
      Returns the current mouse y-coordinate.
      Returns:
      y-coordinate in viewport pixels
    • pmouseX

      int pmouseX()
      Returns the previous frame's mouse x-coordinate.
      Returns:
      x-coordinate in viewport pixels
    • pmouseY

      int pmouseY()
      Returns the previous frame's mouse y-coordinate.
      Returns:
      y-coordinate in viewport pixels
    • mouseDX

      default int mouseDX()
      Returns horizontal mouse movement since the previous frame.
      Returns:
      change in x, in pixels
    • mouseDY

      default int mouseDY()
      Returns vertical mouse movement since the previous frame.
      Returns:
      change in y, in pixels
    • mouseDown

      boolean mouseDown(Input.MouseButton button)
      Tests whether a mouse button is held.
      Parameters:
      button - button to test
      Returns:
      whether the button is held
    • mouseJustPressed

      boolean mouseJustPressed(Input.MouseButton button)
      Tests whether a mouse button was pressed during this frame.
      Parameters:
      button - button to test
      Returns:
      whether the button was just pressed
    • mouseJustReleased

      boolean mouseJustReleased(Input.MouseButton button)
      Tests whether a mouse button was released during this frame.
      Parameters:
      button - button to test
      Returns:
      whether the button was just released
    • mouseDragged

      boolean mouseDragged(Input.MouseButton button)
      Tests whether a mouse-drag event occurred during this frame while the specified button was held. Just holding a button does not count as dragging (must also move).
      Parameters:
      button - button to test
      Returns:
      whether a drag was reported during this frame
    • mouseWheel

      int mouseWheel()
      Returns scroll-wheel movement accumulated during this frame. Positive values generally indicate scrolling down, negative values up; the direction can depend on system scroll settings. The value counts scroll steps, not pixels, and resets after each frame.
      Returns:
      signed scroll-step count, or zero if no scrolling occurred
    • mouseDown

      default boolean mouseDown()
      Tests whether the left mouse button is held.
      Returns:
      whether the left mouse button is held
    • mouseJustPressed

      default boolean mouseJustPressed()
      Tests whether the left mouse button was just pressed.
      Returns:
      whether the left mouse button was just pressed
    • mouseJustReleased

      default boolean mouseJustReleased()
      Tests whether the left mouse button was just released.
      Returns:
      whether the left mouse button was just released
    • mouseDragged

      default boolean mouseDragged()
      Tests whether the left mouse button is dragging.
      Returns:
      whether the left mouse button is dragging
    • keyDown

      boolean keyDown(char key)
      Tests whether a character key is held, ignoring letter case. For example, keyDown('a') also recognizes Shift+A.
      Parameters:
      key - character to test
      Returns:
      whether the key is held
    • keyJustPressed

      boolean keyJustPressed(char key)
      Tests whether a character key was pressed during this frame, ignoring letter case.
      Parameters:
      key - character to test
      Returns:
      whether the key was just pressed
    • keyJustReleased

      boolean keyJustReleased(char key)
      Tests whether a character key was released during this frame, ignoring letter case.
      Parameters:
      key - character to test
      Returns:
      whether the key was just released
    • keyDown

      boolean keyDown(Input.Key key)
      Tests whether a special key is held.
      Parameters:
      key - special key to test
      Returns:
      whether the key is held
    • keyJustPressed

      boolean keyJustPressed(Input.Key key)
      Tests whether a special key was pressed during this frame.
      Parameters:
      key - special key to test
      Returns:
      whether the key was just pressed
    • keyJustReleased

      boolean keyJustReleased(Input.Key key)
      Tests whether a special key was released during this frame.
      Parameters:
      key - special key to test
      Returns:
      whether the key was just released
    • mousePosition

      default Vec2 mousePosition()
      Returns the mouse position in viewport coordinates.
      Returns:
      current mouse position