Class SquidInput

java.lang.Object
com.badlogic.gdx.InputAdapter
squidpony.squidgrid.gui.gdx.SquidInput
All Implemented Interfaces:
com.badlogic.gdx.InputProcessor
Direct Known Subclasses:
VisualInput

public class SquidInput
extends com.badlogic.gdx.InputAdapter
This input processing class can handle mouse and keyboard input, using a squidpony.squidgrid.gui.gdx.SquidMouse for Mouse input and a user implementation of the SquidInput.KeyHandler interface 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, '↓'. 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.
It does not perform the blocking functionality of earlier SquidKey implementations, because this is meant to run in an event-driven libGDX game and should not step on the toes of libGDX's input handling. 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.
Author:
Eben Howard - http://squidpony.com - howard@squidpony.com, Nathan Sweet, Tommy Ettinger
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static interface  SquidInput.KeyHandler
    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 char BACKSPACE
    Backspace key on most PC keyboards; Delete key on Mac keyboards.
    static char CENTER_ARROW
    Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 5.
    static char DOWN_ARROW
    Down arrow key.
    static char DOWN_LEFT_ARROW
    Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 1.
    static char DOWN_RIGHT_ARROW
    Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 3.
    static char END
    End key (commonly used for moving a cursor to end of line).
    static char ENTER
    Enter key, also called Return key.
    static char ESCAPE
    Esc or Escape key
    static char F1
    Function key F1
    static char F10
    Function key F10
    static char F11
    Function key F11
    static char F12
    Function key F12
    static char F2
    Function key F2
    static char F3
    Function key F3
    static char F4
    Function key F4
    static char F5
    Function key F5
    static char F6
    Function key F6
    static char F7
    Function key F7
    static char F8
    Function key F8
    static char F9
    Function key F9
    static char FORWARD_DELETE
    Delete key on most PC keyboards; no equivalent on some (all?) Mac keyboards.
    static char GAMEPAD_A
    Gamepad A button.
    static char GAMEPAD_B
    Gamepad B button.
    static char GAMEPAD_C
    Gamepad C button.
    static char GAMEPAD_L1
    Gamepad L1 button.
    static char GAMEPAD_L2
    Gamepad L2 button.
    static char GAMEPAD_LEFT_THUMB
    Gamepad Left Thumb button.
    static char GAMEPAD_R1
    Gamepad R1 button.
    static char GAMEPAD_R2
    Gamepad R2 button.
    static char GAMEPAD_RIGHT_THUMB
    Gamepad Right Thumb button.
    static char GAMEPAD_SELECT
    Gamepad Select button.
    static char GAMEPAD_START
    Gamepad Start button.
    static char GAMEPAD_X
    Gamepad X button.
    static char GAMEPAD_Y
    Gamepad Y button.
    static char GAMEPAD_Z
    Gamepad Z button.
    protected IntIntOrderedMap heldCodes  
    static char HOME
    Home key (commonly used for moving a cursor to start of line).
    protected boolean ignoreInput  
    static char INSERT
    Insert key.
    protected SquidInput.KeyHandler keyAction  
    protected long lastKeyTime  
    static char LEFT_ARROW
    Left arrow key.
    com.badlogic.gdx.utils.IntIntMap mapping  
    protected SquidMouse mouse  
    protected boolean numpadDirections  
    static char PAGE_DOWN
    Page Down key.
    static char PAGE_UP
    Page Up key.
    protected IntVLA queue  
    protected long repeatGapMillis  
    static char RIGHT_ARROW
    Down arrow key.
    static char TAB
    Tab key.
    static char UP_ARROW
    Up arrow key.
    static char UP_LEFT_ARROW
    Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 7.
    static char UP_RIGHT_ARROW
    Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 9.
    static char VERTICAL_ARROW
    Not typically a dedicated key, but if numpadDirections is enabled, this will be sent by Numpad 0.
  • Constructor Summary

    Constructors 
    Constructor Description
    SquidInput()
    Constructs a new SquidInput that does not respond to keyboard or mouse input.
    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.
    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.
    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.
    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).
    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.
  • Method Summary

    Modifier and Type Method Description
    SquidInput clearMapping()
    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 drain()
    Processes all events queued up, passing them through this object's key processing and then to keyHandler.
    void flush()
    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 getIgnoreInput()
    Get the status for whether this should ignore input right now or not.
    SquidInput.KeyHandler getKeyHandler()  
    SquidMouse getMouse()  
    long getRepeatGap()
    Gets the amount of milliseconds of holding a key this requires to count as a key repeat.
    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.
    boolean isUsingNumpadDirections()  
    boolean keyDown​(int keycode)  
    SquidInput keyMappingFromString​(String keymap)
    Reads in a String (almost certainly produced by keyMappingToString()) to set the current key remapping.
    String keyMappingToString()
    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 next()
    Processes the first key event queued up, passing it to this object's InputProcessor.
    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.
    SquidInput remap​(int[] pairs)
    Remaps many keypress combinations, each of which is a char and several potential modifiers, to other keypress combinations.
    SquidInput remap​(int pressed, int target)
    Remaps a keypress combination, which is a char and several potential modifiers, to another keypress combination.
    boolean scrolled​(int amount)  
    void setIgnoreInput​(boolean ignoreInput)
    Set the status for whether this should ignore input right now or not.
    void setKeyHandler​(SquidInput.KeyHandler keyHandler)  
    void setMouse​(SquidMouse mouse)  
    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)  
    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.
    SquidInput unmap​(int pressed)
    Removes a keypress combination from the mapping by specifying the keypress combination as an int.

    Methods inherited from class java.lang.Object

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

  • 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

    • 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:
      combineModifiers is usually used to make pressed and target
    • 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:
      combineModifiers is usually used to make the contents of pairs
    • 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:
      combineModifiers is usually used to make pressed
    • 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

      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

      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​(int amount)
      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