APIdia Launch Partner
Top Description Inners Methods
com.badlogic.gdx

public Interface Input

Known Direct Implementers
com.badlogic.gdx.input.RemoteInput, com.badlogic.gdx.AbstractInput
Imports
com.badlogic.gdx.input.NativeInputConfiguration, .NativeInputConfiguration.NativeInputCloseCallback, com.badlogic.gdx.utils.Null, .ObjectIntMap

Interface to the input facilities. This allows polling the state of the keyboard, the touch screen and the accelerometer. On some backends (desktop, gwt, etc) the touch screen is replaced by mouse input. The accelerometer is of course not available on all backends.

Instead of polling for events, one can process all input events with an InputProcessor. You can set the InputProcessor via the setInputProcessor(InputProcessor) method. It will be called before the ApplicationListener#render() method in each frame.

Keyboard keys are translated to the constants in Keys transparently on all systems. Do not use system specific key constants.

The class also offers methods to use (and test for the presence of) other input systems like vibration, compass, on-screen keyboards, and cursor capture. Support for simple input dialogs is also provided.

Author
mzechner

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Input.Buttons

Mouse buttons.

public static interface
public static interface
public static class
public static enum
public static enum
public static enum
Input.Peripheral

Enumeration of potentially available peripherals.

public static interface
public static enum

Method Summary

Modifier and TypeMethod and Description
public default void
closeTextInputField(boolean
Whether the closing can be considered confirmative. Will be passed to the NativeInputCloseCallback
isConfirmative
)

Closes the native input field and applies the result to the input wrapper.

public default void
closeTextInputField(boolean
Whether the closing can be considered confirmative. Will be passed to the NativeInputCloseCallback
isConfirmative
,
NativeInputConfiguration.NativeInputCloseCallback
An optional callback to also run, when the close was processed. Will be called on the main thread. Will be called after NativeInputCloseCallback
callback
)

Closes the native input field and applies the result to the input wrapper.

public float
getAccelerometerX()

Returns: The acceleration force in m/s^2 applied to the device in the X axis, including the force of gravity

public float
getAccelerometerY()

Returns: The acceleration force in m/s^2 applied to the device in the Y axis, including the force of gravity

public float
getAccelerometerZ()

Returns: The acceleration force in m/s^2 applied to the device in the Z axis, including the force of gravity

public float

Returns:

the azimuth in degrees
getAzimuth
()

The azimuth is the angle of the device's orientation around the z-axis.

public long
getCurrentEventTime()

Returns: the time of the event currently reported to the InputProcessor.

public int
getDeltaX()

Returns: the different between the current pointer location and the last pointer location on the x-axis.

public int
getDeltaX(int pointer)

Returns: the different between the current pointer location and the last pointer location on the x-axis.

public int
getDeltaY()

Returns: the different between the current pointer location and the last pointer location on the y-axis.

public int
getDeltaY(int pointer)

Returns: the different between the current pointer location and the last pointer location on the y-axis.

public float
getGyroscopeX()

Returns: The rate of rotation in rad/s around the X axis

public float
getGyroscopeY()

Returns: The rate of rotation in rad/s around the Y axis

public float
getGyroscopeZ()

Returns: The rate of rotation in rad/s around the Z axis

public InputProcessor
getInputProcessor()

Returns: the currently set InputProcessor or null.

public int
getMaxPointers()

Returns: The maximum number of pointers supported

public Input.Orientation
getNativeOrientation()

Returns: the native orientation of the device.

public float

Returns:

the pitch in degrees
getPitch
()

The pitch is the angle of the device's orientation around the x-axis.

public float
getPressure()

Returns: the pressure of the first pointer

public float

Returns:

the pressure
getPressure
(int
the pointer id.
pointer
)

Returns the pressure of the given pointer, where 0 is untouched.

public float

Returns:

the roll in degrees
getRoll
()

The roll is the angle of the device's orientation around the y-axis.

public int
getRotation()

Returns: the rotation of the device with respect to its native orientation.

public void
getRotationMatrix(float[] matrix)

Returns the rotation matrix describing the devices rotation as per SensorManager#getRotationMatrix(float[], float[], float[], float[]).

public void
getTextInput(Input.TextInputListener
The TextInputListener.
listener
,
String
The title of the text input dialog.
title
,
String
The message presented to the user.
text
,
String hint)

System dependent method to input a string of text.

public void
getTextInput(Input.TextInputListener
The TextInputListener.
listener
,
String
The title of the text input dialog.
title
,
String
The message presented to the user.
text
,
String hint, Input.OnscreenKeyboardType
which type of keyboard we wish to display
type
)

System dependent method to input a string of text.

public int
getX()

Returns: The x coordinate of the last touch on touch screen devices and the current mouse position on desktop for the first pointer in screen coordinates.

public int

Returns:

the x coordinate
getX
(int
the pointer id.
pointer
)

Returns the x coordinate in screen coordinates of the given pointer.

public int
getY()

Returns: The y coordinate of the last touch on touch screen devices and the current mouse position on desktop for the first pointer in screen coordinates.

public int

Returns:

the y coordinate
getY
(int
the pointer id.
pointer
)

Returns the y coordinate in screen coordinates of the given pointer.

public boolean

Returns:

true or false.
isButtonJustPressed
(int
the button to check.
button
)

Returns whether a given button has just been pressed.

public boolean

Returns:

whether the button is down or not.
isButtonPressed
(int
the button to check.
button
)

Whether a given button is pressed or not.

public boolean
isCatchKey(int
keycode to check if caught
keycode
)

Returns: true if the given keycode is configured to be caught

public boolean
isCursorCatched()

Returns: whether the mouse cursor is catched.

public boolean

Returns:

true or false.
isKeyJustPressed
(int
The key code as found in Input.Keys.
key
)

Returns whether the key has just been pressed.

public boolean

Returns:

true or false.
isKeyPressed
(int
The key code as found in Input.Keys.
key
)

Returns whether the key is pressed.

public boolean

Returns:

whether the peripheral is available or not.
isPeripheralAvailable
(Input.Peripheral peripheral)

Queries whether a Peripheral is currently available.

public default boolean
isTextInputFieldOpened()

Returns if a native input field is currently open

public boolean
isTouched()

Returns: whether the screen is currently touched.

public boolean

Returns:

whether the screen is touched by the pointer
isTouched
(int
the pointer
pointer
)

Whether the screen is currently touched by the pointer with the given index.

public boolean
justTouched()

Returns: whether a new touch down event just occurred.

public void
openTextInputField(NativeInputConfiguration
The configuration for the native input field
configuration
)

Sets the on-screen keyboard visible if available.

public void
setCatchKey(int
keycode to catch
keycode
,
boolean
whether to catch the given keycode
catchKey
)

Sets whether the given key on Android or GWT should be caught.

public void
setCursorCatched(boolean
whether to catch or not to catch the mouse cursor
catched
)

Only viable on the desktop.

public void
setCursorPosition(int
the x-position
x
,
int
the y-position
y
)

Only viable on the desktop.

public void
setInputProcessor(InputProcessor
the InputProcessor
processor
)

Sets the InputProcessor that will receive all touch and key input events.

public void
setKeyboardHeightObserver(Input.KeyboardHeightObserver observer)

This will set a keyboard height callback.

public void
setOnscreenKeyboardVisible(boolean
visible or not
visible
)

Sets the on-screen keyboard visible if available.

public void
setOnscreenKeyboardVisible(boolean
visible or not
visible
,
Input.OnscreenKeyboardType
which type of keyboard we wish to display. Can be null when hiding
type
)

Sets the on-screen keyboard visible if available.

public void
vibrate(int
the number of milliseconds to vibrate.
milliseconds
)

Generates a simple haptic effect of a given duration or a vibration effect on devices without haptic capabilities.

public void
vibrate(int
the duration of the haptics effect
milliseconds
,
boolean
whether to use non-haptic vibrator on devices without haptics capabilities (or haptics disabled). Fallback non-haptic vibrations may ignore length parameter in some backends.
fallback
)

Generates a simple haptic effect of a given duration and default amplitude.

public void
vibrate(int
the duration of the haptics effect
milliseconds
,
int
the amplitude/strength of the haptics effect. Valid values in the range [0, 255].
amplitude
,
boolean
whether to use non-haptic vibrator on devices without haptics capabilities (or haptics disabled). Fallback non-haptic vibrations may ignore length and/or amplitude parameters in some backends.
fallback
)

Generates a simple haptic effect of a given duration and amplitude.

public void
vibrate(Input.VibrationType
the type of vibration
vibrationType
)

Generates a simple haptic effect of a type.