to top
Android APIs
public final class

InputDevice

extends Object
implements Parcelable
java.lang.Object
   ↳ android.view.InputDevice

Class Overview

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
class InputDevice.MotionRange Provides information about the range of values for a particular MotionEvent axis. 
Constants
int KEYBOARD_TYPE_ALPHABETIC The keyboard supports a complement of alphabetic keys.
int KEYBOARD_TYPE_NONE There is no keyboard.
int KEYBOARD_TYPE_NON_ALPHABETIC The keyboard is not fully alphabetic.
int MOTION_RANGE_ORIENTATION This constant is deprecated. Use AXIS_ORIENTATION instead.
int MOTION_RANGE_PRESSURE This constant is deprecated. Use AXIS_PRESSURE instead.
int MOTION_RANGE_SIZE This constant is deprecated. Use AXIS_SIZE instead.
int MOTION_RANGE_TOOL_MAJOR This constant is deprecated. Use AXIS_TOOL_MAJOR instead.
int MOTION_RANGE_TOOL_MINOR This constant is deprecated. Use AXIS_TOOL_MINOR instead.
int MOTION_RANGE_TOUCH_MAJOR This constant is deprecated. Use AXIS_TOUCH_MAJOR instead.
int MOTION_RANGE_TOUCH_MINOR This constant is deprecated. Use AXIS_TOUCH_MINOR instead.
int MOTION_RANGE_X This constant is deprecated. Use AXIS_X instead.
int MOTION_RANGE_Y This constant is deprecated. Use AXIS_Y instead.
int SOURCE_ANY A special input source constant that is used when filtering input devices to match devices that provide any type of input source.
int SOURCE_CLASS_BUTTON The input source has buttons or keys.
int SOURCE_CLASS_JOYSTICK The input source is a joystick.
int SOURCE_CLASS_MASK A mask for input source classes.
int SOURCE_CLASS_POINTER The input source is a pointing device associated with a display.
int SOURCE_CLASS_POSITION The input source is an absolute positioning device not associated with a display (unlike SOURCE_CLASS_POINTER).
int SOURCE_CLASS_TRACKBALL The input source is a trackball navigation device.
int SOURCE_DPAD The input source is a DPad.
int SOURCE_GAMEPAD The input source is a game pad.
int SOURCE_JOYSTICK The input source is a joystick.
int SOURCE_KEYBOARD The input source is a keyboard.
int SOURCE_MOUSE The input source is a mouse pointing device.
int SOURCE_STYLUS The input source is a stylus pointing device.
int SOURCE_TOUCHPAD The input source is a touch pad or digitizer tablet that is not associated with a display (unlike SOURCE_TOUCHSCREEN).
int SOURCE_TOUCHSCREEN The input source is a touch screen pointing device.
int SOURCE_TRACKBALL The input source is a trackball.
int SOURCE_UNKNOWN The input source is unknown.
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<InputDevice> CREATOR
Public Methods
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
String getDescriptor()
Gets the input device descriptor, which is a stable identifier for an input device.
static InputDevice getDevice(int id)
Gets information about the input device with the specified id.
static int[] getDeviceIds()
Gets the ids of all input devices in the system.
int getId()
Gets the input device id.
KeyCharacterMap getKeyCharacterMap()
Gets the key character map associated with this input device.
int getKeyboardType()
Gets the keyboard type.
InputDevice.MotionRange getMotionRange(int axis, int source)
Gets information about the range of values for a particular MotionEvent axis used by a particular source on the device.
InputDevice.MotionRange getMotionRange(int axis)
Gets information about the range of values for a particular MotionEvent axis.
List<InputDevice.MotionRange> getMotionRanges()
Gets the ranges for all axes supported by the device.
String getName()
Gets the name of this input device.
int getSources()
Gets the input sources supported by this input device as a combined bitfield.
Vibrator getVibrator()
Gets the vibrator service associated with the device, if there is one.
boolean isVirtual()
Returns true if the device is a virtual input device rather than a real one, such as the virtual keyboard (see VIRTUAL_KEYBOARD).
String toString()
Returns a string containing a concise, human-readable description of this object.
void writeToParcel(Parcel out, int flags)
Flatten this object in to a Parcel.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final int KEYBOARD_TYPE_ALPHABETIC

Since: API Level 9

The keyboard supports a complement of alphabetic keys.

Constant Value: 2 (0x00000002)

public static final int KEYBOARD_TYPE_NONE

Since: API Level 9

There is no keyboard.

Constant Value: 0 (0x00000000)

public static final int KEYBOARD_TYPE_NON_ALPHABETIC

Since: API Level 9

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.

Constant Value: 1 (0x00000001)

public static final int MOTION_RANGE_ORIENTATION

Since: API Level 9

This constant is deprecated.
Use AXIS_ORIENTATION instead.

Constant for retrieving the range of values for AXIS_ORIENTATION.

Constant Value: 8 (0x00000008)

public static final int MOTION_RANGE_PRESSURE

Since: API Level 9

This constant is deprecated.
Use AXIS_PRESSURE instead.

Constant for retrieving the range of values for AXIS_PRESSURE.

Constant Value: 2 (0x00000002)

public static final int MOTION_RANGE_SIZE

Since: API Level 9

This constant is deprecated.
Use AXIS_SIZE instead.

Constant for retrieving the range of values for AXIS_SIZE.

Constant Value: 3 (0x00000003)

public static final int MOTION_RANGE_TOOL_MAJOR

Since: API Level 9

This constant is deprecated.
Use AXIS_TOOL_MAJOR instead.

Constant for retrieving the range of values for AXIS_TOOL_MAJOR.

Constant Value: 6 (0x00000006)

public static final int MOTION_RANGE_TOOL_MINOR

Since: API Level 9

This constant is deprecated.
Use AXIS_TOOL_MINOR instead.

Constant for retrieving the range of values for AXIS_TOOL_MINOR.

Constant Value: 7 (0x00000007)

public static final int MOTION_RANGE_TOUCH_MAJOR

Since: API Level 9

This constant is deprecated.
Use AXIS_TOUCH_MAJOR instead.

Constant for retrieving the range of values for AXIS_TOUCH_MAJOR.

Constant Value: 4 (0x00000004)

public static final int MOTION_RANGE_TOUCH_MINOR

Since: API Level 9

This constant is deprecated.
Use AXIS_TOUCH_MINOR instead.

Constant for retrieving the range of values for AXIS_TOUCH_MINOR.

Constant Value: 5 (0x00000005)

public static final int MOTION_RANGE_X

Since: API Level 9

This constant is deprecated.
Use AXIS_X instead.

Constant for retrieving the range of values for AXIS_X.

Constant Value: 0 (0x00000000)

public static final int MOTION_RANGE_Y

Since: API Level 9

This constant is deprecated.
Use AXIS_Y instead.

Constant for retrieving the range of values for AXIS_Y.

Constant Value: 1 (0x00000001)

public static final int SOURCE_ANY

Since: API Level 9

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

Constant Value: -256 (0xffffff00)

public static final int SOURCE_CLASS_BUTTON

Since: API Level 9

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.

Constant Value: 1 (0x00000001)

public static final int SOURCE_CLASS_JOYSTICK

Since: API Level 12

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

Constant Value: 16 (0x00000010)

public static final int SOURCE_CLASS_MASK

Since: API Level 9

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.

Constant Value: 255 (0x000000ff)

public static final int SOURCE_CLASS_POINTER

Since: API Level 9

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(int) 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.

Constant Value: 2 (0x00000002)

public static final int SOURCE_CLASS_POSITION

Since: API Level 9

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(int) to query the range of positions.

Constant Value: 8 (0x00000008)

public static final int SOURCE_CLASS_TRACKBALL

Since: API Level 9

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(int) to query the range of motion.

Constant Value: 4 (0x00000004)

public static final int SOURCE_DPAD

Since: API Level 9

The input source is a DPad.

Constant Value: 513 (0x00000201)

public static final int SOURCE_GAMEPAD

Since: API Level 12

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

Constant Value: 1025 (0x00000401)

public static final int SOURCE_JOYSTICK

Since: API Level 12

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

Constant Value: 16777232 (0x01000010)

public static final int SOURCE_KEYBOARD

Since: API Level 9

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.

Constant Value: 257 (0x00000101)

public static final int SOURCE_MOUSE

Since: API Level 9

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

Constant Value: 8194 (0x00002002)

public static final int SOURCE_STYLUS

Since: API Level 14

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 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 TOOL_TYPE_FINGER and another pointer with tool type TOOL_TYPE_STYLUS. So it is important to examine the tool type of each pointer, regardless of the source reported by getSource().

Constant Value: 16386 (0x00004002)

public static final int SOURCE_TOUCHPAD

Since: API Level 9

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

Constant Value: 1048584 (0x00100008)

public static final int SOURCE_TOUCHSCREEN

Since: API Level 9

The input source is a touch screen pointing device.

Constant Value: 4098 (0x00001002)

public static final int SOURCE_TRACKBALL

Since: API Level 9

The input source is a trackball.

Constant Value: 65540 (0x00010004)

public static final int SOURCE_UNKNOWN

Since: API Level 9

The input source is unknown.

Constant Value: 0 (0x00000000)

Fields

public static final Creator<InputDevice> CREATOR

Since: API Level 9

Public Methods

public int describeContents ()

Since: API Level 9

Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public String getDescriptor ()

Since: API Level 16

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().

Returns
  • The input device descriptor.

public static InputDevice getDevice (int id)

Since: API Level 9

Gets information about the input device with the specified id.

Parameters
id The device id.
Returns
  • The input device or null if not found.

public static int[] getDeviceIds ()

Since: API Level 9

Gets the ids of all input devices in the system.

Returns
  • The input device ids.

public int getId ()

Since: API Level 9

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().

Returns
  • The input device id.

public KeyCharacterMap getKeyCharacterMap ()

Since: API Level 9

Gets the key character map associated with this input device.

Returns
  • The key character map.

public int getKeyboardType ()

Since: API Level 9

Gets the keyboard type.

Returns
  • The keyboard type.

public InputDevice.MotionRange getMotionRange (int axis, int source)

Since: API Level 12

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 The axis constant.
source The source for which to return information.
Returns
  • The range of values, or null if the requested axis is not supported by the device.

public InputDevice.MotionRange getMotionRange (int axis)

Since: API Level 9

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 The axis constant.
Returns
  • The range of values, or null if the requested axis is not supported by the device.

public List<InputDevice.MotionRange> getMotionRanges ()

Since: API Level 12

Gets the ranges for all axes supported by the device.

Returns
  • The motion ranges for the device.

public String getName ()

Since: API Level 9

Gets the name of this input device.

Returns
  • The input device name.

public int getSources ()

Since: API Level 9

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

Returns
  • The supported input sources.

public Vibrator getVibrator ()

Since: API Level 16

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 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 getSystemService(String) with VIBRATOR_SERVICE as argument.

Returns
  • The vibrator service associated with the device, never null.

public boolean isVirtual ()

Since: API Level 16

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

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

Returns
  • True if the device is virtual.
See Also

public String toString ()

Since: API Level 9

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public void writeToParcel (Parcel out, int flags)

Since: API Level 9

Flatten this object in to a Parcel.

Parameters
out The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.