Google is committed to advancing racial equity for Black communities. See how.
Added in API level 9

InputDevice

class InputDevice : Parcelable
kotlin.Any
   ↳ android.view.InputDevice

Describes the capabilities of a particular input device.

Each input device may support multiple classes of input. For example, a multi-function keyboard may compose the capabilities of a standard keyboard together with a track pad mouse or other pointing device.

Some input devices present multiple distinguishable sources of input. Applications can query the framework about the characteristics of each distinct source.

As a further wrinkle, different kinds of input sources uses different coordinate systems to describe motion events. Refer to the comments on the input source constants for the appropriate interpretation.

Summary

Nested classes

Provides information about the range of values for a particular MotionEvent axis.

Constants
static Int

The keyboard supports a complement of alphabetic keys.

static Int

There is no keyboard.

static Int

The keyboard is not fully alphabetic.

static Int

Constant for retrieving the range of values for MotionEvent#AXIS_ORIENTATION.

static Int

Constant for retrieving the range of values for MotionEvent#AXIS_PRESSURE.

static Int

Constant for retrieving the range of values for MotionEvent#AXIS_SIZE.

static Int

Constant for retrieving the range of values for MotionEvent#AXIS_TOOL_MAJOR.

static Int

Constant for retrieving the range of values for MotionEvent#AXIS_TOOL_MINOR.

static Int

Constant for retrieving the range of values for MotionEvent#AXIS_TOUCH_MAJOR.

static Int

Constant for retrieving the range of values for MotionEvent#AXIS_TOUCH_MINOR.

static Int

Constant for retrieving the range of values for MotionEvent#AXIS_X.

static Int

Constant for retrieving the range of values for MotionEvent#AXIS_Y.

static Int

A special input source constant that is used when filtering input devices to match devices that provide any type of input source.

static Int

The input device is a Bluetooth stylus.

static Int

The input source has buttons or keys.

static Int

The input source is a joystick.

static Int

A mask for input source classes.

static Int

The input source has no class.

static Int

The input source is a pointing device associated with a display.

static Int

The input source is an absolute positioning device not associated with a display (unlike SOURCE_CLASS_POINTER).

static Int

The input source is a trackball navigation device.

static Int

The input source is a DPad.

static Int

The input source is a game pad.

static Int

The input source is a device connected through HDMI-based bus.

static Int

The input source is a joystick.

static Int

The input source is a keyboard.

static Int

The input source is a mouse pointing device.

static Int

The input source is a mouse device whose relative motions should be interpreted as navigation events.

static Int

The input source is a rotating encoder device whose motions should be interpreted as akin to those of a scroll wheel.

static Int

The input source is a stylus pointing device.

static Int

The input source is a touch pad or digitizer tablet that is not associated with a display (unlike SOURCE_TOUCHSCREEN).

static Int

The input source is a touch screen pointing device.

static Int

The input source is a touch device whose motions should be interpreted as navigation events.

static Int

The input source is a trackball.

static Int

The input source is unknown.

Inherited constants
Public methods
Int

Int

The controller number for a given input device.

String!

Gets the input device descriptor, which is a stable identifier for an input device.

static InputDevice!

Gets information about the input device with the specified id.

static IntArray!

Gets the ids of all input devices in the system.

Int

Gets the input device id.

KeyCharacterMap!

Gets the key character map associated with this input device.

Int

Gets the keyboard type.

InputDevice.MotionRange!

Gets information about the range of values for a particular MotionEvent axis.

InputDevice.MotionRange!
getMotionRange(axis: Int, source: Int)

Gets information about the range of values for a particular MotionEvent axis used by a particular source on the device.

MutableList<InputDevice.MotionRange!>!

Gets the ranges for all axes supported by the device.

String!

Gets the name of this input device.

Int

Gets the product id for the given device, if available.

Int

Gets the input sources supported by this input device as a combined bitfield.

Int

Gets the vendor id for the given device, if available.

Vibrator!

Gets the vibrator service associated with the device, if there is one.

BooleanArray!
hasKeys(vararg keys: Int)

Gets whether the device is capable of producing the list of keycodes.

Boolean

Reports whether the device has a built-in microphone.

Boolean

Returns true if input device is enabled.

Boolean

Returns true if the device is external (connected to USB or Bluetooth or some other peripheral bus), otherwise it is built-in.

Boolean

Returns true if the device is a virtual input device rather than a real one, such as the virtual keyboard (see KeyCharacterMap#VIRTUAL_KEYBOARD).

Boolean

Determines whether the input device supports the given source or sources.

String

Unit
writeToParcel(out: Parcel!, flags: Int)

Properties
static Parcelable.Creator<InputDevice!>

Constants

KEYBOARD_TYPE_ALPHABETIC

Added in API level 9
static val KEYBOARD_TYPE_ALPHABETIC: Int

The keyboard supports a complement of alphabetic keys.

Value: 2

KEYBOARD_TYPE_NONE

Added in API level 9
static val KEYBOARD_TYPE_NONE: Int

There is no keyboard.

Value: 0

KEYBOARD_TYPE_NON_ALPHABETIC

Added in API level 9
static val KEYBOARD_TYPE_NON_ALPHABETIC: Int

The keyboard is not fully alphabetic. It may be a numeric keypad or an assortment of buttons that are not mapped as alphabetic keys suitable for text input.

Value: 1

MOTION_RANGE_ORIENTATION

Added in API level 9
Deprecated in API level 15
static val MOTION_RANGE_ORIENTATION: Int

Deprecated: Use MotionEvent#AXIS_ORIENTATION instead.

Constant for retrieving the range of values for MotionEvent#AXIS_ORIENTATION.

Value: 8

See Also

MOTION_RANGE_PRESSURE

Added in API level 9
Deprecated in API level 15
static val MOTION_RANGE_PRESSURE: Int

Deprecated: Use MotionEvent#AXIS_PRESSURE instead.

Constant for retrieving the range of values for MotionEvent#AXIS_PRESSURE.

Value: 2

See Also

MOTION_RANGE_SIZE

Added in API level 9
Deprecated in API level 15
static val MOTION_RANGE_SIZE: Int

Deprecated: Use MotionEvent#AXIS_SIZE instead.

Constant for retrieving the range of values for MotionEvent#AXIS_SIZE.

Value: 3

See Also

MOTION_RANGE_TOOL_MAJOR

Added in API level 9
Deprecated in API level 15
static val MOTION_RANGE_TOOL_MAJOR: Int

Deprecated: Use MotionEvent#AXIS_TOOL_MAJOR instead.

Constant for retrieving the range of values for MotionEvent#AXIS_TOOL_MAJOR.

Value: 6

See Also

MOTION_RANGE_TOOL_MINOR

Added in API level 9
Deprecated in API level 15
static val MOTION_RANGE_TOOL_MINOR: Int

Deprecated: Use MotionEvent#AXIS_TOOL_MINOR instead.

Constant for retrieving the range of values for MotionEvent#AXIS_TOOL_MINOR.

Value: 7

See Also

MOTION_RANGE_TOUCH_MAJOR

Added in API level 9
Deprecated in API level 15
static val MOTION_RANGE_TOUCH_MAJOR: Int

Deprecated: Use MotionEvent#AXIS_TOUCH_MAJOR instead.

Constant for retrieving the range of values for MotionEvent#AXIS_TOUCH_MAJOR.

Value: 4

See Also

MOTION_RANGE_TOUCH_MINOR

Added in API level 9
Deprecated in API level 15
static val MOTION_RANGE_TOUCH_MINOR: Int

Deprecated: Use MotionEvent#AXIS_TOUCH_MINOR instead.

Constant for retrieving the range of values for MotionEvent#AXIS_TOUCH_MINOR.

Value: 5

See Also

MOTION_RANGE_X

Added in API level 9
Deprecated in API level 15
static val MOTION_RANGE_X: Int

Deprecated: Use MotionEvent#AXIS_X instead.

Constant for retrieving the range of values for MotionEvent#AXIS_X.

Value: 0

See Also

MOTION_RANGE_Y

Added in API level 9
Deprecated in API level 15
static val MOTION_RANGE_Y: Int

Deprecated: Use MotionEvent#AXIS_Y instead.

Constant for retrieving the range of values for MotionEvent#AXIS_Y.

Value: 1

See Also

SOURCE_ANY

Added in API level 9
static val SOURCE_ANY: Int

A special input source constant that is used when filtering input devices to match devices that provide any type of input source.

Value: -256

SOURCE_BLUETOOTH_STYLUS

Added in API level 23
static val SOURCE_BLUETOOTH_STYLUS: Int

The input device is a Bluetooth stylus.

Note that this bit merely indicates that an input device is capable of obtaining input from a Bluetooth stylus. To determine whether a given touch event was produced by a stylus, examine the tool type returned by MotionEvent#getToolType(int) for each individual pointer.

A single touch event may multiple pointers with different tool types, such as an event that has one pointer with tool type MotionEvent#TOOL_TYPE_FINGER and another pointer with tool type MotionEvent#TOOL_TYPE_STYLUS. So it is important to examine the tool type of each pointer, regardless of the source reported by MotionEvent#getSource().

A bluetooth stylus generally receives its pressure and button state information from the stylus itself, and derives the rest from another source. For example, a Bluetooth stylus used in conjunction with a touchscreen would derive its contact position and pointer size from the touchscreen and may not be any more accurate than other tools such as fingers.

Value: 49154

SOURCE_CLASS_BUTTON

Added in API level 9
static val SOURCE_CLASS_BUTTON: Int

The input source has buttons or keys. Examples: SOURCE_KEYBOARD, SOURCE_DPAD. A KeyEvent should be interpreted as a button or key press. Use getKeyCharacterMap to query the device's button and key mappings.

Value: 1

SOURCE_CLASS_JOYSTICK

Added in API level 12
static val SOURCE_CLASS_JOYSTICK: Int

The input source is a joystick. A MotionEvent should be interpreted as absolute joystick movements. Use getMotionRange to query the range of positions.

Value: 16

SOURCE_CLASS_MASK

Added in API level 9
static val SOURCE_CLASS_MASK: Int

A mask for input source classes. Each distinct input source constant has one or more input source class bits set to specify the desired interpretation for its input events.

Value: 255

SOURCE_CLASS_NONE

Added in API level 18
static val SOURCE_CLASS_NONE: Int

The input source has no class. It is up to the application to determine how to handle the device based on the device type.

Value: 0

SOURCE_CLASS_POINTER

Added in API level 9
static val SOURCE_CLASS_POINTER: Int

The input source is a pointing device associated with a display. Examples: SOURCE_TOUCHSCREEN, SOURCE_MOUSE. A MotionEvent should be interpreted as absolute coordinates in display units according to the View hierarchy. Pointer down/up indicated when the finger touches the display or when the selection button is pressed/released. Use getMotionRange to query the range of the pointing device. Some devices permit touches outside the display area so the effective range may be somewhat smaller or larger than the actual display size.

Value: 2

SOURCE_CLASS_POSITION

Added in API level 9
static val SOURCE_CLASS_POSITION: Int

The input source is an absolute positioning device not associated with a display (unlike SOURCE_CLASS_POINTER). A MotionEvent should be interpreted as absolute coordinates in device-specific surface units. Use getMotionRange to query the range of positions.

Value: 8

SOURCE_CLASS_TRACKBALL

Added in API level 9
static val SOURCE_CLASS_TRACKBALL: Int

The input source is a trackball navigation device. Examples: SOURCE_TRACKBALL. A MotionEvent should be interpreted as relative movements in device-specific units used for navigation purposes. Pointer down/up indicates when the selection button is pressed/released. Use getMotionRange to query the range of motion.

Value: 4

SOURCE_DPAD

Added in API level 9
static val SOURCE_DPAD: Int

The input source is a DPad.

Value: 513

SOURCE_GAMEPAD

Added in API level 12
static val SOURCE_GAMEPAD: Int

The input source is a game pad. (It may also be a SOURCE_JOYSTICK).

Value: 1025

SOURCE_HDMI

Added in API level 21
static val SOURCE_HDMI: Int

The input source is a device connected through HDMI-based bus. The key comes in through HDMI-CEC or MHL signal line, and is treated as if it were generated by a locally connected DPAD or keyboard.

Value: 33554433

SOURCE_JOYSTICK

Added in API level 12
static val SOURCE_JOYSTICK: Int

The input source is a joystick. (It may also be a SOURCE_GAMEPAD).

Value: 16777232

SOURCE_KEYBOARD

Added in API level 9
static val SOURCE_KEYBOARD: Int

The input source is a keyboard. This source indicates pretty much anything that has buttons. Use getKeyboardType() to determine whether the keyboard has alphabetic keys and can be used to enter text.

Value: 257

SOURCE_MOUSE

Added in API level 9
static val SOURCE_MOUSE: Int

The input source is a mouse pointing device. This code is also used for other mouse-like pointing devices such as trackpads and trackpoints.

Value: 8194

SOURCE_MOUSE_RELATIVE

Added in API level 26
static val SOURCE_MOUSE_RELATIVE: Int

The input source is a mouse device whose relative motions should be interpreted as navigation events.

Value: 131076

SOURCE_ROTARY_ENCODER

Added in API level 26
static val SOURCE_ROTARY_ENCODER: Int

The input source is a rotating encoder device whose motions should be interpreted as akin to those of a scroll wheel.

Value: 4194304

SOURCE_STYLUS

Added in API level 14
static val SOURCE_STYLUS: Int

The input source is a stylus pointing device.

Note that this bit merely indicates that an input device is capable of obtaining input from a stylus. To determine whether a given touch event was produced by a stylus, examine the tool type returned by MotionEvent#getToolType(int) for each individual pointer.

A single touch event may multiple pointers with different tool types, such as an event that has one pointer with tool type MotionEvent#TOOL_TYPE_FINGER and another pointer with tool type MotionEvent#TOOL_TYPE_STYLUS. So it is important to examine the tool type of each pointer, regardless of the source reported by MotionEvent#getSource().

Value: 16386

SOURCE_TOUCHPAD

Added in API level 9
static val SOURCE_TOUCHPAD: Int

The input source is a touch pad or digitizer tablet that is not associated with a display (unlike SOURCE_TOUCHSCREEN).

Value: 1048584

SOURCE_TOUCHSCREEN

Added in API level 9
static val SOURCE_TOUCHSCREEN: Int

The input source is a touch screen pointing device.

Value: 4098

SOURCE_TOUCH_NAVIGATION

Added in API level 18
static val SOURCE_TOUCH_NAVIGATION: Int

The input source is a touch device whose motions should be interpreted as navigation events. For example, an upward swipe should be as an upward focus traversal in the same manner as pressing up on a D-Pad would be. Swipes to the left, right and down should be treated in a similar manner.

Value: 2097152

SOURCE_TRACKBALL

Added in API level 9
static val SOURCE_TRACKBALL: Int

The input source is a trackball.

Value: 65540

SOURCE_UNKNOWN

Added in API level 9
static val SOURCE_UNKNOWN: Int

The input source is unknown.

Value: 0

Public methods

describeContents

Added in API level 9
fun describeContents(): Int
Return
Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR

getControllerNumber

Added in API level 19
fun getControllerNumber(): Int

The controller number for a given input device.

Each gamepad or joystick is given a unique, positive controller number when initially configured by the system. This number may change due to events such as device disconnects / reconnects or user initiated reassignment. Any change in number will trigger an event that can be observed by registering an InputManager.InputDeviceListener.

All input devices which are not gamepads or joysticks will be assigned a controller number of 0.

Return
Int The controller number of the device.

getDescriptor

Added in API level 16
fun getDescriptor(): String!

Gets the input device descriptor, which is a stable identifier for an input device.

An input device descriptor uniquely identifies an input device. Its value is intended to be persistent across system restarts, and should not change even if the input device is disconnected, reconnected or reconfigured at any time.

It is possible for there to be multiple InputDevice instances that have the same input device descriptor. This might happen in situations where a single human input device registers multiple InputDevice instances (HID collections) that describe separate features of the device, such as a keyboard that also has a trackpad. Alternately, it may be that the input devices are simply indistinguishable, such as two keyboards made by the same manufacturer.

The input device descriptor returned by getDescriptor should only be used when an application needs to remember settings associated with a particular input device. For all other purposes when referring to a logical InputDevice instance at runtime use the id returned by getId().

Return
String! The input device descriptor.

getDevice

Added in API level 9
static fun getDevice(id: Int): InputDevice!

Gets information about the input device with the specified id.

Parameters
id Int: The device id.
Return
InputDevice! The input device or null if not found.

getDeviceIds

Added in API level 9
static fun getDeviceIds(): IntArray!

Gets the ids of all input devices in the system.

Return
IntArray! The input device ids.

getId

Added in API level 9
fun getId(): Int

Gets the input device id.

Each input device receives a unique id when it is first configured by the system. The input device id may change when the system is restarted or if the input device is disconnected, reconnected or reconfigured at any time. If you require a stable identifier for a device that persists across boots and reconfigurations, use getDescriptor().

Return
Int The input device id.

getKeyCharacterMap

Added in API level 9
fun getKeyCharacterMap(): KeyCharacterMap!

Gets the key character map associated with this input device.

Return
KeyCharacterMap! The key character map.

getKeyboardType

Added in API level 9
fun getKeyboardType(): Int

Gets the keyboard type.

Return
Int The keyboard type.

getMotionRange

Added in API level 9
fun getMotionRange(axis: Int): InputDevice.MotionRange!

Gets information about the range of values for a particular MotionEvent axis. If the device supports multiple sources, the same axis may have different meanings for each source. Returns information about the first axis found for any source. To obtain information about the axis for a specific source, use getMotionRange(int,int).

Parameters
axis Int: The axis constant.
Return
InputDevice.MotionRange! The range of values, or null if the requested axis is not supported by the device.

getMotionRange

Added in API level 12
fun getMotionRange(
    axis: Int,
    source: Int
): InputDevice.MotionRange!

Gets information about the range of values for a particular MotionEvent axis used by a particular source on the device. If the device supports multiple sources, the same axis may have different meanings for each source.

Parameters
axis Int: The axis constant.
source Int: The source for which to return information.
Return
InputDevice.MotionRange! The range of values, or null if the requested axis is not supported by the device.

getMotionRanges

Added in API level 12
fun getMotionRanges(): MutableList<InputDevice.MotionRange!>!

Gets the ranges for all axes supported by the device.

Return
MutableList<InputDevice.MotionRange!>! The motion ranges for the device.

getName

Added in API level 9
fun getName(): String!

Gets the name of this input device.

Return
String! The input device name.

getProductId

Added in API level 19
fun getProductId(): Int

Gets the product id for the given device, if available.

A product id uniquely identifies which product within the address space of a given vendor, identified by the device's vendor id. A value of 0 will be assigned where a product id is not available.

Return
Int The product id of a given device

getSources

Added in API level 9
fun getSources(): Int

Gets the input sources supported by this input device as a combined bitfield.

Return
Int The supported input sources.

getVendorId

Added in API level 19
fun getVendorId(): Int

Gets the vendor id for the given device, if available.

A vendor id uniquely identifies the company who manufactured the device. A value of 0 will be assigned where a vendor id is not available.

Return
Int The vendor id of a given device

getVibrator

Added in API level 16
fun getVibrator(): Vibrator!

Gets the vibrator service associated with the device, if there is one. Even if the device does not have a vibrator, the result is never null. Use Vibrator#hasVibrator to determine whether a vibrator is present. Note that the vibrator associated with the device may be different from the system vibrator. To obtain an instance of the system vibrator instead, call Context#getSystemService with Context#VIBRATOR_SERVICE as argument.

Return
Vibrator! The vibrator service associated with the device, never null.

hasKeys

Added in API level 19
fun hasKeys(vararg keys: Int): BooleanArray!

Gets whether the device is capable of producing the list of keycodes.

Parameters
keys Int: The list of android keycodes to check for.
Return
BooleanArray! An array of booleans where each member specifies whether the device is capable of generating the keycode given by the corresponding value at the same index in the keys array.

hasMicrophone

Added in API level 23
fun hasMicrophone(): Boolean

Reports whether the device has a built-in microphone.

Return
Boolean Whether the device has a built-in microphone.

isEnabled

Added in API level 27
fun isEnabled(): Boolean

Returns true if input device is enabled.

Return
Boolean Whether the input device is enabled.

isExternal

Added in API level 29
fun isExternal(): Boolean

Returns true if the device is external (connected to USB or Bluetooth or some other peripheral bus), otherwise it is built-in.

Return
Boolean True if the device is external.

isVirtual

Added in API level 16
fun isVirtual(): Boolean

Returns true if the device is a virtual input device rather than a real one, such as the virtual keyboard (see KeyCharacterMap#VIRTUAL_KEYBOARD).

Virtual input devices are provided to implement system-level functionality and should not be seen or configured by users.

Return
Boolean True if the device is virtual.

supportsSource

Added in API level 21
fun supportsSource(source: Int): Boolean

Determines whether the input device supports the given source or sources.

Parameters
source Int: The input source or sources to check against. This can be a generic device type such as InputDevice#SOURCE_MOUSE, a more generic device class, such as InputDevice#SOURCE_CLASS_POINTER, or a combination of sources bitwise ORed together.
Return
Boolean Whether the device can produce all of the given sources.

toString

Added in API level 9
fun toString(): String
Return
String a string representation of the object.

writeToParcel

Added in API level 9
fun writeToParcel(
    out: Parcel!,
    flags: Int
): Unit
Parameters
dest The Parcel in which the object should be written.
flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

Properties

CREATOR

Added in API level 9
static val CREATOR: Parcelable.Creator<InputDevice!>