Class KeyHandler

java.lang.Object
io.github.espressoengine.input.KeyHandler

public class KeyHandler extends Object
Class to handle input from keyboards.
Version:
$Id: $Id
Author:
pastthepixels
  • Field Details

    • dbg

      public boolean dbg
    • pressedKeys

      protected ArrayList<Integer> pressedKeys
  • Constructor Details

    • KeyHandler

      public KeyHandler(Window window)

      Constructor for KeyHandler.

      Parameters:
      window - a Window object
  • Method Details

    • getPressedKeys

      public ArrayList<Integer> getPressedKeys()
      Gets a list of all keys currently being pressed down.
      Returns:
      a ArrayList object
    • isKeyPressed

      public boolean isKeyPressed(int keyCode)

      Returns true if a keycode is in the list of pressed keys.

      Parameters:
      keyCode - a int
      Returns:
      a boolean
    • getAxis

      public double getAxis(int negativeKeyCode, int positiveKeyCode)

      Similar to Godot's getAxis. Returns -1 if the key under negativeKeyCode is pressed, 1 if the key under positiveKeyCode is pressed, and 0 if none or both of them are pressed.

      Parameters:
      negativeKeyCode - a int
      positiveKeyCode - a int
      Returns:
      a double
    • onKeyPressed

      public void onKeyPressed(KeyEvent e)
      Is called whenever a key is pressed, and is designed to be overridden on class instances as an event.
      Parameters:
      e - a KeyEvent object
    • onKeyReleased

      public void onKeyReleased(KeyEvent e)
      Is called whenever a key is released, and is designed to be overridden on class instances as an event.
      Parameters:
      e - a KeyEvent object