Class SquidInput

java.lang.Object
com.badlogic.gdx.InputAdapter
com.github.yellowstonegames.press.SquidInput
All Implemented Interfaces:
com.badlogic.gdx.InputProcessor

public class SquidInput extends com.badlogic.gdx.InputAdapter
This input processing class can handle mouse and keyboard input, using a SquidMouse for Mouse input and a user implementation of SquidInput.KeyHandler (often a lambda) to react to keys represented as chars and the modifiers those keys were pressed with, any of alt, ctrl, and/or shift. Not all keys are representable by default in Unicode, so symbolic representations are stored in constants in this class, and are passed to SquidInput.KeyHandler.handle(char, boolean, boolean, boolean) as chars like DOWN_ARROW or its value, '\u2193'. Shift modifies the input as it would on a QWERTY keyboard, and the exact mapping is documented in fromCode(int, boolean) as well. This class handles mouse input immediately, but stores keypresses in a queue, storing all key events and allowing them to be processed one at a time using next() or all at once using drain(). To have an effect, it needs to be registered by calling Input.setInputProcessor(InputProcessor). Note that calling hasNext() does more than just check if there are events that can be processed; because hasNext() is expected to be called frequently, it is also the point where this class checks if a key is being held and so the next event should occur. Holding a key only causes the keyDown() method of InputListener to be called once, so this uses hasNext() to see if there should be a next event coming from a held key.
This also allows some key remapping, including remapping so a key pressed with modifiers like Ctrl and Shift could act like '?' (which could be used by expert players to avoid accidentally opening a help menu they don't need), and that would free up '?' for some other use that could also be remapped. The remap() methods do much of this, often with help from combineModifiers(char, boolean, boolean, boolean), while the unmap() methods allow removal of any no-longer-wanted remappings.
This does not perform any blocking functionality. To block game logic until an event has been received, check hasNext() in the game's render() method and effectively "block" by not running game logic if hasNext() returns false. You can process an event if hasNext() returns true by calling next(). Mouse inputs do not affect hasNext(), and next() will process only key pressed events. Also, see above about the extra behavior of hasNext regarding held keys.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    A single-method interface used to process "typed" characters, special characters produced by unusual keys, and modifiers that can affect them.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char
    Backspace key on most PC keyboards; Delete key on Mac keyboards.
    static final char
    Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 5.
    static final char
    Down arrow key.
    static final char
    Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 1.
    static final char
    Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 3.
    static final char
    End key (commonly used for moving a cursor to end of line).
    static final char
    Enter key, also called Return key.
    static final char
    Esc or Escape key
    static final char
    Function key F1
    static final char
    Function key F10
    static final char
    Function key F11
    static final char
    Function key F12
    static final char
    Function key F2
    static final char
    Function key F3
    static final char
    Function key F4
    static final char
    Function key F5
    static final char
    Function key F6
    static final char
    Function key F7
    static final char
    Function key F8
    static final char
    Function key F9
    static final char
    Delete key on most PC keyboards; no equivalent on some (all?) Mac keyboards.
    static final char
    Gamepad A button.
    static final char
    Gamepad B button.
    static final char
    Gamepad C button.
    static final char
    Gamepad L1 button.
    static final char
    Gamepad L2 button.
    static final char
    Gamepad Left Thumb button.
    static final char
    Gamepad R1 button.
    static final char
    Gamepad R2 button.
    static final char
    Gamepad Right Thumb button.
    static final char
    Gamepad Select button.
    static final char
    Gamepad Start button.
    static final char
    Gamepad X button.
    static final char
    Gamepad Y button.
    static final char
    Gamepad Z button.
    protected com.github.tommyettinger.ds.IntIntOrderedMap
     
    static final char
    Home key (commonly used for moving a cursor to start of line).
    protected boolean
     
    static final char
    Insert key.
     
    protected long
     
    static final char
    Left arrow key.
    final com.github.tommyettinger.ds.IntIntMap
     
    protected SquidMouse
     
    protected boolean
     
    static final char
    Page Down key.
    static final char
    Page Up key.
    protected final com.github.tommyettinger.ds.IntDeque
     
    protected long
     
    static final char
    Down arrow key.
    static final char
    Tab key.
    static final char
    Up arrow key.
    static final char
    Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 7.
    static final char
    Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 9.
    static final char
    Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 0.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new SquidInput that does not respond to keyboard or mouse input.
    Constructs a new SquidInput that does not respond to mouse input, but does take keyboard input and sends keyboard events through some processing before calling keyHandler.handle() on keypresses that can sensibly be processed.
    SquidInput(SquidInput.KeyHandler keyHandler, boolean ignoreInput)
    Constructs a new SquidInput that does not respond to mouse input, but does take keyboard input and sends keyboard events through some processing before calling keyHandler.handle() on keypresses that can sensibly be processed.
    Constructs a new SquidInput that responds to mouse and keyboard input when given a SquidMouse and a SquidInput.KeyHandler implementation.
    SquidInput(SquidInput.KeyHandler keyHandler, SquidMouse mouse, boolean ignoreInput)
    Constructs a new SquidInput that responds to mouse and keyboard input when given a SquidMouse and a SquidInput.KeyHandler implementation, and can be put in an initial state where it ignores input until told otherwise via setIgnoreInput(boolean).
    Constructs a new SquidInput that does not respond to keyboard input, but does take mouse input and passes mouse events along to the given SquidMouse.
  • Method Summary

    Modifier and Type
    Method
    Description
    Removes any remappings to key bindings that were in use in this SquidInput.
    static int
    combineModifiers(char key, boolean alt, boolean ctrl, boolean shift)
    Combines the key (as it would be given to SquidInput.KeyHandler.handle(char, boolean, boolean, boolean)) with the three booleans for the alt, ctrl, and shift modifier keys, returning an int that can be used with the internal queue of ints or the public mapping of received inputs to actual inputs the program can process.
    void
    Processes all events queued up, passing them through this object's key processing and then to keyHandler.
    void
    Empties the backing queue of data.
    char
    fromCode(int keycode, boolean shift)
    Maps keycodes to Unicode chars, sometimes depending on whether the Shift key is held.
    boolean
    Get the status for whether this should ignore input right now or not.
     
     
    long
    Gets the amount of milliseconds of holding a key this requires to count as a key repeat.
    boolean
    Returns true if at least one event is queued, but also will call keyDown(int) if a key is being held but there is a failure to process the repeated event.
    boolean
     
    boolean
    keyDown(int keycode)
     
    Reads in a String (almost certainly produced by keyMappingToString()) to set the current key remapping.
    Gets the current key remapping as a String, which can be saved in a file and read back with keyMappingFromString(String).
    boolean
    keyTyped(char character)
     
    boolean
    keyUp(int keycode)
     
    boolean
    mouseMoved(int screenX, int screenY)
     
    void
    Processes the first key event queued up, passing it to this object's InputProcessor.
    remap(char pressedChar, boolean pressedAlt, boolean pressedCtrl, boolean pressedShift, char targetChar, boolean targetAlt, boolean targetCtrl, boolean targetShift)
    Remaps a char that could be input and processed by SquidInput.KeyHandler.handle(char, boolean, boolean, boolean) (possibly with some pressed modifiers) to another char with possible modifiers.
    remap(int[] pairs)
    Remaps many keypress combinations, each of which is a char and several potential modifiers, to other keypress combinations.
    remap(int pressed, int target)
    Remaps a keypress combination, which is a char and several potential modifiers, to another keypress combination.
    boolean
    scrolled(float amountX, float amountY)
     
    void
    setIgnoreInput(boolean ignoreInput)
    Set the status for whether this should ignore input right now or not.
    void
     
    void
     
    void
    setRepeatGap(long time)
    Sets the amount of milliseconds of holding a key this requires to count as a key repeat.
    void
    setUsingNumpadDirections(boolean using)
     
    boolean
    touchDown(int screenX, int screenY, int pointer, int button)
     
    boolean
    touchDragged(int screenX, int screenY, int pointer)
     
    boolean
    touchUp(int screenX, int screenY, int pointer, int button)
     
    unmap(char pressedChar, boolean pressedAlt, boolean pressedCtrl, boolean pressedShift)
    Removes a keypress combination from the mapping by specifying the char and any modifiers that are part of the keypress combination.
    unmap(int pressed)
    Removes a keypress combination from the mapping by specifying the keypress combination as an int.

    Methods inherited from class com.badlogic.gdx.InputAdapter

    touchCancelled

    Methods inherited from class Object

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

    • keyAction

      protected SquidInput.KeyHandler keyAction
    • numpadDirections

      protected boolean numpadDirections
    • ignoreInput

      protected boolean ignoreInput
    • mouse

      protected SquidMouse mouse
    • queue

      protected final com.github.tommyettinger.ds.IntDeque queue
    • lastKeyTime

      protected long lastKeyTime
    • heldCodes

      protected com.github.tommyettinger.ds.IntIntOrderedMap heldCodes
    • repeatGapMillis

      protected long repeatGapMillis
    • mapping

      public final com.github.tommyettinger.ds.IntIntMap mapping
    • LEFT_ARROW

      public static final char LEFT_ARROW
      Left arrow key. If numpadDirections is enabled, this will also be sent by Numpad 4.
      See Also:
    • UP_ARROW

      public static final char UP_ARROW
      Up arrow key. If numpadDirections is enabled, this will also be sent by Numpad 8.
      See Also:
    • RIGHT_ARROW

      public static final char RIGHT_ARROW
      Down arrow key. If numpadDirections is enabled, this will also be sent by Numpad 6.
      See Also:
    • DOWN_ARROW

      public static final char DOWN_ARROW
      Down arrow key. If numpadDirections is enabled, this will also be sent by Numpad 2.
      See Also:
    • DOWN_LEFT_ARROW

      public static final char DOWN_LEFT_ARROW
      Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 1.
      See Also:
    • DOWN_RIGHT_ARROW

      public static final char DOWN_RIGHT_ARROW
      Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 3.
      See Also:
    • UP_RIGHT_ARROW

      public static final char UP_RIGHT_ARROW
      Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 9.
      See Also:
    • UP_LEFT_ARROW

      public static final char UP_LEFT_ARROW
      Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 7.
      See Also:
    • CENTER_ARROW

      public static final char CENTER_ARROW
      Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 5.
      See Also:
    • VERTICAL_ARROW

      public static final char VERTICAL_ARROW
      Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 0.
      Intended for games that might need up a jump or crouch button on the numpad that supplants movement.
      See Also:
    • ENTER

      public static final char ENTER
      Enter key, also called Return key. Used to start a new line of text or confirm entries in forms.
      See Also:
    • TAB

      public static final char TAB
      Tab key. Used for entering horizontal spacing, such as indentation, but also often to cycle between menu items.
      See Also:
    • BACKSPACE

      public static final char BACKSPACE
      Backspace key on most PC keyboards; Delete key on Mac keyboards. Used to delete the previous character.
      See Also:
    • FORWARD_DELETE

      public static final char FORWARD_DELETE
      Delete key on most PC keyboards; no equivalent on some (all?) Mac keyboards. Used to delete the next character.
      Not present on some laptop keyboards and some (all?) Mac keyboards.
      See Also:
    • INSERT

      public static final char INSERT
      Insert key. Not recommended for common use because it could affect other application behavior.
      Not present on some laptop keyboards.
      See Also:
    • PAGE_DOWN

      public static final char PAGE_DOWN
      Page Down key.
      Not present on some laptop keyboards.
      See Also:
    • PAGE_UP

      public static final char PAGE_UP
      Page Up key.
      Not present on some laptop keyboards.
      See Also:
    • HOME

      public static final char HOME
      Home key (commonly used for moving a cursor to start of line).
      Not present on some laptop keyboards.
      See Also:
    • END

      public static final char END
      End key (commonly used for moving a cursor to end of line).
      Not present on some laptop keyboards.
      See Also:
    • ESCAPE

      public static final char ESCAPE
      Esc or Escape key
      See Also:
    • F1

      public static final char F1
      Function key F1
      See Also:
    • F2

      public static final char F2
      Function key F2
      See Also:
    • F3

      public static final char F3
      Function key F3
      See Also:
    • F4

      public static final char F4
      Function key F4
      See Also:
    • F5

      public static final char F5
      Function key F5
      See Also:
    • F6

      public static final char F6
      Function key F6
      See Also:
    • F7

      public static final char F7
      Function key F7
      See Also:
    • F8

      public static final char F8
      Function key F8
      See Also:
    • F9

      public static final char F9
      Function key F9
      See Also:
    • F10

      public static final char F10
      Function key F10
      See Also:
    • F11

      public static final char F11
      Function key F11
      See Also:
    • F12

      public static final char F12
      Function key F12
      See Also:
    • GAMEPAD_A

      public static final char GAMEPAD_A
      Gamepad A button.
      See Also:
    • GAMEPAD_B

      public static final char GAMEPAD_B
      Gamepad B button.
      See Also:
    • GAMEPAD_C

      public static final char GAMEPAD_C
      Gamepad C button.
      See Also:
    • GAMEPAD_X

      public static final char GAMEPAD_X
      Gamepad X button.
      See Also:
    • GAMEPAD_Y

      public static final char GAMEPAD_Y
      Gamepad Y button.
      See Also:
    • GAMEPAD_Z

      public static final char GAMEPAD_Z
      Gamepad Z button.
      See Also:
    • GAMEPAD_L1

      public static final char GAMEPAD_L1
      Gamepad L1 button.
      See Also:
    • GAMEPAD_L2

      public static final char GAMEPAD_L2
      Gamepad L2 button.
      See Also:
    • GAMEPAD_R1

      public static final char GAMEPAD_R1
      Gamepad R1 button.
      See Also:
    • GAMEPAD_R2

      public static final char GAMEPAD_R2
      Gamepad R2 button.
      See Also:
    • GAMEPAD_LEFT_THUMB

      public static final char GAMEPAD_LEFT_THUMB
      Gamepad Left Thumb button.
      See Also:
    • GAMEPAD_RIGHT_THUMB

      public static final char GAMEPAD_RIGHT_THUMB
      Gamepad Right Thumb button.
      See Also:
    • GAMEPAD_START

      public static final char GAMEPAD_START
      Gamepad Start button.
      See Also:
    • GAMEPAD_SELECT

      public static final char GAMEPAD_SELECT
      Gamepad Select button.
      See Also:
  • Constructor Details

    • SquidInput

      public SquidInput()
      Constructs a new SquidInput that does not respond to keyboard or mouse input. These can be set later by calling setKeyHandler() to allow keyboard handling or setMouse() to allow mouse handling on a grid.
      All SquidInput constructors must be called after the ApplicationListener.create() method has started, and cannot be called in an ApplicationListener's constructor or in initialization at the class level. This is because all constructors attempt to load a file, if it exists, with Gdx.files.local("keymap.preferences"), and Gdx.files is only available starting in create(). This file, keymap.preferences, is meant to contain any key remappings specified by the user, and its contents should be produced by keyMappingToString() when any key mappings change and are saved. You can use your own filename, but keymap.preferences is the standard one and these can be exchanged between games (so common remappings for users of DVORAK or AZERTY keyboards can be sent between users even if they play different games). If you really want a custom filename, or to load the keymap from a larger user profile, you can give the contents to keyMappingFromString(String) on a SquidInput after construction.
    • SquidInput

      public SquidInput(SquidMouse mouse)
      Constructs a new SquidInput that does not respond to keyboard input, but does take mouse input and passes mouse events along to the given SquidMouse. The SquidMouse, even though it is an InputProcessor on its own, should not be registered by calling Input.setInputProcessor(SquidMouse), and instead this object should be registered by calling Input.setInputProcessor(SquidInput). The keyboard and mouse handling can be changed later by calling setKeyHandler() to allow keyboard handling or setMouse() to change mouse handling.
      All SquidInput constructors must be called after the ApplicationListener.create() method has started, and cannot be called in an ApplicationListener's constructor or in initialization at the class level. This is because all constructors attempt to load a file, if it exists, with Gdx.files.local("keymap.preferences"), and Gdx.files is only available starting in create(). This file, keymap.preferences, is meant to contain any key remappings specified by the user, and its contents should be produced by keyMappingToString() when any key mappings change and are saved. You can use your own filename, but keymap.preferences is the standard one and these can be exchanged between games (so common remappings for users of DVORAK or AZERTY keyboards can be sent between users even if they play different games). If you really want a custom filename, or to load the keymap from a larger user profile, you can give the contents to keyMappingFromString(String) on a SquidInput after construction.
      Parameters:
      mouse - a SquidMouse instance that will be used for handling mouse input.
    • SquidInput

      public SquidInput(SquidInput.KeyHandler keyHandler)
      Constructs a new SquidInput that does not respond to mouse input, but does take keyboard input and sends keyboard events through some processing before calling keyHandler.handle() on keypresses that can sensibly be processed. Modifier keys do not go through the same processing but are checked for their current state when the key is pressed, and the states of alt, ctrl, and shift are passed to keyHandler.handle() as well. You can use setMouse() to allow mouse handling or change the KeyHandler with setKeyHandler().
      All SquidInput constructors must be called after the ApplicationListener.create() method has started, and cannot be called in an ApplicationListener's constructor or in initialization at the class level. This is because all constructors attempt to load a file, if it exists, with Gdx.files.local("keymap.preferences"), and Gdx.files is only available starting in create(). This file, keymap.preferences, is meant to contain any key remappings specified by the user, and its contents should be produced by keyMappingToString() when any key mappings change and are saved. You can use your own filename, but keymap.preferences is the standard one and these can be exchanged between games (so common remappings for users of DVORAK or AZERTY keyboards can be sent between users even if they play different games). If you really want a custom filename, or to load the keymap from a larger user profile, you can give the contents to keyMappingFromString(String) on a SquidInput after construction.
      Parameters:
      keyHandler - must implement the SquidInput.KeyHandler interface so it can handle() key input.
    • SquidInput

      public SquidInput(SquidInput.KeyHandler keyHandler, boolean ignoreInput)
      Constructs a new SquidInput that does not respond to mouse input, but does take keyboard input and sends keyboard events through some processing before calling keyHandler.handle() on keypresses that can sensibly be processed. Modifier keys do not go through the same processing but are checked for their current state when the key is pressed, and the states of alt, ctrl, and shift are passed to keyHandler.handle() as well. You can use setMouse() to allow mouse handling or change the KeyHandler with setKeyHandler().
      All SquidInput constructors must be called after the ApplicationListener.create() method has started, and cannot be called in an ApplicationListener's constructor or in initialization at the class level. This is because all constructors attempt to load a file, if it exists, with Gdx.files.local("keymap.preferences"), and Gdx.files is only available starting in create(). This file, keymap.preferences, is meant to contain any key remappings specified by the user, and its contents should be produced by keyMappingToString() when any key mappings change and are saved. You can use your own filename, but keymap.preferences is the standard one and these can be exchanged between games (so common remappings for users of DVORAK or AZERTY keyboards can be sent between users even if they play different games). If you really want a custom filename, or to load the keymap from a larger user profile, you can give the contents to keyMappingFromString(String) on a SquidInput after construction.
      Parameters:
      keyHandler - must implement the SquidInput.KeyHandler interface so it can handle() key input.
      ignoreInput - true if this should ignore input initially, false if it should process input normally.
    • SquidInput

      public SquidInput(SquidInput.KeyHandler keyHandler, SquidMouse mouse)
      Constructs a new SquidInput that responds to mouse and keyboard input when given a SquidMouse and a SquidInput.KeyHandler implementation. It sends keyboard events through some processing before calling keyHandler.handle() on keypresses that can sensibly be processed. Modifier keys do not go through the same processing but are checked for their current state when the key is pressed, and the states of alt, ctrl, and shift are passed to keyHandler.handle() as well. The SquidMouse, even though it is an InputProcessor on its own, should not be registered by calling Input.setInputProcessor(SquidMouse), and instead this object should be registered by calling Input.setInputProcessor(SquidInput). You can use setKeyHandler() or setMouse() to change keyboard or mouse handling.
      All SquidInput constructors must be called after the ApplicationListener.create() method has started, and cannot be called in an ApplicationListener's constructor or in initialization at the class level. This is because all constructors attempt to load a file, if it exists, with Gdx.files.local("keymap.preferences"), and Gdx.files is only available starting in create(). This file, keymap.preferences, is meant to contain any key remappings specified by the user, and its contents should be produced by keyMappingToString() when any key mappings change and are saved. You can use your own filename, but keymap.preferences is the standard one and these can be exchanged between games (so common remappings for users of DVORAK or AZERTY keyboards can be sent between users even if they play different games). If you really want a custom filename, or to load the keymap from a larger user profile, you can give the contents to keyMappingFromString(String) on a SquidInput after construction.
      Parameters:
      keyHandler - must implement the SquidInput.KeyHandler interface so it can handle() key input.
      mouse - a SquidMouse instance that will be used for handling mouse input.
    • SquidInput

      public SquidInput(SquidInput.KeyHandler keyHandler, SquidMouse mouse, boolean ignoreInput)
      Constructs a new SquidInput that responds to mouse and keyboard input when given a SquidMouse and a SquidInput.KeyHandler implementation, and can be put in an initial state where it ignores input until told otherwise via setIgnoreInput(boolean). It sends keyboard events through some processing before calling keyHandler.handle() on keypresses that can sensibly be processed. Modifier keys do not go through the same processing but are checked for their current state when the key is pressed, and the states of alt, ctrl, and shift are passed to keyHandler.handle() as well. The SquidMouse, even though it is an InputProcessor on its own, should not be registered by calling Input.setInputProcessor(SquidMouse), and instead this object should be registered by calling Input.setInputProcessor(SquidInput). You can use setKeyHandler() or setMouse() to change keyboard or mouse handling.
      All SquidInput constructors must be called after the ApplicationListener.create() method has started, and cannot be called in an ApplicationListener's constructor or in initialization at the class level. This is because all constructors attempt to load a file, if it exists, with Gdx.files.local("keymap.preferences"), and Gdx.files is only available starting in create(). This file, keymap.preferences, is meant to contain any key remappings specified by the user, and its contents should be produced by keyMappingToString() when any key mappings change and are saved. You can use your own filename, but keymap.preferences is the standard one and these can be exchanged between games (so common remappings for users of DVORAK or AZERTY keyboards can be sent between users even if they play different games). If you really want a custom filename, or to load the keymap from a larger user profile, you can give the contents to keyMappingFromString(String) on a SquidInput after construction.
      Parameters:
      keyHandler - must implement the SquidInput.KeyHandler interface so it can handle() key input.
      mouse - a SquidMouse instance that will be used for handling mouse input.
      ignoreInput - true if this should ignore input initially, false if it should process input normally.
  • Method Details

    • setKeyHandler

      public void setKeyHandler(SquidInput.KeyHandler keyHandler)
    • setMouse

      public void setMouse(SquidMouse mouse)
    • isUsingNumpadDirections

      public boolean isUsingNumpadDirections()
    • setUsingNumpadDirections

      public void setUsingNumpadDirections(boolean using)
    • getKeyHandler

      public SquidInput.KeyHandler getKeyHandler()
    • getMouse

      public SquidMouse getMouse()
    • getIgnoreInput

      public boolean getIgnoreInput()
      Get the status for whether this should ignore input right now or not. True means this object will ignore and not queue input, false means it should process them normally. Useful to pause processing or delegate it to another object temporarily.
      Returns:
      true if this object currently ignores input, false otherwise.
    • setIgnoreInput

      public void setIgnoreInput(boolean ignoreInput)
      Set the status for whether this should ignore input right now or not. True means this object will ignore and not queue input, false means it should process them normally. Useful to pause processing or delegate it to another object temporarily.
      Parameters:
      ignoreInput - true if this should object should ignore and not queue input, false otherwise.
    • remap

      public SquidInput remap(char pressedChar, boolean pressedAlt, boolean pressedCtrl, boolean pressedShift, char targetChar, boolean targetAlt, boolean targetCtrl, boolean targetShift)
      Remaps a char that could be input and processed by SquidInput.KeyHandler.handle(char, boolean, boolean, boolean) (possibly with some pressed modifiers) to another char with possible modifiers. When the first key/modifier mix is received, it will be translated to the second group in this method.
      Parameters:
      pressedChar - a source char that might be used in handling, like 'q', 'A', '7', '(', or UP_ARROW.
      pressedAlt - true if alt is part of the source combined keypress, false otherwise
      pressedCtrl - true if ctrl is part of the source combined keypress, false otherwise
      pressedShift - true if shift is part of the source combined keypress, false otherwise
      targetChar - a target char that might be used in handling, like 'q', 'A', '7', '(', or UP_ARROW.
      targetAlt - true if alt is part of the target combined keypress, false otherwise
      targetCtrl - true if ctrl is part of the target combined keypress, false otherwise
      targetShift - true if shift is part of the target combined keypress, false otherwise
      Returns:
      this for chaining
    • remap

      public SquidInput remap(int pressed, int target)
      Remaps a keypress combination, which is a char and several potential modifiers, to another keypress combination. When the pressed combination is received, it will be translated to target in this method.
      Parameters:
      pressed - an int for the source keypress, probably produced by combineModifiers(char, boolean, boolean, boolean)
      target - an int for the target keypress, probably produced by combineModifiers(char, boolean, boolean, boolean)
      Returns:
      this for chaining
      See Also:
    • remap

      public SquidInput remap(int[] pairs)
      Remaps many keypress combinations, each of which is a char and several potential modifiers, to other keypress combinations. When the first of a pair of combinations is received, it will be translated to the second combination of the pair.
      Parameters:
      pairs - an int array alternating source and target keypresses, each probably produced by combineModifiers(char, boolean, boolean, boolean)
      Returns:
      this for chaining
      See Also:
    • unmap

      public SquidInput unmap(char pressedChar, boolean pressedAlt, boolean pressedCtrl, boolean pressedShift)
      Removes a keypress combination from the mapping by specifying the char and any modifiers that are part of the keypress combination. This combination will no longer be remapped, but the original handling will be the same.
      Parameters:
      pressedChar - a char that might be used in handling, like 'q', 'A', '7', '(', or UP_ARROW.
      pressedAlt - true if alt is part of the combined keypress, false otherwise
      pressedCtrl - true if ctrl is part of the combined keypress, false otherwise
      pressedShift - true if shift is part of the combined keypress, false otherwise
      Returns:
      this for chaining
    • unmap

      public SquidInput unmap(int pressed)
      Removes a keypress combination from the mapping by specifying the keypress combination as an int. This combination will no longer be remapped, but the original handling will be the same.
      Parameters:
      pressed - an int for the source keypress, probably produced by combineModifiers(char, boolean, boolean, boolean)
      Returns:
      this for chaining
      See Also:
    • clearMapping

      public SquidInput clearMapping()
      Removes any remappings to key bindings that were in use in this SquidInput.
      Returns:
      this for chaining
    • combineModifiers

      public static int combineModifiers(char key, boolean alt, boolean ctrl, boolean shift)
      Combines the key (as it would be given to SquidInput.KeyHandler.handle(char, boolean, boolean, boolean)) with the three booleans for the alt, ctrl, and shift modifier keys, returning an int that can be used with the internal queue of ints or the public mapping of received inputs to actual inputs the program can process.
      Parameters:
      key - a char that might be used in handling, like 'q', 'A', '7', '(', or UP_ARROW.
      alt - true if alt is part of this combined keypress, false otherwise
      ctrl - true if ctrl is part of this combined keypress, false otherwise
      shift - true if shift is part of this combined keypress, false otherwise
      Returns:
      an int that contains the information to represent the key with any modifiers as one value
    • keyMappingToString

      public String keyMappingToString()
      Gets the current key remapping as a String, which can be saved in a file and read back with keyMappingFromString(String). Because that method is automatically called by SquidInput's constructor and tries to load a file named "keymap.preferences" in the local folder, it is recommended that you save user-remapped keys to that file, but only if the user has actively changed them (that file could exist from an earlier run, and you don't want to affect it unless the user made some change). This will allow input with any of Shift, Alt, and Ctl modifiers in any script supported by the Unicode Basic Multilingual Plane (the first 65536 chars of Unicode).
      Returns:
      a String that stores four chars per remapping.
    • keyMappingFromString

      public SquidInput keyMappingFromString(String keymap)
      Reads in a String (almost certainly produced by keyMappingToString()) to set the current key remapping. This is automatically called if a file named "keymap.preferences" is present in the local folder, receiving the contents of that file as a parameter, so games that want to save a user's preferences should try to save that file if possible (this also allows one file to be reused across multiple computers or installations by copying it). This will allow input with any of Shift, Alt, and Ctl modifiers in any script supported by the Unicode Basic Multilingual Plane (the first 65536 chars of Unicode). You may want to call clearMapping() before calling this if you have already set the mapping and want the String's contents to be used as the only mapping.
      Parameters:
      keymap - a String that was probably produced by keyMappingToString()
      Returns:
      this for chaining
    • drain

      public void drain()
      Processes all events queued up, passing them through this object's key processing and then to keyHandler. Mouse events are not queued and are processed when they come in.
    • getRepeatGap

      public long getRepeatGap()
      Gets the amount of milliseconds of holding a key this requires to count as a key repeat. The default is 220.
      Returns:
      how long a key needs to be held before this will count it as a key repeat, as a long in milliseconds
    • setRepeatGap

      public void setRepeatGap(long time)
      Sets the amount of milliseconds of holding a key this requires to count as a key repeat. The default is 220.
      Parameters:
      time - how long a key needs to be held before this will count it as a key repeat, as a positive long in milliseconds
    • hasNext

      public boolean hasNext()
      Returns true if at least one event is queued, but also will call keyDown(int) if a key is being held but there is a failure to process the repeated event. The conditions this checks:
      • Is a key is currently being held?
      • Are no modifier keys being held (shift, control, alt)? (without this check, the modifier key counts as a repeat of the key it modifies, which is probably never the intended behavior)
      • Has keyDown(int) already been called at least once?
      • Have there been at least getRepeatGap() milliseconds between the last key being received and this call?
      If all of these conditions are true, keyDown() is called again with the last key it had received, and if this has an effect (the key can be handled), then generally an event should be queued, so this will have a next event and should return true. You can change the amount of time required to hold a key to cause key repeats with setRepeatGap(long), but the default of 220 ms is usually suitable. Too low of a value can cause normal key presses to be counted twice or more, and too high of a value may delay an expected key repeat.
      Returns:
      true if there is an event queued, false otherwise
    • next

      public void next()
      Processes the first key event queued up, passing it to this object's InputProcessor. Mouse events are not queued and are processed when they come in.
    • flush

      public void flush()
      Empties the backing queue of data.
    • keyDown

      public boolean keyDown(int keycode)
      Specified by:
      keyDown in interface com.badlogic.gdx.InputProcessor
      Overrides:
      keyDown in class com.badlogic.gdx.InputAdapter
    • keyUp

      public boolean keyUp(int keycode)
      Specified by:
      keyUp in interface com.badlogic.gdx.InputProcessor
      Overrides:
      keyUp in class com.badlogic.gdx.InputAdapter
    • keyTyped

      public boolean keyTyped(char character)
      Specified by:
      keyTyped in interface com.badlogic.gdx.InputProcessor
      Overrides:
      keyTyped in class com.badlogic.gdx.InputAdapter
    • touchDown

      public boolean touchDown(int screenX, int screenY, int pointer, int button)
      Specified by:
      touchDown in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchDown in class com.badlogic.gdx.InputAdapter
    • touchUp

      public boolean touchUp(int screenX, int screenY, int pointer, int button)
      Specified by:
      touchUp in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchUp in class com.badlogic.gdx.InputAdapter
    • touchDragged

      public boolean touchDragged(int screenX, int screenY, int pointer)
      Specified by:
      touchDragged in interface com.badlogic.gdx.InputProcessor
      Overrides:
      touchDragged in class com.badlogic.gdx.InputAdapter
    • mouseMoved

      public boolean mouseMoved(int screenX, int screenY)
      Specified by:
      mouseMoved in interface com.badlogic.gdx.InputProcessor
      Overrides:
      mouseMoved in class com.badlogic.gdx.InputAdapter
    • scrolled

      public boolean scrolled(float amountX, float amountY)
      Specified by:
      scrolled in interface com.badlogic.gdx.InputProcessor
      Overrides:
      scrolled in class com.badlogic.gdx.InputAdapter
    • fromCode

      public char fromCode(int keycode, boolean shift)
      Maps keycodes to Unicode chars, sometimes depending on whether the Shift key is held.
      It is strongly recommended that you refer to key combinations regarding non-alphabet keys by using, for example, Ctrl-Shift-; instead of Ctrl-:, that is to use the unshifted key with Shift instead of assuming that all keyboards will use the QWERTY layout. Pressing shift while pressing just about any representable symbol will map to the shifted version as if on a QWERTY keyboard, and if you don't have a QWERTY keyboard, the mappings are documented in full below.
      Keys 'a' to 'z' report 'A' to 'Z' when shift is held. Non-ASCII-Latin characters do not have this behavior, since most keyboards would be unable to send keys for a particular language and A-Z are very common. You can still allow a response to, e.g. 'ä' and 'Ä' separately by checking for whether Shift was pressed in conjunction with 'ä' on a keyboard with that key, which can be useful when users can configure their own keyboard layouts.
      Top row numbers map as follows:
      '1' to '!', '2' to '@', '3' to '#', '4' to '$', '5' to '%', '6' to '^', '7' to '&', '8' to '*', '9' to '(', '0' to ')'
      Numpad numbers will report a SquidInput constant such as UP_LEFT_ARROW for Numpad 7, but only if numpadDirections is true; otherwise they send the number (here, 7). Numpad 0 sends VERTICAL_ARROW or 0.
      Most symbol keys are mapped to a single Unicode char as a constant in SquidInput and disregard Shift. The constant is usually the same as the name of the char; possible exceptions are Backspace (on PC) or Delete (on Mac) mapping to BACKSPACE, Delete (on PC) mapping to FORWARD_DELETE, Esc mapping to ESCAPE, and Enter (on PC) or Return (on Mac) mapping to ENTER.
      ':', '*', '#', '@', and space keys, if present, always map to themselves, regardless of Shift.
      Other characters map as follows when Shift is held, as they would on a QWERTY keyboard:
      • ',' to '<'
      • '.' to '>'
      • '/' to '?'
      • ';' to ':'
      • '\'' to '"'
      • '[' to '{'
      • ']' to '}'
      • '|' to '\\'
      • '-' to '_'
      • '+' to '='
      • '`' to '~' (note, this key produces no event on the GWT backend)
      Parameters:
      keycode - a keycode as passed by libGDX
      shift - true if Shift key is being held.
      Returns:
      a char appropriate to the given keycode; often uses shift to capitalize or change a char, but not for keys like the arrow keys that normally don't produce chars