Class KeyboardHandler

java.lang.Object
io.github.ocelot.window.input.KeyboardHandler
All Implemented Interfaces:
WindowEventListener

public class KeyboardHandler extends Object implements WindowEventListener
Tracks pressed keys using keycode and scancode.
  • Constructor Details

    • KeyboardHandler

      public KeyboardHandler()
  • Method Details

    • keyPressed

      public void keyPressed(Window window, int key, int scanCode, KeyMods mods)
      Description copied from interface: WindowEventListener
      Called when a key on the keyboard is pressed.
      Specified by:
      keyPressed in interface WindowEventListener
      Parameters:
      window - The window that fired the event
      key - The universal key code
      scanCode - The machine-specific scan code
      mods - The keyboard modifier flags set when the key was pressed
    • keyReleased

      public void keyReleased(Window window, int key, int scanCode, KeyMods mods)
      Description copied from interface: WindowEventListener
      Called when a key on the keyboard is released.
      Specified by:
      keyReleased in interface WindowEventListener
      Parameters:
      window - The window that fired the event
      key - The universal key code
      scanCode - The machine-specific scan code
      mods - The keyboard modifier flags set when the key was released
    • isKeyPressed

      public boolean isKeyPressed(int keyCode, int scanCode)
      Checks to see if the specified key or scan code is pressed.
      Parameters:
      keyCode - The id of the key or GLFW.GLFW_KEY_UNKNOWN to defer to the scan code
      scanCode - The device-specific scan code
      Returns:
      Whether that key is pressed
    • isKeyPressed

      public boolean isKeyPressed(int keyCode)
      Checks to see if the specified key is pressed. isKeyPressed(int, int) should be used if scanCode is available to support device-specific keys.
      Parameters:
      keyCode - The id of the key
      Returns:
      Whether that key is pressed