Class KeyboardInfo

java.lang.Object
ActiverseEngine.KeyboardInfo
All Implemented Interfaces:
KeyListener, EventListener

public class KeyboardInfo extends Object implements KeyListener
Provides utility methods to retrieve information about keyboard input. This class implements the KeyListener interface to handle keyboard events. Supports special keyword "shift" for any shift key.
Version:
1.4.2
Author:
Knivier
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    appendAlphaNumeric(String current, boolean[] keyWasDown, boolean allowSpace)
    Appends debounced A-Z, 0-9 and optional space text input based on current key states.
    static boolean
    isAnyKeyDown(char... keyChars)
    Returns true when any character key in the set is currently down.
    static boolean
    isAnyKeyDown(int... keyCodes)
    Returns true when any key code in the set is currently down.
    static boolean
    isKeyDown(char keyChar)
    Checks if a specific key character is currently pressed.
    static boolean
    isKeyDown(int keyCode)
    Checks if a specific key is currently pressed.
    static boolean
    isKeyDown(String keyName)
    Checks if a specific key is pressed by name (supports special keywords) Special keywords: "shift" for any shift key
    static boolean
    isLetterDown(char letter)
    Checks a letter key ignoring case.
    static boolean
    justPressed(boolean keyDown, boolean wasDown)
    Returns true on the rising edge (up -> down) for a sampled key state.
    static boolean
    justReleased(boolean keyDown, boolean wasDown)
    Returns true on the falling edge (down -> up) for a sampled key state.
    void
    Called when a key is pressed.
    void
    Called when a key is released.
    void
    Called when a key is typed.
    static void
    syncAlphaNumericState(boolean[] keyWasDown, boolean includeSpace)
    Synchronizes debounced key states for A-Z, 0-9 and optional space.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • KeyboardInfo

      public KeyboardInfo()
  • Method Details

    • isKeyDown

      public static boolean isKeyDown(int keyCode)
      Checks if a specific key is currently pressed.
      Parameters:
      keyCode - The integer code of the key to check.
      Returns:
      true if the key is currently pressed, false otherwise.
    • isKeyDown

      public static boolean isKeyDown(char keyChar)
      Checks if a specific key character is currently pressed.
      Parameters:
      keyChar - Character to check (e.g. 'w', '/')
      Returns:
      true if the key is currently pressed
    • isLetterDown

      public static boolean isLetterDown(char letter)
      Checks a letter key ignoring case.
      Parameters:
      letter - Alphabetic character
      Returns:
      true if either lowercase or uppercase variant is pressed
    • isAnyKeyDown

      public static boolean isAnyKeyDown(char... keyChars)
      Returns true when any character key in the set is currently down.
      Parameters:
      keyChars - Character keys to test
    • isAnyKeyDown

      public static boolean isAnyKeyDown(int... keyCodes)
      Returns true when any key code in the set is currently down.
      Parameters:
      keyCodes - Virtual key codes to test
    • justPressed

      public static boolean justPressed(boolean keyDown, boolean wasDown)
      Returns true on the rising edge (up -> down) for a sampled key state.
      Parameters:
      keyDown - Current sampled key state
      wasDown - Previous sampled key state
    • justReleased

      public static boolean justReleased(boolean keyDown, boolean wasDown)
      Returns true on the falling edge (down -> up) for a sampled key state.
      Parameters:
      keyDown - Current sampled key state
      wasDown - Previous sampled key state
    • isKeyDown

      public static boolean isKeyDown(String keyName)
      Checks if a specific key is pressed by name (supports special keywords) Special keywords: "shift" for any shift key
      Parameters:
      keyName - The name of the key (e.g., "shift")
      Returns:
      true if the key is currently pressed
    • appendAlphaNumeric

      public static String appendAlphaNumeric(String current, boolean[] keyWasDown, boolean allowSpace)
      Appends debounced A-Z, 0-9 and optional space text input based on current key states.

      The keyWasDown array must be indexed by KeyEvent key codes.

      Parameters:
      current - Existing text value (null-safe)
      keyWasDown - Per-key previous-state array
      allowSpace - Whether space should be accepted
      Returns:
      Updated text value
    • syncAlphaNumericState

      public static void syncAlphaNumericState(boolean[] keyWasDown, boolean includeSpace)
      Synchronizes debounced key states for A-Z, 0-9 and optional space. Use this when entering a menu state to avoid immediate held-key injection.
      Parameters:
      keyWasDown - Per-key previous-state array
      includeSpace - Whether to synchronize space as well
    • keyPressed

      public void keyPressed(KeyEvent e)
      Called when a key is pressed. Updates the state of the corresponding key in the keys array.
      Specified by:
      keyPressed in interface KeyListener
      Parameters:
      e - The KeyEvent object representing the key press event.
    • keyReleased

      public void keyReleased(KeyEvent e)
      Called when a key is released. Updates the state of the corresponding key in the keys array.
      Specified by:
      keyReleased in interface KeyListener
      Parameters:
      e - The KeyEvent object representing the key release event.
    • keyTyped

      public void keyTyped(KeyEvent e)
      Called when a key is typed. This method is not used in this class implementation.
      Specified by:
      keyTyped in interface KeyListener
      Parameters:
      e - The KeyEvent object representing the key typed event.