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 |
|
Provides information on how views processing |
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 |
static Int |
Constant for retrieving the range of values for |
static Int |
Constant for retrieving the range of values for |
static Int |
Constant for retrieving the range of values for |
static Int |
Constant for retrieving the range of values for |
static Int |
Constant for retrieving the range of values for |
static Int |
Constant for retrieving the range of values for |
static Int |
Constant for retrieving the range of values for |
static Int |
Constant for retrieving the range of values for |
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 |
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 sensor associated with the input device. |
static Int |
The input source is a stylus pointing device. |
static Int |
The input source is a touchpad (also known as a trackpad). |
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 | |
BatteryState |
Gets the battery state object associated with the device, if there is one. |
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 |
getId() Gets the input device id. |
KeyCharacterMap! |
Gets the key character map associated with this input device. |
Int |
getKeyCodeForKeyLocation(locationKeyCode: Int) Gets the |
Int |
Gets the keyboard type. |
LightsManager |
Gets the lights manager associated with the device, if there is one. |
InputDevice.MotionRange! |
getMotionRange(axis: Int) Gets information about the range of values for a particular |
InputDevice.MotionRange! |
getMotionRange(axis: Int, source: Int) Gets information about the range of values for a particular |
MutableList<InputDevice.MotionRange!>! |
Gets the ranges for all axes supported by the device. |
String! |
getName() Gets the name of this input device. |
Int |
Gets the product id for the given device, if available. |
SensorManager |
Gets the sensor manager service associated with the input device. |
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. |
VibratorManager |
Gets the vibrator manager associated with the device. |
BooleanArray! |
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 |
Boolean |
supportsSource(source: Int) Determines whether the input device supports the given source or sources. |
String |
toString() |
Unit |
writeToParcel(out: Parcel, flags: Int) |
Properties | |
---|---|
static Parcelable.Creator<InputDevice!> |
Constants
KEYBOARD_TYPE_ALPHABETIC
static val KEYBOARD_TYPE_ALPHABETIC: Int
The keyboard supports a complement of alphabetic keys.
Value: 2
KEYBOARD_TYPE_NONE
static val KEYBOARD_TYPE_NONE: Int
There is no keyboard.
Value: 0
KEYBOARD_TYPE_NON_ALPHABETIC
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
static valMOTION_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
static valMOTION_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
static valMOTION_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
static valMOTION_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
static valMOTION_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
static valMOTION_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
static valMOTION_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
static valMOTION_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
static valMOTION_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
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
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
See Also
SOURCE_CLASS_BUTTON
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
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
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
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
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
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
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
static val SOURCE_DPAD: Int
The input source is a DPad.
Value: 513
See Also
SOURCE_GAMEPAD
static val SOURCE_GAMEPAD: Int
The input source is a game pad. (It may also be a SOURCE_JOYSTICK
).
Value: 1025
See Also
SOURCE_HDMI
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
static val SOURCE_JOYSTICK: Int
The input source is a joystick. (It may also be a SOURCE_GAMEPAD
).
Value: 16777232
See Also
SOURCE_KEYBOARD
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
See Also
SOURCE_MOUSE
static val SOURCE_MOUSE: Int
The input source is a mouse pointing device. This value is also used for other mouse-like pointing devices such as touchpads and pointing sticks. When used in combination with SOURCE_STYLUS
, it denotes an external drawing tablet.
Value: 8194
See Also
SOURCE_MOUSE_RELATIVE
static val SOURCE_MOUSE_RELATIVE: Int
The input source is a mouse device whose relative motions should be interpreted as navigation events.
Value: 131076
See Also
SOURCE_ROTARY_ENCODER
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
See Also
SOURCE_SENSOR
static val SOURCE_SENSOR: Int
The input source is a sensor associated with the input device.
Value: 67108864
See Also
SOURCE_STYLUS
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
See Also
SOURCE_TOUCHPAD
static val SOURCE_TOUCHPAD: Int
The input source is a touchpad (also known as a trackpad). Touchpads that are used to move the mouse cursor will also have SOURCE_MOUSE
.
Value: 1048584
See Also
SOURCE_TOUCHSCREEN
static val SOURCE_TOUCHSCREEN: Int
The input source is a touch screen pointing device.
Value: 4098
See Also
SOURCE_TOUCH_NAVIGATION
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
See Also
SOURCE_TRACKBALL
static val SOURCE_TRACKBALL: Int
The input source is a trackball.
Value: 65540
See Also
SOURCE_UNKNOWN
static val SOURCE_UNKNOWN: Int
The input source is unknown.
Value: 0
Public methods
describeContents
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 |
getBatteryState
fun getBatteryState(): BatteryState
Gets the battery state object associated with the device, if there is one. Even if the device does not have a battery, the result is never null. Use BatteryState#isPresent
to determine whether a battery is present.
Return | |
---|---|
BatteryState |
The battery object associated with the device, never null. |
getControllerNumber
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 android.hardware.input.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
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 touchpad. 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
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
static fun getDeviceIds(): IntArray!
Gets the ids of all input devices in the system.
Return | |
---|---|
IntArray! |
The input device ids. |
getId
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
fun getKeyCharacterMap(): KeyCharacterMap!
Gets the key character map associated with this input device.
Return | |
---|---|
KeyCharacterMap! |
The key character map. |
getKeyCodeForKeyLocation
fun getKeyCodeForKeyLocation(locationKeyCode: Int): Int
Gets the key code
produced by the given location on a reference QWERTY keyboard layout.
This API is useful for querying the physical location of keys that change the character produced based on the current locale and keyboard layout.
The following table provides a non-exhaustive list of examples:
Active Keyboard Layout | Input Parameter | Return Value |
---|---|---|
French AZERTY |
|
|
German QWERTZ |
|
|
US QWERTY |
|
|
Parameters | |
---|---|
locationKeyCode |
Int: The location of a key specified as a key code on the QWERTY layout. This provides a consistent way of referring to the physical location of a key independently of the current keyboard layout. Also see the hypothetical keyboard provided by the W3C, which may be helpful for identifying the physical location of a key. |
Return | |
---|---|
Int |
The key code produced by the key at the specified location, given the current keyboard layout. Returns KeyEvent#KEYCODE_UNKNOWN if the device does not specify InputDevice#SOURCE_KEYBOARD or the requested mapping cannot be determined. |
getKeyboardType
fun getKeyboardType(): Int
Gets the keyboard type.
Return | |
---|---|
Int |
The keyboard type. |
getLightsManager
fun getLightsManager(): LightsManager
Gets the lights manager associated with the device, if there is one. Even if the device does not have lights, the result is never null. Use LightsManager#getLights
to determine whether any lights is present.
Return | |
---|---|
LightsManager |
The lights manager associated with the device, never null. |
getMotionRange
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
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
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. |
See Also
getName
fun getName(): String!
Gets the name of this input device.
Return | |
---|---|
String! |
The input device name. |
getProductId
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 |
getSensorManager
fun getSensorManager(): SensorManager
Gets the sensor manager service associated with the input device. Even if the device does not have a sensor, the result is never null. Use SensorManager#getSensorList
to get a full list of all supported sensors. Note that the sensors associated with the device may be different from the system sensors, as typically they are builtin sensors physically attached to input devices.
Return | |
---|---|
SensorManager |
The sensor manager service associated with the device, never null. |
getSources
fun getSources(): Int
Gets the input sources supported by this input device as a combined bitfield.
Return | |
---|---|
Int |
The supported input sources. |
getVendorId
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
fungetVibrator(): Vibrator!
Deprecated: Use getVibratorManager()
to retrieve the default device 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 android.content.Context#getSystemService with Context#VIBRATOR_SERVICE
as argument.
Return | |
---|---|
Vibrator! |
The vibrator service associated with the device, never null. |
getVibratorManager
fun getVibratorManager(): VibratorManager
Gets the vibrator manager associated with the device. Even if the device does not have a vibrator manager, the result is never null. Use VibratorManager#getVibratorIds
to determine whether any vibrator is present.
Return | |
---|---|
VibratorManager |
The vibrator manager associated with the device, never null. |
hasKeys
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
fun hasMicrophone(): Boolean
Reports whether the device has a built-in microphone.
Return | |
---|---|
Boolean |
Whether the device has a built-in microphone. |
isEnabled
fun isEnabled(): Boolean
Returns true if input device is enabled.
Return | |
---|---|
Boolean |
Whether the input device is enabled. |
isExternal
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
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
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
fun toString(): String
Return | |
---|---|
String |
a string representation of the object. |
writeToParcel
fun writeToParcel(
out: Parcel,
flags: Int
): Unit
Parameters | |
---|---|
dest |
The Parcel in which the object should be written. This value cannot be null . |
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 |