Package arc

Class Input

java.lang.Object
arc.Input
Direct Known Subclasses:
AndroidInput, IOSInput, MockInput, SdlInput

public abstract class Input extends Object

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.

  • Field Details

    • keyboard

      protected KeyboardDevice keyboard
      The default input device (keyboard)
    • devices

      protected Seq<InputDevice> devices
      All available input devices, including controllers and keyboards.
    • inputMultiplexer

      protected InputMultiplexer inputMultiplexer
      An input multiplexer to handle events.
    • caughtKeys

      protected IntSet caughtKeys
      List of caught keys for Android.
    • mouseReturn

      protected Vec2 mouseReturn
      Return Vec2 value for various functions.
    • useKeyboard

      protected boolean useKeyboard
      Whether to use keyboard controls on Android.
  • Constructor Details

    • Input

      public Input()
  • Method Details

    • mouseWorld

      public Vec2 mouseWorld(float x, float y)
      Returns the unprojected mouse position (screen -> world).
    • mouseScreen

      public Vec2 mouseScreen(float x, float y)
      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

      public Vec2 mouseWorld()
      Returns the unprojected mouse position in the world.
    • mouse

      public Vec2 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 with isPeripheralAvailable(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

      public boolean keyDown(KeyCode key)
      Returns whether the key is pressed.
    • keyTap

      public boolean keyTap(KeyCode key)
      Returns whether the key has just been pressed.
    • keyRelease

      public boolean keyRelease(KeyCode key)
      Returns whether the key has just been released.
    • axis

      public float axis(KeyCode key)
      Returns the [-1, 1] axis value of a key.
    • keyDown

      public boolean keyDown(KeyBinds.KeyBind key)
      Returns whether the keybind is pressed.
    • keyTap

      public boolean keyTap(KeyBinds.KeyBind key)
      Returns whether the key has just been pressed.
    • keyRelease

      public boolean keyRelease(KeyBinds.KeyBind key)
      Returns whether the key has just been released.
    • axis

      public float axis(KeyBinds.KeyBind key)
      Returns the [-1, 1] axis value of a key.
    • axisTap

      public float axisTap(KeyBinds.KeyBind key)
      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

      public void getTextInput(Input.TextInput input)
      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

      public Vec3 getAccelerometer()
      Returns:
      The acceleration force in m/s^2 applied to the device, including the force of gravity
    • getGyroscope

      public Vec3 getGyroscope()
      Returns:
      The rate of rotation in rad/s.
    • getOrientation

      public Vec3 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

      public void setCatch(KeyCode code, boolean c)
      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

      public boolean isCatch(KeyCode code)
      Returns:
      whether the back button is currently being caught
    • addProcessor

      public void addProcessor(InputProcessor processor)
      Adds a InputProcessor that will receive all touch and key input events. It will be called before the ApplicationListener.update() method each frame.
      Parameters:
      processor - the InputProcessor
    • removeProcessor

      public void removeProcessor(InputProcessor processor)
      Removes a InputProcessor from the chain.
    • getInputProcessors

      public Seq<InputProcessor> getInputProcessors()
      Returns:
      the currently set InputProcessor or null.
    • getInputMultiplexer

      public InputMultiplexer getInputMultiplexer()
    • getDevices

      public Seq<InputDevice> 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

      public KeyboardDevice getKeyboard()
      Returns the default input device (keyboard).
    • isPeripheralAvailable

      public boolean isPeripheralAvailable(Input.Peripheral peripheral)
      Queries whether a 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.
      Parameters:
      peripheral - the Input.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

      public Input.Orientation getNativeOrientation()
      Returns:
      the native orientation of the device.