Class GUIKeyStroke

java.lang.Object
com.blackrook.gui.input.GUIKeyStroke
All Implemented Interfaces:
GUIInputConstants, GUIKeyTables

public class GUIKeyStroke extends Object implements GUIKeyTables
A keystroke defined by this GUI for listening for broadcast events. The key masks are defined by the MASK_* constants in this class.
Author:
Matthew Tropiano
  • Field Details

  • Constructor Details

    • GUIKeyStroke

      protected GUIKeyStroke(int inputType, int keyMask, int keyPress, boolean flag)
      Creates a keystroke.
      Parameters:
      inputType - the input type.
      keyMask - the key mask.
      keyPress - the key press.
      flag - the modifier flag.
  • Method Details

    • create

      public static GUIKeyStroke create(String keystroke)
      Creates a keystroke by parsing a string that represents the keystroke.

      The key is defined by how a keystroke is defined in menus: modifiers plus the key. Gamepad taps are "PAD" plus an axis plus "+" or "-" to signify the axis direction. If no direction, assumes button. The keys and axes are not case-sensitive.

      For example:

      • "X" -> GUIKeyStroke.create(INPUT_KEY, 0, OGLInputConstants.KEY_X, false)
      • "CTRL+X" -> GUIKeyStroke.create(INPUT_KEY, MASK_CTRL, OGLInputConstants.KEY_X, false)
      • "CTRL+ALT+X" -> GUIKeyStroke.create(INPUT_KEY, MASK_CTRL | MASK_ALT, OGLInputConstants.KEY_X, false)
      • "X release" -> GUIKeyStroke.create(INPUT_KEY, 0, OGLInputConstants.KEY_X, true)
      • "PAD 2" -> GUIKeyStroke.create(INPUT_GAMEPAD, 0, OGLInputConstants.GAMEPAD_2)
      • "PAD X+" -> GUIKeyStroke.create(INPUT_GAMEPAD_AXIS, 0, OGLInputConstants.AXIS_X, true)
      • "PAD Y-" -> GUIKeyStroke.create(INPUT_GAMEPAD_AXIS, 0, OGLInputConstants.AXIS_Y, false)
      • "generic 2" -> GUIKeyStroke.create(INPUT_GENERIC, 0, 2, false)
      Parameters:
      keystroke - the keystroke name.
      Returns:
      the corresponding key stroke.
      Throws:
      IllegalArgumentException - if the keystroke can't be parsed.
    • createGeneric

      public static GUIKeyStroke createGeneric(int code)
      Creates a new generic input keystroke.
      Parameters:
      code - the input code.
      Returns:
      the corresponding key stroke.
    • createGamepad

      public static GUIKeyStroke createGamepad(int button)
      Creates a new gamepad button press keystroke with no mask.
      Parameters:
      button - the button press (OGLInputContants.*).
      Returns:
      the corresponding key stroke.
    • createGamepad

      public static GUIKeyStroke createGamepad(int button, boolean flag)
      Creates a new gamepad button keystroke with no mask.
      Parameters:
      button - the button press (OGLInputContants.*).
      flag - if true, this is a release.
      Returns:
      the corresponding key stroke.
    • createGamepad

      public static GUIKeyStroke createGamepad(int keyMask, int button, boolean flag)
      Creates a new gamepad button keystroke.
      Parameters:
      keyMask - the key mask (GUIKeyStroke.MASK_*).
      button - the button press (OGLInputContants.*).
      flag - if true, this is a release.
      Returns:
      the corresponding key stroke.
    • createGamepadTap

      public static GUIKeyStroke createGamepadTap(int axis, boolean positive)
      Creates a new gamepad axis tap with no mask.
      Parameters:
      axis - the axis (OGLInputContants.*).
      positive - if true, positive axis, if false, negative.
      Returns:
      the corresponding key stroke.
    • createKey

      public static GUIKeyStroke createKey(int keyPress)
      Creates a new keyboard press keystroke with no mask.
      Parameters:
      keyPress - the key press (OGLInputContants.*).
      Returns:
      the corresponding key stroke.
    • createKey

      public static GUIKeyStroke createKey(int keyPress, boolean flag)
      Creates a new keyboard keystroke with no mask.
      Parameters:
      keyPress - the key press (OGLInputContants.*).
      flag - if keyboard key, this is a release. If a gamepad axis tap: if true, positive axis, if false, negative.
      Returns:
      the corresponding key stroke.
    • createKey

      public static GUIKeyStroke createKey(int keyMask, int keyPress, boolean flag)
      Creates a new keyboard keystroke.
      Parameters:
      keyMask - the key mask (GUIKeyStroke.MASK_*).
      keyPress - the key press (OGLInputContants.*).
      flag - if keyboard key, this is a release. If a gamepad axis tap: if true, positive axis, if false, negative.
      Returns:
      the corresponding key stroke.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(GUIKeyStroke ks)
      Tests if this keystroke equals another.
      Parameters:
      ks - the key stroke.
      Returns:
      true if so, false if not.