Input for Android devices
Understand how to detect and handle user input on different types of Android devices.
Read time 5 minutesLast updated 5 days ago
Mobile devices are the primary target for Android applications. Unity provides an Input System package to handle user input on Android devices. This input solution is enabled by default for new projects.
The Input System package supports a variety of input devices on the Android platform, including mouse, keyboard, pen, touchscreen, sensors, joystick, and gamepads. For more information, refer to Supported input devices in the Input System package documentation.
For additional input features on Android, refer to the following sections:
On-screen keyboard support
Android devices automatically display an on-screen touchscreen keyboard when users select editable UI elements, such as Input Fields created using UGUI, or TextField controls created using UI Toolkit, or IMGUI. Unity automatically activates the Android keyboard and handles input from it. If you want to manually activate and configure the Android touchscreen keyboard behavior, refer to Mobile Keyboard.
Gamepad and rumble support
Unity provides gamepad support allowing users to use physical controllers when playing your Android games. You can configure the level of gamepad support in the Android Player settings > Other Settings > Configuration > Android Gamepad Support Level. To handle gamepad input, use the Input System package APIs.
Unity also supports rumble with gamepad controllers on Android devices, allowing controller vibration in response to in-game events and improving the overall gameplay experience. To implement rumble support, use the Input System package APIs.
Notes:
- Rumble support varies depending on the Android OS version.
- The Input System package APIs support rumble with gamepad controllers. If you want to trigger vibration of the Android device itself, use the API.
Handheld.Vibrate
Mouse and touchpad input
Some Android devices convert mouse and touchpad input into touchscreen input, so that applications designed for touchscreens work with a mouse. ChromeOS and Googlebook devices, and Google Play Games on PC perform this conversion for applications that don't declare the feature in the Android App Manifest. Googlebook devices perform this conversion only for applications with App Category set to Game. Phones and tablets don't convert mouse and touchpad input.
android.hardware.type.pcYou can configure Unity to convert mouse and touchpad input into touchscreen input on all Android devices, or disable the conversion. To specify whether the target device, Unity, or neither converts the input, use Android Player settings > Other Settings > Android Application Configuration > Input Emulation, or the API.
PlayerSettings.Android.inputEmulationThe following table describes the Input Emulation options and their effects on the manifest and target devices:
Option | Manifest | Phones and tablets | ChromeOS devices, Googlebook devices, and Google Play Games on PC |
|---|---|---|---|
| Platform (default) | Unchanged | Mouse and touchpad input | The device converts the input into touch input. Googlebook devices convert input only for applications with App Category set to Game. |
| Engine | Declares | Unity converts the input into touch input | Unity converts the input into touch input |
| None | Declares | Mouse and touchpad input | Mouse and touchpad input |
Unity declares as not required, so Google Play still lists your application on devices without that feature.
android.hardware.type.pcUse Engine if your application expects touch input on every Android device. Engine requires Active Input Handling set to Input System Package (New). If Active Input Handling is Input Manager (Old) or Both, the Engine option is unavailable. If you select Engine before you change Active Input Handling, Unity displays a warning when you build and doesn't convert mouse and touchpad input into touch input.
With Engine, Unity adds a touchscreen device to the Input System and converts the following input to touch input on that device:
- Left mouse button presses
- Touchpad clicks and drags
- Two-finger touchpad scrolls, on Android 14 and later
The right and middle mouse buttons, the scroll wheel, and the pointer position when no button is pressed remain mouse input.
If you press more than one mouse button, the button that you press first determines whether Unity converts the press into a touch input:
- If you press the left mouse button first, Unity converts the press into a touch and ignores any other buttons that you press.
- If you press any other button first, the press remains mouse input, even if you then press the left mouse button.
When you set the Input Emulation to Engine, the following behaviors apply:
- On Android 14 and later, a two-finger scroll on a touchpad becomes a touch that starts at the mouse pointer and follows the fingers, while the pointer itself doesn't move. UI elements that the touch passes over can react to it, for example by highlighting. The touch can move outside the application's window. Unity doesn't convert a two-finger pinch on a touchpad into touch input.
- While Unity converts a mouse button press or touchpad gesture to touch input, the mouse position () doesn't change. After the touch ends, the mouse position updates the next time the mouse moves or on some devices the mouse position updates immediately.
Mouse.position - Unity cancels a touch from the mouse when the application loses focus or pauses, or when you lock the cursor with . If the mouse disconnects during a press, Unity cancels the touch. On some devices, the touch ends as a release.
Cursor.lockState - Android can cancel a touch from one device when another device presses or releases, for example a finger on the touchscreen while the user holds a mouse button. The touch that Android cancels depends on the device.
When Unity or the device converts mouse input to touch input, your application receives presses that start with the left mouse button as touches. adds touch inputs only for mouse input that Unity or the device doesn't convert, such as the right and middle mouse buttons.
EnhancedTouch.TouchSimulationUse None if your application uses the mouse to control the UI or gameplay. When you select this option, neither Unity nor the target device converts mouse and touchpad input into touch input.