Class SquidKey

java.lang.Object
squidpony.squidgrid.gui.gdx.SquidKey
All Implemented Interfaces:
com.badlogic.gdx.InputProcessor

public class SquidKey
extends Object
implements com.badlogic.gdx.InputProcessor
This wraps an InputProcessor, 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(SquidKey).
It does not perform the blocking functionality of the now-removed Swing SquidKey implementation, 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 get an event if hasNext() returns true by calling next().
Author:
Eben Howard - http://squidpony.com - howard@squidpony.com, Nathan Sweet, Tommy Ettinger
  • Constructor Summary

    Constructors 
    Constructor Description
    SquidKey()
    Constructs a SquidKey with no InputProcessor; for this to do anything, setProcessor() must be called.
    SquidKey​(com.badlogic.gdx.InputProcessor processor)
    Constructs a SquidKey with the given InputProcessor.
    SquidKey​(com.badlogic.gdx.InputProcessor processor, boolean ignoreInput)
    Constructs a SquidKey with the given InputProcessor.
  • Method Summary

    Modifier and Type Method Description
    void drain()
    Processes all events queued up, passing them to this object's InputProcessor.
    void flush()
    Empties the backing queue of data.
    boolean getIgnoreInput()
    Get the status for whether this should ignore input right now or not.
    com.badlogic.gdx.InputProcessor getProcessor()
    Gets this object's InputProcessor.
    boolean hasNext()
    Returns true if at least one event is queued.
    boolean keyDown​(int keycode)  
    boolean keyTyped​(char character)  
    boolean keyUp​(int keycode)  
    boolean mouseMoved​(int screenX, int screenY)  
    void next()
    Processes the first event queued up, passing it to this object's InputProcessor.
    boolean scrolled​(int amount)  
    void setIgnoreInput​(boolean ignoreInput)
    Set the status for whether this should ignore input right now or not.
    void setProcessor​(com.badlogic.gdx.InputProcessor processor)
    Sets the InputProcessor that this object will use to make sense of Key events.
    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)  

    Methods inherited from class java.lang.Object

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

    • SquidKey

      public SquidKey()
      Constructs a SquidKey with no InputProcessor; for this to do anything, setProcessor() must be called.
    • SquidKey

      public SquidKey​(com.badlogic.gdx.InputProcessor processor)
      Constructs a SquidKey with the given InputProcessor.
      Parameters:
      processor - An InputProcessor that will handle keyDown(), keyUp(), and keyTyped() events
    • SquidKey

      public SquidKey​(com.badlogic.gdx.InputProcessor processor, boolean ignoreInput)
      Constructs a SquidKey with the given InputProcessor.
      Parameters:
      processor - An InputProcessor that will handle keyDown(), keyUp(), and keyTyped() events
      ignoreInput - the starting value for the ignore status; true to ignore input, false to process it.
  • Method Details

    • setProcessor

      public void setProcessor​(com.badlogic.gdx.InputProcessor processor)
      Sets the InputProcessor that this object will use to make sense of Key events.
      Parameters:
      processor - An InputProcessor that will handle keyDown(), keyUp(), and keyTyped() events
    • getProcessor

      public com.badlogic.gdx.InputProcessor getProcessor()
      Gets this object's InputProcessor.
      Returns:
      this object's InputProcessor
    • 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 keypresses, 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 keypresses, 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.
    • drain

      public void drain()
      Processes all events queued up, passing them to this object's InputProcessor.
    • hasNext

      public boolean hasNext()
      Returns true if at least one event is queued.
      Returns:
      true if there is an event queued, false otherwise.
    • next

      public void next()
      Processes the first event queued up, passing it to this object's InputProcessor.
    • 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
    • keyUp

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

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

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

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

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

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

      public boolean scrolled​(int amount)
      Specified by:
      scrolled in interface com.badlogic.gdx.InputProcessor