Package com.badlogic.gdx.input
Class RemoteInput
- java.lang.Object
-
- com.badlogic.gdx.input.RemoteInput
-
- All Implemented Interfaces:
Input,java.lang.Runnable
public class RemoteInput extends java.lang.Object implements java.lang.Runnable, Input
An
Inputimplementation 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRemoteInput.RemoteInputListener-
Nested classes/interfaces inherited from interface com.badlogic.gdx.Input
Input.Buttons, Input.Keys, Input.OnscreenKeyboardType, Input.Orientation, Input.Peripheral, Input.TextInputListener, Input.VibrationType
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_PORTjava.lang.String[]ips
-
Constructor Summary
Constructors Constructor Description RemoteInput()RemoteInput(int port)RemoteInput(int port, RemoteInput.RemoteInputListener listener)RemoteInput(RemoteInput.RemoteInputListener listener)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description floatgetAccelerometerX()floatgetAccelerometerY()floatgetAccelerometerZ()floatgetAzimuth()The azimuth is the angle of the device's orientation around the z-axis.longgetCurrentEventTime()intgetDeltaX()intgetDeltaX(int pointer)intgetDeltaY()intgetDeltaY(int pointer)floatgetGyroscopeX()floatgetGyroscopeY()floatgetGyroscopeZ()InputProcessorgetInputProcessor()java.lang.String[]getIPs()intgetMaxPointers()Input.OrientationgetNativeOrientation()floatgetPitch()The pitch is the angle of the device's orientation around the x-axis.floatgetPressure()floatgetPressure(int pointer)Returns the pressure of the given pointer, where 0 is untouched.floatgetRoll()The roll is the angle of the device's orientation around the y-axis.intgetRotation()voidgetRotationMatrix(float[] matrix)Returns the rotation matrix describing the devices rotation as per SensorManager#getRotationMatrix(float[], float[], float[], float[]).voidgetTextInput(Input.TextInputListener listener, java.lang.String title, java.lang.String text, java.lang.String hint)System dependent method to input a string of text.voidgetTextInput(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.intgetX()intgetX(int pointer)Returns the x coordinate in screen coordinates of the given pointer.intgetY()intgetY(int pointer)Returns the y coordinate in screen coordinates of the given pointer.booleanisButtonJustPressed(int button)Returns whether a given button has just been pressed.booleanisButtonPressed(int button)Whether a given button is pressed or not.booleanisCatchBackKey()booleanisCatchKey(int keycode)booleanisCatchMenuKey()booleanisConnected()booleanisCursorCatched()booleanisKeyJustPressed(int key)Returns whether the key has just been pressed.booleanisKeyPressed(int key)Returns whether the key is pressed.booleanisPeripheralAvailable(Input.Peripheral peripheral)Queries whether aInput.Peripheralis currently available.booleanisTouched()booleanisTouched(int pointer)Whether the screen is currently touched by the pointer with the given index.booleanjustTouched()voidrun()voidsetCatchBackKey(boolean catchBack)voidsetCatchKey(int keycode, boolean catchKey)Sets whether the given key on Android or GWT should be caught.voidsetCatchMenuKey(boolean catchMenu)voidsetCursorCatched(boolean catched)Only viable on the desktop.voidsetCursorPosition(int x, int y)Only viable on the desktop.voidsetInputProcessor(InputProcessor processor)Sets theInputProcessorthat will receive all touch and key input events.voidsetOnscreenKeyboardVisible(boolean visible)Sets the on-screen keyboard visible if available.voidsetOnscreenKeyboardVisible(boolean visible, Input.OnscreenKeyboardType type)Sets the on-screen keyboard visible if available.voidvibrate(int milliseconds)Generates a simple haptic effect of a given duration or a vibration effect on devices without haptic capabilities.voidvibrate(int milliseconds, boolean fallback)Generates a simple haptic effect of a given duration and default amplitude.voidvibrate(int milliseconds, int amplitude, boolean fallback)Generates a simple haptic effect of a given duration and amplitude.voidvibrate(Input.VibrationType vibrationType)Generates a simple haptic effect of a type.
-
-
-
Constructor Detail
-
RemoteInput
public RemoteInput()
-
RemoteInput
public RemoteInput(RemoteInput.RemoteInputListener listener)
-
RemoteInput
public RemoteInput(int port)
-
RemoteInput
public RemoteInput(int port, RemoteInput.RemoteInputListener listener)
-
-
Method Detail
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
isConnected
public boolean isConnected()
-
getAccelerometerX
public float getAccelerometerX()
- Specified by:
getAccelerometerXin interfaceInput- 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:
getAccelerometerYin interfaceInput- 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:
getAccelerometerZin interfaceInput- 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:
getGyroscopeXin interfaceInput- Returns:
- The rate of rotation in rad/s around the X axis
-
getGyroscopeY
public float getGyroscopeY()
- Specified by:
getGyroscopeYin interfaceInput- Returns:
- The rate of rotation in rad/s around the Y axis
-
getGyroscopeZ
public float getGyroscopeZ()
- Specified by:
getGyroscopeZin interfaceInput- Returns:
- The rate of rotation in rad/s around the Z axis
-
getMaxPointers
public int getMaxPointers()
- Specified by:
getMaxPointersin interfaceInput- Returns:
- The maximum number of pointers supported
-
getX
public int getX()
-
getX
public int getX(int pointer)
Description copied from interface:InputReturns 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.
-
getY
public int getY()
-
getY
public int getY(int pointer)
Description copied from interface:InputReturns 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.
-
isTouched
public boolean isTouched()
-
justTouched
public boolean justTouched()
- Specified by:
justTouchedin interfaceInput- Returns:
- whether a new touch down event just occurred.
-
isTouched
public boolean isTouched(int pointer)
Description copied from interface:InputWhether 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.
-
getPressure
public float getPressure()
- Specified by:
getPressurein interfaceInput- Returns:
- the pressure of the first pointer
-
getPressure
public float getPressure(int pointer)
Description copied from interface:InputReturns 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 withInput.isPeripheralAvailable(Peripheral). If not supported, returns 1.0 when touched.- Specified by:
getPressurein interfaceInput- Parameters:
pointer- the pointer id.- Returns:
- the pressure
-
isButtonPressed
public boolean isButtonPressed(int button)
Description copied from interface:InputWhether a given button is pressed or not. Button constants can be found inInput.Buttons. On Android only the Buttons#LEFT constant is meaningful before version 4.0.- Specified by:
isButtonPressedin interfaceInput- Parameters:
button- the button to check.- Returns:
- whether the button is down or not.
-
isButtonJustPressed
public boolean isButtonJustPressed(int button)
Description copied from interface:InputReturns whether a given button has just been pressed. Button constants can be found inInput.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:
isButtonJustPressedin interfaceInput- Parameters:
button- the button to check.- Returns:
- true or false.
-
isKeyPressed
public boolean isKeyPressed(int key)
Description copied from interface:InputReturns whether the key is pressed.- Specified by:
isKeyPressedin interfaceInput- Parameters:
key- The key code as found inInput.Keys.- Returns:
- true or false.
-
isKeyJustPressed
public boolean isKeyJustPressed(int key)
Description copied from interface:InputReturns whether the key has just been pressed.- Specified by:
isKeyJustPressedin interfaceInput- Parameters:
key- The key code as found inInput.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:InputSystem 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 providedInput.TextInputListenerwill be called on the rendering thread.- Specified by:
getTextInputin interfaceInput- 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:InputSystem 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 providedInput.TextInputListenerwill be called on the rendering thread.- Specified by:
getTextInputin interfaceInput- 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:InputSets the on-screen keyboard visible if available. Will use the Default keyboard type.- Specified by:
setOnscreenKeyboardVisiblein interfaceInput- Parameters:
visible- visible or not
-
setOnscreenKeyboardVisible
public void setOnscreenKeyboardVisible(boolean visible, Input.OnscreenKeyboardType type)Description copied from interface:InputSets the on-screen keyboard visible if available.- Specified by:
setOnscreenKeyboardVisiblein interfaceInput- Parameters:
visible- visible or nottype- which type of keyboard we wish to display. Can be null when hiding
-
vibrate
public void vibrate(int milliseconds)
Description copied from interface:InputGenerates 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 permissionin your manifest file in order for this to work. On iOS backend you'll need to setuseHaptics = truefor devices with haptics capabilities to use them.
-
vibrate
public void vibrate(int milliseconds, boolean fallback)Description copied from interface:InputGenerates a simple haptic effect of a given duration and default amplitude. Note that on Android backend you'll need the permissionin your manifest file in order for this to work. On iOS backend you'll need to setuseHaptics = truefor devices with haptics capabilities to use them.
-
vibrate
public void vibrate(int milliseconds, int amplitude, boolean fallback)Description copied from interface:InputGenerates a simple haptic effect of a given duration and amplitude. Note that on Android backend you'll need the permissionin your manifest file in order for this to work. On iOS backend you'll need to setuseHaptics = truefor devices with haptics capabilities to use them.- Specified by:
vibratein interfaceInput- Parameters:
milliseconds- the duration of the haptics effectamplitude- 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:InputGenerates 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 permissionin your manifest file in order for this to work. On iOS backend you'll need to setuseHaptics = truefor devices with haptics capabilities to use them.
-
getAzimuth
public float getAzimuth()
Description copied from interface:InputThe azimuth is the angle of the device's orientation around the z-axis. The positive z-axis points towards the earths center.- Specified by:
getAzimuthin interfaceInput- Returns:
- the azimuth in degrees
- See Also:
- http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])
-
getPitch
public float getPitch()
Description copied from interface:InputThe pitch is the angle of the device's orientation around the x-axis. The positive x-axis roughly points to the west and is orthogonal to the z- and y-axis.- Specified by:
getPitchin interfaceInput- Returns:
- the pitch in degrees
- See Also:
- http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])
-
getRoll
public float getRoll()
Description copied from interface:InputThe roll is the angle of the device's orientation around the y-axis. The positive y-axis points to the magnetic north pole of the earth.- Specified by:
getRollin interfaceInput- Returns:
- the roll in degrees
- See Also:
- http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])
-
setCatchBackKey
public void setCatchBackKey(boolean catchBack)
- Specified by:
setCatchBackKeyin interfaceInput- Parameters:
catchBack- whether to catch the back button
-
isCatchBackKey
public boolean isCatchBackKey()
- Specified by:
isCatchBackKeyin interfaceInput- Returns:
- whether the back button is currently being caught
-
setCatchMenuKey
public void setCatchMenuKey(boolean catchMenu)
- Specified by:
setCatchMenuKeyin interfaceInput- Parameters:
catchMenu- whether to catch the menu button
-
isCatchMenuKey
public boolean isCatchMenuKey()
- Specified by:
isCatchMenuKeyin interfaceInput- Returns:
- whether the menu button is currently being caught
-
setCatchKey
public void setCatchKey(int keycode, boolean catchKey)Description copied from interface:InputSets 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:
setCatchKeyin interfaceInput- Parameters:
keycode- keycode to catchcatchKey- whether to catch the given keycode
-
isCatchKey
public boolean isCatchKey(int keycode)
- Specified by:
isCatchKeyin interfaceInput- Parameters:
keycode- keycode to check if caught- Returns:
- true if the given keycode is configured to be caught
-
setInputProcessor
public void setInputProcessor(InputProcessor processor)
Description copied from interface:InputSets theInputProcessorthat will receive all touch and key input events. It will be called before theApplicationListener.render()method each frame.- Specified by:
setInputProcessorin interfaceInput- Parameters:
processor- the InputProcessor
-
getInputProcessor
public InputProcessor getInputProcessor()
- Specified by:
getInputProcessorin interfaceInput- Returns:
- the currently set
InputProcessoror null.
-
getIPs
public java.lang.String[] getIPs()
- Returns:
- the IP addresses
RemoteSenderor gdx-remote should connect to. Most likely the LAN addresses if behind a NAT.
-
isPeripheralAvailable
public boolean isPeripheralAvailable(Input.Peripheral peripheral)
Description copied from interface:InputQueries whether aInput.Peripheralis currently available. In case of Android and theInput.Peripheral.HardwareKeyboardthis returns the whether the keyboard is currently slid out or not.- Specified by:
isPeripheralAvailablein interfaceInput- Parameters:
peripheral- theInput.Peripheral- Returns:
- whether the peripheral is available or not.
-
getRotation
public int getRotation()
- Specified by:
getRotationin interfaceInput- Returns:
- the rotation of the device with respect to its native orientation.
-
getNativeOrientation
public Input.Orientation getNativeOrientation()
- Specified by:
getNativeOrientationin interfaceInput- Returns:
- the native orientation of the device.
-
setCursorCatched
public void setCursorCatched(boolean catched)
Description copied from interface:InputOnly 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:
setCursorCatchedin interfaceInput- Parameters:
catched- whether to catch or not to catch the mouse cursor
-
isCursorCatched
public boolean isCursorCatched()
- Specified by:
isCursorCatchedin interfaceInput- Returns:
- whether the mouse cursor is catched.
-
getDeltaX
public int getDeltaX()
-
getDeltaX
public int getDeltaX(int pointer)
-
getDeltaY
public int getDeltaY()
-
getDeltaY
public int getDeltaY(int pointer)
-
setCursorPosition
public void setCursorPosition(int x, int y)Description copied from interface:InputOnly viable on the desktop. Will set the mouse cursor location to the given window coordinates (origin top-left corner).- Specified by:
setCursorPositionin interfaceInput- Parameters:
x- the x-positiony- the y-position
-
getCurrentEventTime
public long getCurrentEventTime()
- Specified by:
getCurrentEventTimein interfaceInput- Returns:
- the time of the event currently reported to the
InputProcessor.
-
getRotationMatrix
public void getRotationMatrix(float[] matrix)
Description copied from interface:InputReturns 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.- Specified by:
getRotationMatrixin interfaceInput
-
-