public interface Input
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 Input.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.
Modifier and Type | Interface and Description |
---|---|
static class |
Input.Buttons
Mouse buttons.
|
static class |
Input.Keys
Keys.
|
static class |
Input.OnscreenKeyboardType |
static class |
Input.Orientation |
static class |
Input.Peripheral
Enumeration of potentially available peripherals.
|
static interface |
Input.TextInputListener
Callback interface for
getTextInput(TextInputListener, String, String, String) |
Modifier and Type | Method and Description |
---|---|
void |
cancelVibrate()
Stops the vibrator
|
float |
getAccelerometerX() |
float |
getAccelerometerY() |
float |
getAccelerometerZ() |
float |
getAzimuth()
The azimuth is the angle of the device's orientation around the z-axis.
|
long |
getCurrentEventTime() |
int |
getDeltaX() |
int |
getDeltaX(int pointer) |
int |
getDeltaY() |
int |
getDeltaY(int pointer) |
float |
getGyroscopeX() |
float |
getGyroscopeY() |
float |
getGyroscopeZ() |
InputProcessor |
getInputProcessor() |
int |
getMaxPointers() |
Input.Orientation |
getNativeOrientation() |
float |
getPitch()
The pitch is the angle of the device's orientation around the x-axis.
|
float |
getPressure() |
float |
getPressure(int pointer)
Returns the pressure of the given pointer, where 0 is untouched.
|
float |
getRoll()
The roll is the angle of the device's orientation around the y-axis.
|
int |
getRotation() |
void |
getRotationMatrix(float[] matrix)
Returns the rotation matrix describing the devices rotation as per
SensorManager#getRotationMatrix(float[], float[], float[], float[]).
|
void |
getTextInput(Input.TextInputListener listener,
java.lang.String title,
java.lang.String text,
java.lang.String hint)
System dependent method to input a string of text.
|
void |
getTextInput(Input.TextInputListener listener,
java.lang.String title,
java.lang.String text,
java.lang.String hint,
Input.OnscreenKeyboardType type)
System dependent method to input a string of text.
|
int |
getX() |
int |
getX(int pointer)
Returns the x coordinate in screen coordinates of the given pointer.
|
int |
getY() |
int |
getY(int pointer)
Returns the y coordinate in screen coordinates of the given pointer.
|
boolean |
isButtonJustPressed(int button)
Returns whether a given button has just been pressed.
|
boolean |
isButtonPressed(int button)
Whether a given button is pressed or not.
|
boolean |
isCatchBackKey()
Deprecated.
use
isCatchKey(int keycode) instead |
boolean |
isCatchKey(int keycode) |
boolean |
isCatchMenuKey()
Deprecated.
use
isCatchKey(int keycode) instead |
boolean |
isCursorCatched() |
boolean |
isKeyJustPressed(int key)
Returns whether the key has just been pressed.
|
boolean |
isKeyPressed(int key)
Returns whether the key is pressed.
|
boolean |
isPeripheralAvailable(Input.Peripheral peripheral)
Queries whether a
Input.Peripheral is currently available. |
boolean |
isTouched() |
boolean |
isTouched(int pointer)
Whether the screen is currently touched by the pointer with the given index.
|
boolean |
justTouched() |
void |
setCatchBackKey(boolean catchBack)
Deprecated.
use
setCatchKey(int keycode, boolean catchKey) instead
Sets whether the BACK button on Android should be caught. This will prevent the app from being paused. Will have
no effect on the desktop. |
void |
setCatchKey(int keycode,
boolean catchKey)
Sets whether the given key on Android or GWT should be caught.
|
void |
setCatchMenuKey(boolean catchMenu)
Deprecated.
use
setCatchKey(int keycode, boolean catchKey) instead
Sets whether the MENU button on Android should be caught. This will prevent the onscreen keyboard to show up.
Will have no effect on the desktop. |
void |
setCursorCatched(boolean catched)
Only viable on the desktop.
|
void |
setCursorPosition(int x,
int y)
Only viable on the desktop.
|
void |
setInputProcessor(InputProcessor processor)
Sets the
InputProcessor that will receive all touch and key input events. |
void |
setOnscreenKeyboardVisible(boolean visible)
Sets the on-screen keyboard visible if available.
|
void |
setOnscreenKeyboardVisible(boolean visible,
Input.OnscreenKeyboardType type)
Sets the on-screen keyboard visible if available.
|
void |
vibrate(int milliseconds)
Vibrates for the given amount of time.
|
void |
vibrate(long[] pattern,
int repeat)
Vibrate with a given pattern.
|
float getAccelerometerX()
float getAccelerometerY()
float getAccelerometerZ()
float getGyroscopeX()
float getGyroscopeY()
float getGyroscopeZ()
int getMaxPointers()
int getX()
int getX(int pointer)
pointer
- the pointer id.int getDeltaX()
int getDeltaX(int pointer)
int getY()
int getY(int pointer)
pointer
- the pointer id.int getDeltaY()
int getDeltaY(int pointer)
boolean isTouched()
boolean justTouched()
boolean isTouched(int pointer)
pointer
- the pointerfloat getPressure()
float getPressure(int pointer)
isPeripheralAvailable(Peripheral)
. If not supported, returns 1.0 when touched.pointer
- the pointer id.boolean isButtonPressed(int button)
Input.Buttons
. On Android only the
Buttons#LEFT constant is meaningful before version 4.0.button
- the button to check.boolean isButtonJustPressed(int button)
Input.Buttons
. On Android only the
Buttons#LEFT constant is meaningful before version 4.0. On WebGL (GWT), only LEFT, RIGHT and MIDDLE buttons are supported.button
- the button to check.boolean isKeyPressed(int key)
key
- The key code as found in Input.Keys
.boolean isKeyJustPressed(int key)
key
- The key code as found in Input.Keys
.void getTextInput(Input.TextInputListener listener, java.lang.String title, java.lang.String text, java.lang.String hint)
Input.TextInputListener
will be called on the rendering thread.listener
- The TextInputListener.title
- The title of the text input dialog.text
- The message presented to the user.void getTextInput(Input.TextInputListener listener, java.lang.String title, java.lang.String text, java.lang.String hint, Input.OnscreenKeyboardType type)
Input.TextInputListener
will be called on the
rendering thread.listener
- The TextInputListener.title
- The title of the text input dialog.text
- The message presented to the user.type
- which type of keyboard we wish to displayvoid setOnscreenKeyboardVisible(boolean visible)
visible
- visible or notvoid setOnscreenKeyboardVisible(boolean visible, Input.OnscreenKeyboardType type)
visible
- visible or nottype
- which type of keyboard we wish to display. Can be null when hidingvoid vibrate(int milliseconds)
in your manifest file in order for this to work.milliseconds
- the number of milliseconds to vibrate.void vibrate(long[] pattern, int repeat)
pattern
- an array of longs of times to turn the vibrator on or off.repeat
- the index into pattern at which to repeat, or -1 if you don't want to repeat.void cancelVibrate()
float getAzimuth()
float getPitch()
float getRoll()
void getRotationMatrix(float[] matrix)
matrix
- long getCurrentEventTime()
InputProcessor
.@Deprecated void setCatchBackKey(boolean catchBack)
setCatchKey(int keycode, boolean catchKey)
instead
Sets whether the BACK button on Android should be caught. This will prevent the app from being paused. Will have
no effect on the desktop.catchBack
- whether to catch the back button@Deprecated boolean isCatchBackKey()
isCatchKey(int keycode)
instead@Deprecated void setCatchMenuKey(boolean catchMenu)
setCatchKey(int keycode, boolean catchKey)
instead
Sets whether the MENU button on Android should be caught. This will prevent the onscreen keyboard to show up.
Will have no effect on the desktop.catchMenu
- whether to catch the menu button@Deprecated boolean isCatchMenuKey()
isCatchKey(int keycode)
insteadvoid setCatchKey(int keycode, boolean catchKey)
keycode
- keycode to catchcatchKey
- whether to catch the given keycodeboolean isCatchKey(int keycode)
keycode
- keycode to check if caughtvoid setInputProcessor(InputProcessor processor)
InputProcessor
that will receive all touch and key input events. It will be called before the
ApplicationListener.render()
method each frame.processor
- the InputProcessorInputProcessor getInputProcessor()
InputProcessor
or null.boolean isPeripheralAvailable(Input.Peripheral peripheral)
Input.Peripheral
is currently available. In case of Android and the Input.Peripheral.HardwareKeyboard
this returns the whether the keyboard is currently slid out or not.peripheral
- the Input.Peripheral
int getRotation()
Input.Orientation getNativeOrientation()
void setCursorCatched(boolean catched)
catched
- whether to catch or not to catch the mouse cursorboolean isCursorCatched()
void setCursorPosition(int x, int y)
x
- the x-positiony
- the y-position