Class RemoteInput

  • All Implemented Interfaces:
    Input, java.lang.Runnable

    public class RemoteInput
    extends java.lang.Object
    implements java.lang.Runnable, Input

    An Input implementation that receives touch, key, accelerometer and compass events from a remote Android device. Just instantiate it and specify the port it should listen on for incoming connections (default 8190). Then store the new RemoteInput instance in Gdx.input. That's it.

    On your Android device you can use the gdx-remote application available on the Google Code page as an APK or in SVN (extensions/gdx-remote). Open it, specify the IP address and the port of the PC your libGDX app is running on and then tap away.

    The touch coordinates will be translated to the desktop window's coordinate system, no matter the orientation of the device

    • Field Detail

      • DEFAULT_PORT

        public static int DEFAULT_PORT
      • ips

        public final java.lang.String[] ips
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable
      • isConnected

        public boolean isConnected()
      • getAccelerometerX

        public float getAccelerometerX()
        Specified by:
        getAccelerometerX in interface Input
        Returns:
        The acceleration force in m/s^2 applied to the device in the X axis, including the force of gravity
      • getAccelerometerY

        public float getAccelerometerY()
        Specified by:
        getAccelerometerY in interface Input
        Returns:
        The acceleration force in m/s^2 applied to the device in the Y axis, including the force of gravity
      • getAccelerometerZ

        public float getAccelerometerZ()
        Specified by:
        getAccelerometerZ in interface Input
        Returns:
        The acceleration force in m/s^2 applied to the device in the Z axis, including the force of gravity
      • getGyroscopeX

        public float getGyroscopeX()
        Specified by:
        getGyroscopeX in interface Input
        Returns:
        The rate of rotation in rad/s around the X axis
      • getGyroscopeY

        public float getGyroscopeY()
        Specified by:
        getGyroscopeY in interface Input
        Returns:
        The rate of rotation in rad/s around the Y axis
      • getGyroscopeZ

        public float getGyroscopeZ()
        Specified by:
        getGyroscopeZ in interface Input
        Returns:
        The rate of rotation in rad/s around the Z axis
      • getMaxPointers

        public int getMaxPointers()
        Specified by:
        getMaxPointers in interface Input
        Returns:
        The maximum number of pointers supported
      • getX

        public int getX()
        Specified by:
        getX in interface Input
        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.
      • getX

        public int getX​(int pointer)
        Description copied from interface: Input
        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.
        Specified by:
        getX in interface Input
        Parameters:
        pointer - the pointer id.
        Returns:
        the x coordinate
      • getY

        public int getY()
        Specified by:
        getY in interface Input
        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 top left corner.
      • getY

        public int getY​(int pointer)
        Description copied from interface: Input
        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.
        Specified by:
        getY in interface Input
        Parameters:
        pointer - the pointer id.
        Returns:
        the y coordinate
      • isTouched

        public boolean isTouched()
        Specified by:
        isTouched in interface Input
        Returns:
        whether the screen is currently touched.
      • justTouched

        public boolean justTouched()
        Specified by:
        justTouched in interface Input
        Returns:
        whether a new touch down event just occurred.
      • isTouched

        public boolean isTouched​(int pointer)
        Description copied from interface: Input
        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.
        Specified by:
        isTouched in interface Input
        Parameters:
        pointer - the pointer
        Returns:
        whether the screen is touched by the pointer
      • getPressure

        public float getPressure()
        Specified by:
        getPressure in interface Input
        Returns:
        the pressure of the first pointer
      • getPressure

        public float getPressure​(int pointer)
        Description copied from interface: Input
        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 Input.isPeripheralAvailable(Peripheral). If not supported, returns 1.0 when touched.
        Specified by:
        getPressure in interface Input
        Parameters:
        pointer - the pointer id.
        Returns:
        the pressure
      • isButtonPressed

        public boolean isButtonPressed​(int button)
        Description copied from interface: Input
        Whether a given button is pressed or not. Button constants can be found in Input.Buttons. On Android only the Buttons#LEFT constant is meaningful before version 4.0.
        Specified by:
        isButtonPressed in interface Input
        Parameters:
        button - the button to check.
        Returns:
        whether the button is down or not.
      • isButtonJustPressed

        public boolean isButtonJustPressed​(int button)
        Description copied from interface: Input
        Returns whether a given button has just been pressed. Button constants can be found in 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.
        Specified by:
        isButtonJustPressed in interface Input
        Parameters:
        button - the button to check.
        Returns:
        true or false.
      • isKeyPressed

        public boolean isKeyPressed​(int key)
        Description copied from interface: Input
        Returns whether the key is pressed.
        Specified by:
        isKeyPressed in interface Input
        Parameters:
        key - The key code as found in Input.Keys.
        Returns:
        true or false.
      • isKeyJustPressed

        public boolean isKeyJustPressed​(int key)
        Description copied from interface: Input
        Returns whether the key has just been pressed.
        Specified by:
        isKeyJustPressed in interface Input
        Parameters:
        key - The key code as found in Input.Keys.
        Returns:
        true or false.
      • getTextInput

        public void getTextInput​(Input.TextInputListener listener,
                                 java.lang.String title,
                                 java.lang.String text,
                                 java.lang.String hint)
        Description copied from interface: 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. Will use the Default keyboard type. Once the dialog has been closed the provided Input.TextInputListener will be called on the rendering thread.
        Specified by:
        getTextInput in interface Input
        Parameters:
        listener - The TextInputListener.
        title - The title of the text input dialog.
        text - The message presented to the user.
      • getTextInput

        public void getTextInput​(Input.TextInputListener listener,
                                 java.lang.String title,
                                 java.lang.String text,
                                 java.lang.String hint,
                                 Input.OnscreenKeyboardType type)
        Description copied from interface: 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 provided Input.TextInputListener will be called on the rendering thread.
        Specified by:
        getTextInput in interface Input
        Parameters:
        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 display
      • setOnscreenKeyboardVisible

        public void setOnscreenKeyboardVisible​(boolean visible)
        Description copied from interface: Input
        Sets the on-screen keyboard visible if available. Will use the Default keyboard type.
        Specified by:
        setOnscreenKeyboardVisible in interface Input
        Parameters:
        visible - visible or not
      • setOnscreenKeyboardVisible

        public void setOnscreenKeyboardVisible​(boolean visible,
                                               Input.OnscreenKeyboardType type)
        Description copied from interface: Input
        Sets the on-screen keyboard visible if available.
        Specified by:
        setOnscreenKeyboardVisible in interface Input
        Parameters:
        visible - visible or not
        type - which type of keyboard we wish to display. Can be null when hiding
      • vibrate

        public void vibrate​(int milliseconds)
        Description copied from interface: Input
        Generates a simple haptic effect of a given duration or a vibration effect on devices without haptic capabilities. Note that on Android backend you'll need the permission in your manifest file in order for this to work. On iOS backend you'll need to set useHaptics = true for devices with haptics capabilities to use them.
        Specified by:
        vibrate in interface Input
        Parameters:
        milliseconds - the number of milliseconds to vibrate.
      • vibrate

        public void vibrate​(int milliseconds,
                            boolean fallback)
        Description copied from interface: Input
        Generates a simple haptic effect of a given duration and default amplitude. Note that on Android backend you'll need the permission in your manifest file in order for this to work. On iOS backend you'll need to set useHaptics = true for devices with haptics capabilities to use them.
        Specified by:
        vibrate in interface Input
        Parameters:
        milliseconds - the duration of the haptics effect
        fallback - 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.
      • vibrate

        public void vibrate​(int milliseconds,
                            int amplitude,
                            boolean fallback)
        Description copied from interface: Input
        Generates a simple haptic effect of a given duration and amplitude. Note that on Android backend you'll need the permission in your manifest file in order for this to work. On iOS backend you'll need to set useHaptics = true for devices with haptics capabilities to use them.
        Specified by:
        vibrate in interface Input
        Parameters:
        milliseconds - the duration of the haptics effect
        amplitude - the amplitude/strength of the haptics effect. Valid values in the range [0, 255].
        fallback - 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.
      • vibrate

        public void vibrate​(Input.VibrationType vibrationType)
        Description copied from interface: Input
        Generates a simple haptic effect of a type. VibrationTypes are length/amplitude haptic effect presets that depend on each device and are defined by manufacturers. Should give most consistent results across devices and OSs. Note that on Android backend you'll need the permission in your manifest file in order for this to work. On iOS backend you'll need to set useHaptics = true for devices with haptics capabilities to use them.
        Specified by:
        vibrate in interface Input
        Parameters:
        vibrationType - the type of vibration
      • setCatchBackKey

        public void setCatchBackKey​(boolean catchBack)
        Specified by:
        setCatchBackKey in interface Input
        Parameters:
        catchBack - whether to catch the back button
      • isCatchBackKey

        public boolean isCatchBackKey()
        Specified by:
        isCatchBackKey in interface Input
        Returns:
        whether the back button is currently being caught
      • setCatchMenuKey

        public void setCatchMenuKey​(boolean catchMenu)
        Specified by:
        setCatchMenuKey in interface Input
        Parameters:
        catchMenu - whether to catch the menu button
      • isCatchMenuKey

        public boolean isCatchMenuKey()
        Specified by:
        isCatchMenuKey in interface Input
        Returns:
        whether the menu button is currently being caught
      • setCatchKey

        public void setCatchKey​(int keycode,
                                boolean catchKey)
        Description copied from interface: Input
        Sets whether the given key on Android or GWT should be caught. No effect on other platforms. All keys that are not caught may be handled by other apps or background processes on Android, or may trigger default browser behaviour on GWT. For example, media or volume buttons are handled by background media players if present, or Space key triggers a scroll. All keys you need to control your game should be caught to prevent unintended behaviour.
        Specified by:
        setCatchKey in interface Input
        Parameters:
        keycode - keycode to catch
        catchKey - whether to catch the given keycode
      • isCatchKey

        public boolean isCatchKey​(int keycode)
        Specified by:
        isCatchKey in interface Input
        Parameters:
        keycode - keycode to check if caught
        Returns:
        true if the given keycode is configured to be caught
      • getIPs

        public java.lang.String[] getIPs()
        Returns:
        the IP addresses RemoteSender or gdx-remote should connect to. Most likely the LAN addresses if behind a NAT.
      • getRotation

        public int getRotation()
        Specified by:
        getRotation in interface Input
        Returns:
        the rotation of the device with respect to its native orientation.
      • setCursorCatched

        public void setCursorCatched​(boolean catched)
        Description copied from interface: Input
        Only viable on the desktop. Will confine the mouse cursor location to the window and hide the mouse cursor. X and y coordinates are still reported as if the mouse was not catched.
        Specified by:
        setCursorCatched in interface Input
        Parameters:
        catched - whether to catch or not to catch the mouse cursor
      • isCursorCatched

        public boolean isCursorCatched()
        Specified by:
        isCursorCatched in interface Input
        Returns:
        whether the mouse cursor is catched.
      • getDeltaX

        public int getDeltaX()
        Specified by:
        getDeltaX in interface Input
        Returns:
        the different between the current pointer location and the last pointer location on the x-axis.
      • getDeltaX

        public int getDeltaX​(int pointer)
        Specified by:
        getDeltaX in interface Input
        Returns:
        the different between the current pointer location and the last pointer location on the x-axis.
      • getDeltaY

        public int getDeltaY()
        Specified by:
        getDeltaY in interface Input
        Returns:
        the different between the current pointer location and the last pointer location on the y-axis.
      • getDeltaY

        public int getDeltaY​(int pointer)
        Specified by:
        getDeltaY in interface Input
        Returns:
        the different between the current pointer location and the last pointer location on the y-axis.
      • setCursorPosition

        public void setCursorPosition​(int x,
                                      int y)
        Description copied from interface: Input
        Only viable on the desktop. Will set the mouse cursor location to the given window coordinates (origin top-left corner).
        Specified by:
        setCursorPosition in interface Input
        Parameters:
        x - the x-position
        y - the y-position