Class InputListener

  • All Implemented Interfaces:
    EventListener
    Direct Known Subclasses:
    ClickListener, DragListener, Tooltip

    public class InputListener
    extends java.lang.Object
    implements EventListener
    EventListener for low-level input events. Unpacks InputEvents and calls the appropriate method. By default the methods here do nothing with the event. Users are expected to override the methods they are interested in, like this:
     actor.addListener(new InputListener() {
            public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
                    Gdx.app.log("Example", "touch started at (" + x + ", " + y + ")");
                    return false;
            }
     
            public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
                    Gdx.app.log("Example", "touch done at (" + x + ", " + y + ")");
            }
     });
     
    • Constructor Summary

      Constructors 
      Constructor Description
      InputListener()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void enter​(InputEvent event, float x, float y, int pointer, Actor fromActor)
      Called any time the mouse cursor or a finger touch is moved over an actor.
      void exit​(InputEvent event, float x, float y, int pointer, Actor toActor)
      Called any time the mouse cursor or a finger touch is moved out of an actor.
      boolean handle​(Event e)
      Try to handle the given event, if it is an InputEvent.
      boolean keyDown​(InputEvent event, int keycode)
      Called when a key goes down.
      boolean keyTyped​(InputEvent event, char character)
      Called when a key is typed.
      boolean keyUp​(InputEvent event, int keycode)
      Called when a key goes up.
      boolean mouseMoved​(InputEvent event, float x, float y)
      Called any time the mouse is moved when a button is not down.
      boolean scrolled​(InputEvent event, float x, float y, float amountX, float amountY)
      Called when the mouse wheel has been scrolled.
      boolean touchDown​(InputEvent event, float x, float y, int pointer, int button)
      Called when a mouse button or a finger touch goes down on the actor.
      void touchDragged​(InputEvent event, float x, float y, int pointer)
      Called when a mouse button or a finger touch is moved anywhere, but only if touchDown previously returned true for the mouse button or touch.
      void touchUp​(InputEvent event, float x, float y, int pointer, int button)
      Called when a mouse button or a finger touch goes up anywhere, but only if touchDown previously returned true for the mouse button or touch.
      • Methods inherited from class java.lang.Object

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

      • InputListener

        public InputListener()
    • Method Detail

      • touchDown

        public boolean touchDown​(InputEvent event,
                                 float x,
                                 float y,
                                 int pointer,
                                 int button)
        Called when a mouse button or a finger touch goes down on the actor. If true is returned, this listener will have touch focus, so it will receive all touchDragged and touchUp events, even those not over this actor, until touchUp is received. Also when true is returned, the event is handled.
        See Also:
        InputEvent
      • touchUp

        public void touchUp​(InputEvent event,
                            float x,
                            float y,
                            int pointer,
                            int button)
        Called when a mouse button or a finger touch goes up anywhere, but only if touchDown previously returned true for the mouse button or touch. The touchUp event is always handled.
        See Also:
        InputEvent
      • touchDragged

        public void touchDragged​(InputEvent event,
                                 float x,
                                 float y,
                                 int pointer)
        Called when a mouse button or a finger touch is moved anywhere, but only if touchDown previously returned true for the mouse button or touch. The touchDragged event is always handled.
        See Also:
        InputEvent
      • mouseMoved

        public boolean mouseMoved​(InputEvent event,
                                  float x,
                                  float y)
        Called any time the mouse is moved when a button is not down. This event only occurs on the desktop. When true is returned, the event is handled.
        See Also:
        InputEvent
      • enter

        public void enter​(InputEvent event,
                          float x,
                          float y,
                          int pointer,
                          @Null
                          Actor fromActor)
        Called any time the mouse cursor or a finger touch is moved over an actor. On the desktop, this event occurs even when no mouse buttons are pressed (pointer will be -1).
        Parameters:
        fromActor - May be null.
        See Also:
        InputEvent
      • exit

        public void exit​(InputEvent event,
                         float x,
                         float y,
                         int pointer,
                         @Null
                         Actor toActor)
        Called any time the mouse cursor or a finger touch is moved out of an actor. On the desktop, this event occurs even when no mouse buttons are pressed (pointer will be -1).
        Parameters:
        toActor - May be null.
        See Also:
        InputEvent
      • scrolled

        public boolean scrolled​(InputEvent event,
                                float x,
                                float y,
                                float amountX,
                                float amountY)
        Called when the mouse wheel has been scrolled. When true is returned, the event is handled.
      • keyDown

        public boolean keyDown​(InputEvent event,
                               int keycode)
        Called when a key goes down. When true is returned, the event is handled.
      • keyUp

        public boolean keyUp​(InputEvent event,
                             int keycode)
        Called when a key goes up. When true is returned, the event is handled.
      • keyTyped

        public boolean keyTyped​(InputEvent event,
                                char character)
        Called when a key is typed. When true is returned, the event is handled.
        Parameters:
        character - May be 0 for key typed events that don't map to a character (ctrl, shift, etc).