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 ClassesModifier and TypeInterfaceDescriptionstatic enumNon-character keys supported by the input API.static enumMouse buttons supported by the input API. -
Method Summary
Modifier and TypeMethodDescriptionbooleankeyDown(char key) Tests whether a character key is held, ignoring letter case.booleanTests whether a special key is held.booleankeyJustPressed(char key) Tests whether a character key was pressed during this frame, ignoring letter case.booleankeyJustPressed(Input.Key key) Tests whether a special key was pressed during this frame.booleankeyJustReleased(char key) Tests whether a character key was released during this frame, ignoring letter case.booleankeyJustReleased(Input.Key key) Tests whether a special key was released during this frame.default booleanTests whether the left mouse button is held.booleanmouseDown(Input.MouseButton button) Tests whether a mouse button is held.default booleanTests whether the left mouse button is dragging.booleanmouseDragged(Input.MouseButton button) Tests whether a mouse-drag event occurred during this frame while the specified button was held.default intmouseDX()Returns horizontal mouse movement since the previous frame.default intmouseDY()Returns vertical mouse movement since the previous frame.default booleanTests whether the left mouse button was just pressed.booleanmouseJustPressed(Input.MouseButton button) Tests whether a mouse button was pressed during this frame.default booleanTests whether the left mouse button was just released.booleanmouseJustReleased(Input.MouseButton button) Tests whether a mouse button was released during this frame.default Vec2Returns the mouse position in viewport coordinates.intReturns scroll-wheel movement accumulated during this frame.intmouseX()Returns the current mouse x-coordinate.intmouseY()Returns the current mouse y-coordinate.intpmouseX()Returns the previous frame's mouse x-coordinate.intpmouseY()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
Tests whether a mouse button is held.- Parameters:
button- button to test- Returns:
- whether the button is held
-
mouseJustPressed
Tests whether a mouse button was pressed during this frame.- Parameters:
button- button to test- Returns:
- whether the button was just pressed
-
mouseJustReleased
Tests whether a mouse button was released during this frame.- Parameters:
button- button to test- Returns:
- whether the button was just released
-
mouseDragged
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
Tests whether a special key is held.- Parameters:
key- special key to test- Returns:
- whether the key is held
-
keyJustPressed
Tests whether a special key was pressed during this frame.- Parameters:
key- special key to test- Returns:
- whether the key was just pressed
-
keyJustReleased
Tests whether a special key was released during this frame.- Parameters:
key- special key to test- Returns:
- whether the key was just released
-
mousePosition
Returns the mouse position in viewport coordinates.- Returns:
- current mouse position
-