Skip to main content

FlixelKeyInputManager

View source

class

org.flixelgdx.input.keyboard.FlixelKeyInputManager

public class FlixelKeyInputManager implements FlixelInputProcessorManager

Keyboard input manager backed by Gdx.input.

Access via Flixel.keys after the framework is initialized.

Tracks pressed keys via an internal libGDX InputProcessor. The processor is the authoritative source of "is key X currently pressed", which keeps state correct across every libGDX backend (LWJGL3, Android, iOS, TeaVM). The TeaVM/web backend in particular does not always update Gdx.input.isKeyPressed for every keycode, so the framework cannot rebuild its set from polling each frame; doing so would erase any state the InputProcessor just wrote and break FlixelKeyInputManager.justPressed(int) / FlixelKeyInputManager.justReleased(int) on web. Instead, FlixelKeyInputManager.update() simply records this frame's snapshot for "just" detection without ever touching FlixelKeyInputManager.currentPressedKeys.

Make sure that the processor returned by FlixelKeyInputManager.getInputProcessor() is added to the libGDX input chain (this is wired automatically in FlixelGame.create() via an InputMultiplexer). If you replace the input processor with your own, add this one first so key state still updates.

Constructors

FlixelKeyInputManager()

public FlixelKeyInputManager()

Fields

enabled

public boolean enabled

Whether keyboard input is currently enabled. When false, all key checks return false.


Methods

getInputProcessor()

public InputProcessor getInputProcessor()

Returns the input processor that tracks key state. Add this first to an InputMultiplexer (before other processors) so key state is correct.


update()

public void update()

Called once per frame from the game loop. Reserved for future polling-based fallbacks; today the InputProcessor keeps FlixelKeyInputManager.currentPressedKeys up to date in real time, so this method intentionally does nothing.

Earlier versions rebuilt FlixelKeyInputManager.currentPressedKeys from Gdx.input.isKeyPressed every frame, which clobbered any state the InputProcessor had just written and silently broke FlixelKeyInputManager.justPressed(int), FlixelKeyInputManager.justReleased(int), and the "first" helpers on the TeaVM/web backend (where libGDX does not expose every key through isKeyPressed). The processor is now the only writer.

Call FlixelKeyInputManager.endFrame() at the end of the frame so "just pressed/released" detection works next frame.


endFrame()

public void endFrame()

Captures current key state as "previous" for the next frame. Must be called once per frame at the end of the update cycle (after all state updates) so that FlixelKeyInputManager.firstJustPressed() and FlixelKeyInputManager.firstJustReleased() work correctly next frame.


pressed(int)

public boolean pressed(int key)

Returns whether the given key is currently held down. Returns false when the active debug overlay reports that another UI layer (typically the imgui debugger console) is capturing keyboard input, so typing in a debug text field cannot leak into game-side input (e.g. an ui_accept action bound to ENTER).

Use FlixelKeyInputManager.rawPressed(int) when you specifically need the raw, unsuppressed state (the debug overlay itself uses this for its toggle keys so they keep working even when a text field is focused).

Parameters:

NameDescription
keyThe key to check if it is pressed. (e.g. FlixelKey.A, Keys)

Returns: true if the key is pressed and input is enabled and not suppressed by UI.


rawPressed(int)

public boolean rawPressed(int key)

Same as FlixelKeyInputManager.pressed(int) but bypasses the "captured by debug UI" check. Intended for the debug overlay's own toggle keys and tools, which must keep responding even while a Dear ImGui text input has focus.

Parameters:

NameDescription
keyThe key to check if it is pressed.

Returns: true if the key is pressed and input is enabled, regardless of UI capture.


justPressed(int)

public boolean justPressed(int key)

Returns whether the given key was just pressed this frame. Returns false while the active debug overlay reports that another UI layer is capturing keyboard input. Uses the same current vs previous key sets as FlixelKeyInputManager.justReleased(int) and FlixelKeyInputManager.firstJustPressed() so "just" transitions stay reliable on all backends (for example, WebGL where Gdx.input.isKeyJustPressed is not dependable).

Parameters:

NameDescription
keykey code

Returns: true if the key was just pressed and input is enabled and not suppressed by UI.


rawJustPressed(int)

public boolean rawJustPressed(int key)

Same as FlixelKeyInputManager.justPressed(int) but bypasses the "captured by debug UI" check. Use this for input that must keep working regardless of UI capture.

Parameters:

NameDescription
keykey code

Returns: true if the key was just pressed and input is enabled, regardless of UI capture.


justReleased(int)

public boolean justReleased(int key)

Returns whether the given key was just released this frame. Returns false while the active debug overlay reports that another UI layer is capturing keyboard input.

Parameters:

NameDescription
keykey code

Returns: true if the key was pressed last frame and is not pressed now, and input is enabled and not suppressed by UI.


rawJustReleased(int)

public boolean rawJustReleased(int key)

Same as FlixelKeyInputManager.justReleased(int) but bypasses the "captured by debug UI" check.

Parameters:

NameDescription
keyThe key code to check if it was just released.

Returns: true if the key was just released and input is enabled, regardless of UI capture.


anyPressed(int)

public boolean anyPressed(int k1)

Returns whether at least one of the given keys is currently pressed.

Parameters:

NameDescription
k1The first key code to check.

Returns: true if any key in the given list is pressed and input is enabled.


anyPressed(int, int)

public boolean anyPressed(int k1, int k2)

Returns whether at least one of the given keys is currently pressed.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.

Returns: true if any key in the given list is pressed and input is enabled.


anyPressed(int, int, int)

public boolean anyPressed(int k1, int k2, int k3)

Returns whether at least one of the given keys is currently pressed.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.
k3The third key code to check.

Returns: true if any key in the given list is pressed and input is enabled.


anyPressed(int, int, int, int)

public boolean anyPressed(int k1, int k2, int k3, int k4)

Returns whether at least one of the given keys is currently pressed.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.
k3The third key code to check.
k4The fourth key code to check.

Returns: true if any key in the given list is pressed and input is enabled.


anyPressed(int, int, int, int, int)

public boolean anyPressed(int k1, int k2, int k3, int k4, int k5)

Returns whether at least one of the given keys is currently pressed.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.
k3The third key code to check.
k4The fourth key code to check.
k5The fifth key code to check.

Returns: true if any key in the given list is pressed and input is enabled.


anyPressed(int, int, int, int, int, int)

public boolean anyPressed(int k1, int k2, int k3, int k4, int k5, int k6)

Returns whether at least one of the given keys is currently pressed.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.
k3The third key code to check.
k4The fourth key code to check.
k5The fifth key code to check.
k6The sixth key code to check.

Returns: true if any key in the given list is pressed and input is enabled.


anyPressed(int...)

public boolean anyPressed(int... keys)

Returns whether at least one of the given keys is currently pressed.

Parameters:

NameDescription
keysThe keys to check.

Returns: true if any key in the given list is pressed and input is enabled.


anyJustPressed(int)

public boolean anyJustPressed(int k1)

Returns whether at least one of the given keys was just pressed this frame.

Parameters:

NameDescription
k1The first key code to check.

Returns: true if any key in the array was just pressed and input is enabled


anyJustPressed(int, int)

public boolean anyJustPressed(int k1, int k2)

Returns whether at least one of the given keys was just pressed this frame.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.

Returns: true if any key in the given list was just pressed and input is enabled.


anyJustPressed(int, int, int)

public boolean anyJustPressed(int k1, int k2, int k3)

Returns whether at least one of the given keys was just pressed this frame.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.
k3The third key code to check.

Returns: true if any key in the given list was just pressed and input is enabled.


anyJustPressed(int, int, int, int)

public boolean anyJustPressed(int k1, int k2, int k3, int k4)

Returns whether at least one of the given keys was just pressed this frame.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.
k3The third key code to check.
k4The fourth key code to check.

Returns: true if any key in the given list was just pressed and input is enabled.


anyJustPressed(int, int, int, int, int)

public boolean anyJustPressed(int k1, int k2, int k3, int k4, int k5)

Returns whether at least one of the given keys was just pressed this frame.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.
k3The third key code to check.
k4The fourth key code to check.
k5The fifth key code to check.

Returns: true if any key in the given list was just pressed and input is enabled.


anyJustPressed(int, int, int, int, int, int)

public boolean anyJustPressed(int k1, int k2, int k3, int k4, int k5, int k6)

Returns whether at least one of the given keys was just pressed this frame.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.
k3The third key code to check.
k4The fourth key code to check.
k5The fifth key code to check.
k6The sixth key code to check.

Returns: true if any key in the given list was just pressed and input is enabled.


anyJustPressed(int...)

public boolean anyJustPressed(int... keys)

Returns whether at least one of the given keys was just pressed this frame.

Parameters:

NameDescription
keysThe keys to check.

Returns: true if any key in the given list was just pressed and input is enabled.


anyJustReleased(int)

public boolean anyJustReleased(int k1)

Returns whether at least one of the given keys was just released this frame.

Parameters:

NameDescription
k1The first key code to check.

Returns: true if any key in the given list was just released and input is enabled.


anyJustReleased(int, int)

public boolean anyJustReleased(int k1, int k2)

Returns whether at least one of the given keys was just released this frame.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.

Returns: true if any key in the given list was just released and input is enabled.


anyJustReleased(int, int, int)

public boolean anyJustReleased(int k1, int k2, int k3)

Returns whether at least one of the given keys was just released this frame.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.
k3The third key code to check.

Returns: true if any key in the given list was just released and input is enabled.


anyJustReleased(int, int, int, int)

public boolean anyJustReleased(int k1, int k2, int k3, int k4)

Returns whether at least one of the given keys was just released this frame.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.
k3The third key code to check.
k4The fourth key code to check.

Returns: true if any key in the given list was just released and input is enabled.


anyJustReleased(int, int, int, int, int)

public boolean anyJustReleased(int k1, int k2, int k3, int k4, int k5)

Returns whether at least one of the given keys was just released this frame.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.
k3The third key code to check.
k4The fourth key code to check.
k5The fifth key code to check.

Returns: true if any key in the given list was just released and input is enabled.


anyJustReleased(int, int, int, int, int, int)

public boolean anyJustReleased(int k1, int k2, int k3, int k4, int k5, int k6)

Returns whether at least one of the given keys was just released this frame.

Parameters:

NameDescription
k1The first key code to check.
k2The second key code to check.
k3The third key code to check.
k4The fourth key code to check.
k5The fifth key code to check.
k6The sixth key code to check.

Returns: true if any key in the given list was just released and input is enabled.


anyJustReleased(int...)

public boolean anyJustReleased(int... keys)

Returns whether at least one of the given keys was just released this frame.

Parameters:

NameDescription
keysThe keys to check.

Returns: true if any key in the given list was just released and input is enabled.


firstPressed()

public int firstPressed()

Returns the key code that was pressed first (chronologically) among those currently held, or FlixelKey.NONE if none. Returns FlixelKey.NONE while the active debug overlay reports that another UI layer is capturing keyboard input.

Returns: First pressed key code, or FlixelKey.NONE if none.


firstJustPressed()

public int firstJustPressed()

Returns the first key code that was just pressed this frame, or FlixelKey.NONE if none. Returns FlixelKey.NONE while the debug UI is capturing keyboard input.

Returns: First just-pressed key code, or FlixelKey.NONE if none.


firstJustReleased()

public int firstJustReleased()

Returns the first key code that was just released this frame, or FlixelKey.NONE if none. Returns FlixelKey.NONE while the debug UI is capturing keyboard input.

Returns: First just-released key code, or FlixelKey.NONE if none.


reset()

public void reset()

Resets internal state (e.g. clears pressed key tracking). Does not change FlixelKeyInputManager.enabled.


isValidKeycode(int)

public boolean isValidKeycode(int key)

Verifies if the provided FlixelKey code is valid.

Parameters:

NameDescription
keyFlixelKey to check.

Returns: If the keycode is valid.