APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.scenes.scene2d

public Class InputListener

extends Object
implements EventListener
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.scenes.scene2d.EventListener
Known Direct Subclasses
com.badlogic.gdx.scenes.scene2d.ui.Tooltip, com.badlogic.gdx.scenes.scene2d.utils.ClickListener, com.badlogic.gdx.scenes.scene2d.utils.DragListener
Imports
com.badlogic.gdx.math.Vector2, com.badlogic.gdx.utils.Null

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 + ")");
	}
});

Field Summary

Modifier and TypeField and Description
private static final Vector2

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
enter(InputEvent event, float x, float y, int pointer, Actor
May be null.
fromActor
)

Called any time the mouse cursor or a finger touch is moved over an actor.

public void
exit(InputEvent event, float x, float y, int pointer, Actor
May be null.
toActor
)

Called any time the mouse cursor or a finger touch is moved out of an actor.

public boolean
handle(Event e)

Implements com.badlogic.gdx.scenes.scene2d.EventListener.handle.

Try to handle the given event, if it is an InputEvent.

public boolean
keyDown(InputEvent event, int keycode)

Called when a key goes down.

public boolean
keyTyped(InputEvent event, char
May be 0 for key typed events that don't map to a character (ctrl, shift, etc).
character
)

Called when a key is typed.

public boolean
keyUp(InputEvent event, int keycode)

Called when a key goes up.

public boolean
mouseMoved(InputEvent event, float x, float y)

Called any time the mouse is moved when a button is not down.

public boolean
scrolled(InputEvent event, float x, float y, float amountX, float amountY)

Called when the mouse wheel has been scrolled.

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.

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.

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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

tmpCoordsback to summary
private static final Vector2 tmpCoords

Constructor Detail

InputListenerback to summary
public InputListener()

Method Detail

enterback to summary
public 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. On the desktop, this event occurs even when no mouse buttons are pressed (pointer will be -1).

Parameters
fromActor:Actor

May be null.

See Also
InputEvent
exitback to summary
public 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. On the desktop, this event occurs even when no mouse buttons are pressed (pointer will be -1).

Parameters
toActor:Actor

May be null.

See Also
InputEvent
handleback to summary
public boolean handle(Event e)

Implements com.badlogic.gdx.scenes.scene2d.EventListener.handle.

Try to handle the given event, if it is an InputEvent.

If the input event is of type InputEvent.Type#touchDown and InputEvent#getTouchFocus() is true and touchDown(InputEvent, float, float, int, int) returns true (indicating the event was handled) then this listener is added to the stage's touch focus so it will receive all touch dragged events until the next touch up event.

keyDownback to summary
public boolean keyDown(InputEvent event, int keycode)

Called when a key goes down. When true is returned, the event is handled.

keyTypedback to summary
public boolean keyTyped(InputEvent event, char character)

Called when a key is typed. When true is returned, the event is handled.

Parameters
character:char

May be 0 for key typed events that don't map to a character (ctrl, shift, etc).

keyUpback to summary
public boolean keyUp(InputEvent event, int keycode)

Called when a key goes up. When true is returned, the event is handled.

mouseMovedback to summary
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
scrolledback to summary
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.

touchDownback to summary
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
touchDraggedback to summary
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
touchUpback to summary
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