FlixelKeyInputManager
View sourceclass
org.flixelgdx.input.keyboard.FlixelKeyInputManager
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()
Fields
enabled
Whether keyboard input is currently enabled. When false, all key checks return false.
Methods
getInputProcessor()
Returns the input processor that tracks key state. Add this first to an InputMultiplexer (before other processors) so key state is correct.
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()
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)
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:
| Name | Description |
|---|---|
key | The 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)
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:
| Name | Description |
|---|---|
key | The key to check if it is pressed. |
Returns: true if the key is pressed and input is enabled, regardless of UI capture.
justPressed(int)
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:
| Name | Description |
|---|---|
key | key code |
Returns: true if the key was just pressed and input is enabled and not suppressed by UI.
rawJustPressed(int)
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:
| Name | Description |
|---|---|
key | key code |
Returns: true if the key was just pressed and input is enabled, regardless of UI capture.
justReleased(int)
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:
| Name | Description |
|---|---|
key | key 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)
Same as FlixelKeyInputManager.justReleased(int) but bypasses the "captured by debug UI" check.
Parameters:
| Name | Description |
|---|---|
key | The 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)
Returns whether at least one of the given keys is currently pressed.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
Returns: true if any key in the given list is pressed and input is enabled.
anyPressed(int, int)
Returns whether at least one of the given keys is currently pressed.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
Returns: true if any key in the given list is pressed and input is enabled.
anyPressed(int, int, int)
Returns whether at least one of the given keys is currently pressed.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
k3 | The 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)
Returns whether at least one of the given keys is currently pressed.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
k3 | The third key code to check. |
k4 | The 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)
Returns whether at least one of the given keys is currently pressed.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
k3 | The third key code to check. |
k4 | The fourth key code to check. |
k5 | The 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)
Returns whether at least one of the given keys is currently pressed.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
k3 | The third key code to check. |
k4 | The fourth key code to check. |
k5 | The fifth key code to check. |
k6 | The sixth key code to check. |
Returns: true if any key in the given list is pressed and input is enabled.
anyPressed(int...)
Returns whether at least one of the given keys is currently pressed.
Parameters:
| Name | Description |
|---|---|
keys | The keys to check. |
Returns: true if any key in the given list is pressed and input is enabled.
anyJustPressed(int)
Returns whether at least one of the given keys was just pressed this frame.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
Returns: true if any key in the array was just pressed and input is enabled
anyJustPressed(int, int)
Returns whether at least one of the given keys was just pressed this frame.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The 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)
Returns whether at least one of the given keys was just pressed this frame.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
k3 | The 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)
Returns whether at least one of the given keys was just pressed this frame.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
k3 | The third key code to check. |
k4 | The 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)
Returns whether at least one of the given keys was just pressed this frame.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
k3 | The third key code to check. |
k4 | The fourth key code to check. |
k5 | The 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)
Returns whether at least one of the given keys was just pressed this frame.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
k3 | The third key code to check. |
k4 | The fourth key code to check. |
k5 | The fifth key code to check. |
k6 | The sixth key code to check. |
Returns: true if any key in the given list was just pressed and input is enabled.
anyJustPressed(int...)
Returns whether at least one of the given keys was just pressed this frame.
Parameters:
| Name | Description |
|---|---|
keys | The keys to check. |
Returns: true if any key in the given list was just pressed and input is enabled.
anyJustReleased(int)
Returns whether at least one of the given keys was just released this frame.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
Returns: true if any key in the given list was just released and input is enabled.
anyJustReleased(int, int)
Returns whether at least one of the given keys was just released this frame.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The 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)
Returns whether at least one of the given keys was just released this frame.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
k3 | The 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)
Returns whether at least one of the given keys was just released this frame.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
k3 | The third key code to check. |
k4 | The 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)
Returns whether at least one of the given keys was just released this frame.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
k3 | The third key code to check. |
k4 | The fourth key code to check. |
k5 | The 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)
Returns whether at least one of the given keys was just released this frame.
Parameters:
| Name | Description |
|---|---|
k1 | The first key code to check. |
k2 | The second key code to check. |
k3 | The third key code to check. |
k4 | The fourth key code to check. |
k5 | The fifth key code to check. |
k6 | The sixth key code to check. |
Returns: true if any key in the given list was just released and input is enabled.
anyJustReleased(int...)
Returns whether at least one of the given keys was just released this frame.
Parameters:
| Name | Description |
|---|---|
keys | The keys to check. |
Returns: true if any key in the given list was just released and input is enabled.
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()
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()
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()
Resets internal state (e.g. clears pressed key tracking). Does not change FlixelKeyInputManager.enabled.
isValidKeycode(int)
Verifies if the provided FlixelKey code is valid.
Parameters:
| Name | Description |
|---|---|
key | FlixelKey to check. |
Returns: If the keycode is valid.