Package arc
Class Input
java.lang.Object
arc.Input
- Direct Known Subclasses:
AndroidInput
,IOSInput
,MockInput
,SdlInput
Interface to the input facilities. This allows polling the state of the keyboard, the touch screen and the accelerometer. On some backends (desktop) the touch screen is replaced by mouse input. The accelerometer is of course not available on all backends.
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
Enumeration of potentially available peripherals.static class
Parameters for text input. -
Field Summary
Modifier and TypeFieldDescriptionprotected IntSet
List of caught keys for Android.protected Seq<InputDevice>
All available input devices, including controllers and keyboards.protected InputMultiplexer
An input multiplexer to handle events.protected KeyboardDevice
The default input device (keyboard)protected Vec2
Return Vec2 value for various functions.protected boolean
Whether to use keyboard controls on Android. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addProcessor
(InputProcessor processor) Adds aInputProcessor
that will receive all touch and key input events.boolean
alt()
Returns whether one of the two alt keys is pressed.float
Returns the [-1, 1] axis value of a key.float
axis
(KeyBinds.KeyBind key) Returns the [-1, 1] axis value of a key.float
axisTap
(KeyBinds.KeyBind key) Returns the [-1, 1] axis value of a key.void
Stops the vibratorboolean
ctrl()
Returns whether one of the two control keys is currently pressed - or, on Macs, the cmd key.abstract int
deltaX()
abstract int
deltaX
(int pointer) abstract int
deltaY()
abstract int
deltaY
(int pointer) abstract long
Returns a list of input devices, such as keyboards or controllers.Returns the default input device (keyboard).float
float
getPressure
(int pointer) Returns the pressure of the given pointer, where 0 is untouched.int
void
getRotationMatrix
(float[] matrix) Returns the rotation matrix describing the devices rotation as per SensorManager#getRotationMatrix(float[], float[], float[], float[]).void
getTextInput
(Input.TextInput input) System dependent method to input a string of text.int
boolean
boolean
isPeripheralAvailable
(Input.Peripheral peripheral) Queries whether aInput.Peripheral
is currently available.abstract boolean
abstract boolean
isTouched
(int pointer) Whether the screen is currently touched by the pointer with the given index.abstract boolean
boolean
Returns whether the key is pressed.boolean
keyDown
(KeyBinds.KeyBind key) Returns whether the keybind is pressed.boolean
keyRelease
(KeyCode key) Returns whether the key has just been released.boolean
Returns whether the key has just been released.boolean
Returns whether the key has just been pressed.boolean
keyTap
(KeyBinds.KeyBind key) Returns whether the key has just been pressed.mouse()
Returns the mouse position as a Vec2.mouseScreen
(float x, float y) Returns the projected mouse position (world -> screen).Returns the unprojected mouse position in the world.mouseWorld
(float x, float y) Returns the unprojected mouse position (screen -> world).float
float
abstract int
mouseX()
abstract int
mouseX
(int pointer) Returns the x coordinate in screen coordinates of the given pointer.abstract int
mouseY()
abstract int
mouseY
(int pointer) Returns the y coordinate in screen coordinates of the given pointer.void
removeProcessor
(InputProcessor processor) Removes aInputProcessor
from the chain.void
Sets whether the specified button on Android should be caught.void
setOnscreenKeyboardVisible
(boolean visible) Sets the on-screen keyboard visible if available.void
setUseKeyboard
(boolean useKeyboard) boolean
shift()
Returns whether one of the two shift keys is currently pressed.boolean
void
vibrate
(int milliseconds) Vibrates for the given amount of time.void
vibrate
(long[] pattern, int repeat) Vibrate with a given pattern.
-
Field Details
-
keyboard
The default input device (keyboard) -
devices
All available input devices, including controllers and keyboards. -
inputMultiplexer
An input multiplexer to handle events. -
caughtKeys
List of caught keys for Android. -
mouseReturn
Return Vec2 value for various functions. -
useKeyboard
protected boolean useKeyboardWhether to use keyboard controls on Android.
-
-
Constructor Details
-
Input
public Input()
-
-
Method Details
-
mouseWorld
Returns the unprojected mouse position (screen -> world). -
mouseScreen
Returns the projected mouse position (world -> screen). -
mouseWorldX
public float mouseWorldX()- Returns:
- the unprojected mouse position in the world.
-
mouseWorldY
public float mouseWorldY()- Returns:
- the unprojected mouse position in the world.
-
mouseWorld
Returns the unprojected mouse position in the world. -
mouse
Returns the mouse position as a Vec2. -
setUseKeyboard
public void setUseKeyboard(boolean useKeyboard) -
useKeyboard
public boolean useKeyboard()- Returns:
- whether the keyboard should be preferred for mobile devices - used in text fields.
-
mouseX
public abstract int mouseX()- 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. The screen origin is the top left corner.
-
mouseX
public abstract int mouseX(int pointer) Returns the x coordinate in screen coordinates of the given pointer. Pointers are indexed from 0 to n. The pointer id identifies the order in which the fingers went down on the screen, e.g. 0 is the first finger, 1 is the second and so on. When two fingers are touched down and the first one is lifted the second one keeps its index. If another finger is placed on the touch screen the first free index will be used.- Parameters:
pointer
- the pointer id.- Returns:
- the x coordinate
-
deltaX
public abstract int deltaX()- Returns:
- the different between the current pointer location and the last pointer location on the x-axis.
-
deltaX
public abstract int deltaX(int pointer) - Returns:
- the different between the current pointer location and the last pointer location on the x-axis.
-
mouseY
public abstract int mouseY()- 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. The screen origin is the bottom left corner.
-
mouseY
public abstract int mouseY(int pointer) Returns the y coordinate in screen coordinates of the given pointer. Pointers are indexed from 0 to n. The pointer id identifies the order in which the fingers went down on the screen, e.g. 0 is the first finger, 1 is the second and so on. When two fingers are touched down and the first one is lifted the second one keeps its index. If another finger is placed on the touch screen the first free index will be used.- Parameters:
pointer
- the pointer id.- Returns:
- the y coordinate
-
deltaY
public abstract int deltaY()- Returns:
- the different between the current pointer location and the last pointer location on the y-axis.
-
deltaY
public abstract int deltaY(int pointer) - Returns:
- the different between the current pointer location and the last pointer location on the y-axis.
-
isTouched
public abstract boolean isTouched()- Returns:
- whether the screen is currently touched.
-
justTouched
public abstract boolean justTouched()- Returns:
- whether a new touch down event just occurred.
-
getTouches
public int getTouches() -
isTouched
public abstract boolean isTouched(int pointer) Whether the screen is currently touched by the pointer with the given index. Pointers are indexed from 0 to n. The pointer id identifies the order in which the fingers went down on the screen, e.g. 0 is the first finger, 1 is the second and so on. When two fingers are touched down and the first one is lifted the second one keeps its index. If another finger is placed on the touch screen the first free index will be used.- Parameters:
pointer
- the pointer- Returns:
- whether the screen is touched by the pointer
-
getPressure
public float getPressure()- Returns:
- the pressure of the first pointer
-
getPressure
public float getPressure(int pointer) Returns the pressure of the given pointer, where 0 is untouched. On Android it should be up to 1.0, but it can go above that slightly and its not consistent between devices. On iOS 1.0 is the normal touch and significantly more of hard touch. Check relevant manufacturer documentation for details. Check availability withisPeripheralAvailable(Peripheral)
. If not supported, returns 1.0 when touched.- Parameters:
pointer
- the pointer id.- Returns:
- the pressure
-
shift
public boolean shift()Returns whether one of the two shift keys is currently pressed. -
ctrl
public boolean ctrl()Returns whether one of the two control keys is currently pressed - or, on Macs, the cmd key. -
alt
public boolean alt()Returns whether one of the two alt keys is pressed. -
keyDown
Returns whether the key is pressed. -
keyTap
Returns whether the key has just been pressed. -
keyRelease
Returns whether the key has just been released. -
axis
Returns the [-1, 1] axis value of a key. -
keyDown
Returns whether the keybind is pressed. -
keyTap
Returns whether the key has just been pressed. -
keyRelease
Returns whether the key has just been released. -
axis
Returns the [-1, 1] axis value of a key. -
axisTap
Returns the [-1, 1] axis value of a key. In the case of keyboard-based axes, this will only return a value if one of the axes was just pressed. -
getTextInput
System dependent method to input a string of text. A dialog box will be created with the given title and the given text as a message for the user. Once the dialog has been closed the consumer be called on the rendering thread. -
setOnscreenKeyboardVisible
public void setOnscreenKeyboardVisible(boolean visible) Sets the on-screen keyboard visible if available. Only applicable on mobile.- Parameters:
visible
- visible or not
-
vibrate
public void vibrate(int milliseconds) Vibrates for the given amount of time. Note that you'll need the permission<uses-permission android:name="android.permission.VIBRATE" />
in your manifest file in order for this to work.- Parameters:
milliseconds
- the number of milliseconds to vibrate.
-
vibrate
public void vibrate(long[] pattern, int repeat) Vibrate with a given pattern. Pass in an array of ints that are the times at which to turn on or off the vibrator. The first one is how long to wait before turning it on, and then after that it alternates. If you want to repeat, pass the index into the pattern at which to start the repeat.- Parameters:
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.
-
cancelVibrate
public void cancelVibrate()Stops the vibrator -
getAccelerometer
- Returns:
- The acceleration force in m/s^2 applied to the device, including the force of gravity
-
getGyroscope
- Returns:
- The rate of rotation in rad/s.
-
getOrientation
- Returns:
- the device's orientation in degrees in the format (pitch, roll, azimuth) corresponding to x,y,z.
-
getRotationMatrix
public void getRotationMatrix(float[] matrix) Returns the rotation matrix describing the devices rotation as per SensorManager#getRotationMatrix(float[], float[], float[], float[]). Does not manipulate the matrix if the platform does not have an accelerometer. -
getCurrentEventTime
public abstract long getCurrentEventTime()- Returns:
- the time of the event currently reported to the
InputProcessor
.
-
setCatch
Sets whether the specified button on Android should be caught. This will prevent the app from processing the key. Will have no effect on the desktop.- Parameters:
c
- whether to catch the button
-
isCatch
- Returns:
- whether the back button is currently being caught
-
addProcessor
Adds aInputProcessor
that will receive all touch and key input events. It will be called before theApplicationListener.update()
method each frame.- Parameters:
processor
- the InputProcessor
-
removeProcessor
Removes aInputProcessor
from the chain. -
getInputProcessors
- Returns:
- the currently set
InputProcessor
or null.
-
getInputMultiplexer
-
getDevices
Returns a list of input devices, such as keyboards or controllers. This list always contains a keyboard device, regardless of whether one is connected or not (on Android). -
getKeyboard
Returns the default input device (keyboard). -
isPeripheralAvailable
Queries whether aInput.Peripheral
is currently available. In case of Android and theInput.Peripheral.hardwareKeyboard
this returns the whether the keyboard is currently slid out or not.- Parameters:
peripheral
- theInput.Peripheral
- Returns:
- whether the peripheral is available or not.
-
getRotation
public int getRotation()- Returns:
- the rotation of the device with respect to its native orientation.
-
getNativeOrientation
- Returns:
- the native orientation of the device.
-