# @ohos.multimodalInput.inputDevice (Input Device)
The **inputDevice** module allows you to listen for hot swap events of input devices and query information about input devices.
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import { inputDevice } from '@kit.InputKit';
```
## inputDevice.getDeviceList9+
getDeviceList(callback: AsyncCallback<Array<number>>): void
Obtains the IDs of all input devices. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the result.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```js
try {
inputDevice.getDeviceList((error: Error, ids: Array) => {
if (error) {
console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Device id list: ${JSON.stringify(ids)}`);
});
} catch (error) {
console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.getDeviceList9+
getDeviceList(): Promise<Array<number>>
Obtains the IDs of all input devices. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Return value**
| Parameters | Description |
| ---------------------------------- | ------------------------------------------- |
| Promise<Array<number>> | Promise used to return the result.|
**Example**
```js
try {
inputDevice.getDeviceList().then((ids: Array) => {
console.log(`Device id list: ${JSON.stringify(ids)}`);
});
} catch (error) {
console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.getDeviceInfo9+
getDeviceInfo(deviceId: number, callback: AsyncCallback<InputDeviceData>): void
Obtains information about an input device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------------------- | ---- | --------------------------------------- |
| deviceId | number | Yes | ID of the input device. |
| callback | AsyncCallback<[InputDeviceData](#inputdevicedata)> | Yes | Callback used to return the result, which is an **InputDeviceData** object.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```js
// Obtain the name of the device whose ID is 1.
try {
inputDevice.getDeviceInfo(1, (error: Error, deviceData: inputDevice.InputDeviceData) => {
if (error) {
console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Device info: ${JSON.stringify(deviceData)}`);
});
} catch (error) {
console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.getDeviceInfo9+
getDeviceInfo(deviceId: number): Promise<InputDeviceData>
Obtains information about an input device. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------------------- |
| deviceId | number | Yes | ID of the input device.|
**Return value**
| Parameters | Description |
| -------------------------------------------------- | ------------------------------- |
| Promise<[InputDeviceData](#inputdevicedata)> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```js
// Obtain the name of the device whose ID is 1.
try {
inputDevice.getDeviceInfo(1).then((deviceData: inputDevice.InputDeviceData) => {
console.log(`Device info: ${JSON.stringify(deviceData)}`);
});
} catch (error) {
console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.getDeviceInfoSync10+
getDeviceInfoSync(deviceId: number): InputDeviceData
Obtains information about the specified input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------------------- |
| deviceId | number | Yes | ID of the input device.|
**Return value**
| Parameters | Description |
| -------------------------------------------------- | ------------------------------- |
| [InputDeviceData](#inputdevicedata) | Information about the input device.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```js
// Obtain the name of the device whose ID is 1.
try {
let deviceData: inputDevice.InputDeviceData = inputDevice.getDeviceInfoSync(1)
console.log(`Device info: ${JSON.stringify(deviceData)}`)
} catch (error) {
console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`)
}
```
## inputDevice.on9+
on(type: "change", listener: Callback<DeviceListener>): void
Enables listening for device hot swap events. When performing this operation, you need to connect your device to an external device, for example, mouse or keyboard.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------- |
| type | string | Yes | Event type of the input device, such as the mouse, keyboard, or touchscreen. |
| listener | Callback<[DeviceListener](#devicelistener9)> | Yes | Listener for events of the input device.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```js
let isPhysicalKeyboardExist = true;
try {
inputDevice.on("change", (data: inputDevice.DeviceListener) => {
console.log(`Device event info: ${JSON.stringify(data)}`);
inputDevice.getKeyboardType(data.deviceId, (err: Error, type: inputDevice.KeyboardType) => {
console.log("The keyboard type is: " + type);
if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
// The physical keyboard is connected.
isPhysicalKeyboardExist = true;
} else if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
// The physical keyboard is disconnected.
isPhysicalKeyboardExist = false;
}
});
});
// Check whether the soft keyboard is open based on the value of isPhysicalKeyboardExist.
} catch (error) {
console.log(`Get device info failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.off9+
off(type: "change", listener?: Callback<DeviceListener>): void
Disables listening for device hot swap events. This API is called before the application exits.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ----------- |
| type | string | Yes | Event type of the input device, such as the mouse, keyboard, or touchscreen. |
| listener | Callback<[DeviceListener](#devicelistener9)> | No | Listener for events of the input device.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```js
function callback(data: inputDevice.DeviceListener) {
console.log(`Report device event info: ${JSON.stringify(data, [`type`, `deviceId`])}`);
};
try {
inputDevice.on("change", callback);
} catch (error) {
console.log(`Listen device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// Disable this listener.
try {
inputDevice.off("change", callback);
} catch (error) {
console.log(`Cancel listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// Disable all listeners.
try {
inputDevice.off("change");
} catch (error) {
console.log(`Cancel all listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.getDeviceIds(deprecated)
getDeviceIds(callback: AsyncCallback<Array<number>>): void
Obtains the IDs of all input devices. This API uses an asynchronous callback to return the result.
> This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceList](#inputdevicegetdevicelist9) instead.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback<Array<number>> | Yes | Callback used to return the result.|
**Example**
```js
inputDevice.getDeviceIds((error: Error, ids: Array) => {
if (error) {
console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Device id list: ${JSON.stringify(ids)}`);
});
```
## inputDevice.getDeviceIds(deprecated)
getDeviceIds(): Promise<Array<number>>
Obtains the IDs of all input devices. This API uses a promise to return the result.
> This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceList](#inputdevicegetdevicelist9) instead.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Return value**
| Parameters | Description |
| ---------------------------------- | ------------------------------------------- |
| Promise<Array<number>> | Promise used to return the result.|
**Example**
```js
inputDevice.getDeviceIds().then((ids: Array) => {
console.log(`Device id list: ${JSON.stringify(ids)}`);
});
```
## inputDevice.getDevice(deprecated)
getDevice(deviceId: number, callback: AsyncCallback<InputDeviceData>): void
Obtains information about an input device. This API uses an asynchronous callback to return the result.
> This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9) instead.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------------------- | ---- | -------------------------------- |
| deviceId | number | Yes | ID of the input device. |
| callback | AsyncCallback<[InputDeviceData](#inputdevicedata)> | Yes | Callback used to return the result, which is an **InputDeviceData** object.|
**Example**
```js
// Obtain the name of the device whose ID is 1.
inputDevice.getDevice(1, (error: Error, deviceData: inputDevice.InputDeviceData) => {
if (error) {
console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Device info: ${JSON.stringify(deviceData)}`);
});
```
## inputDevice.getDevice(deprecated)
getDevice(deviceId: number): Promise<InputDeviceData>
Obtains information about an input device. This API uses a promise to return the result.
> This API is deprecated since API version 9. You are advised to use [inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9) instead.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------ |
| deviceId | number | Yes | ID of the input device.|
**Return value**
| Parameters | Description |
| -------------------------------------------------- | ----------------------------------- |
| Promise<[InputDeviceData](#inputdevicedata)> | Promise used to return the result.|
**Example**
```js
// Obtain the name of the device whose ID is 1.
inputDevice.getDevice(1).then((deviceData: inputDevice.InputDeviceData) => {
console.log(`Device info: ${JSON.stringify(deviceData)}`);
});
```
## inputDevice.supportKeys9+
supportKeys(deviceId: number, keys: Array<KeyCode>, callback: AsyncCallback <Array<boolean>>): void
Obtains the keycodes supported by the input device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| keys | Array[<KeyCode>](js-apis-keycode.md#keycode) | Yes | Keycodes to be queried. A maximum of five keycodes can be specified. |
| callback | AsyncCallback<Array<boolean>> | Yes | Callback used to return the result. |
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```js
// Check whether the input device whose ID is 1 supports keycodes 17, 22, and 2055.
try {
inputDevice.supportKeys(1, [17, 22, 2055], (error: Error, supportResult: Array) => {
console.log(`Query result: ${JSON.stringify(supportResult)}`);
});
} catch (error) {
console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.supportKeys9+
supportKeys(deviceId: number, keys: Array<KeyCode>): Promise<Array<boolean>>
Obtains the keycodes supported by the input device. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| keys | Array[<KeyCode>](js-apis-keycode.md#keycode) | Yes | Keycodes to be queried. A maximum of five keycodes can be specified. |
**Return value**
| Parameters | Description |
| ----------------------------------- | ------------------------------- |
| Promise<Array<boolean>> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```js
// Check whether the input device whose ID is 1 supports keycodes 17, 22, and 2055.
try {
inputDevice.supportKeys(1, [17, 22, 2055]).then((supportResult: Array) => {
console.log(`Query result: ${JSON.stringify(supportResult)}`);
});
} catch (error) {
console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.supportKeysSync10+
supportKeysSync(deviceId: number, keys: Array<KeyCode>): Array<boolean>
Checks whether the input device supports the specified keycode value.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| keys | Array[<KeyCode>](js-apis-keycode.md#keycode) | Yes | Keycodes to be queried. A maximum of five keycodes can be specified. |
**Return value**
| Parameters | Description |
| ----------------------------------- | ------------------------------- |
| Array<boolean> | Result indicating whether the input device supports the keycode value. The value **true** indicates yes, and the value **false** indicates no.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```js
// Check whether the input device whose ID is 1 supports keycodes 17, 22, and 2055.
try {
let supportResult: Array = inputDevice.supportKeysSync(1, [17, 22, 2055])
console.log(`Query result: ${JSON.stringify(supportResult)}`)
} catch (error) {
console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`)
}
```
## inputDevice.getKeyboardType9+
getKeyboardType(deviceId: number, callback: AsyncCallback<KeyboardType>): void
Obtains the keyboard type of an input device. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| callback | AsyncCallback<[KeyboardType](#keyboardtype9)> | Yes | Callback used to return the result. |
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```js
// Query the keyboard type of the input device whose ID is 1.
try {
inputDevice.getKeyboardType(1, (error: Error, type: Number) => {
if (error) {
console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
console.log(`Keyboard type: ${JSON.stringify(type)}`);
});
} catch (error) {
console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.getKeyboardType9+
getKeyboardType(deviceId: number): Promise<KeyboardType>
Obtains the keyboard type of an input device. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
**Return value**
| Parameters | Description |
| --------------------------------------------- | ------------------------------- |
| Promise<[KeyboardType](#keyboardtype9)> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```js
// Query the keyboard type of the input device whose ID is 1.
try {
inputDevice.getKeyboardType(1).then((type: Number) => {
console.log(`Keyboard type: ${JSON.stringify(type)}`);
});
} catch (error) {
console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.getKeyboardTypeSync10+
getKeyboardTypeSync(deviceId: number): KeyboardType
Obtains the keyboard type of the input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| deviceId | number | Yes | Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
**Return value**
| Parameters | Description |
| --------------------------------------------- | ------------------------------- |
| [KeyboardType](#keyboardtype9) | Keyboard type.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```js
// Query the keyboard type of the input device whose ID is 1.
try {
let type: number = inputDevice.getKeyboardTypeSync(1)
console.log(`Keyboard type: ${JSON.stringify(type)}`)
} catch (error) {
console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`)
}
```
## inputDevice.isFunctionKeyEnabled15+
isFunctionKeyEnabled(functionKey: FunctionKey): Promise<boolean>
Checks whether the function key is enabled. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| functionKey | [FunctionKey](#functionkey15) | Yes | Type of the function key.|
**Return value**
| Parameters | Description |
| ---------------------- | ------------------------------------------------------------ |
| Promise<boolean> | Promise used to return the result. The value **true** indicates that the function key is enabled, and the value **false** indicates the opposite.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Input Device Error Codes](errorcode-inputdevice.md).
| ID | Error Message |
| ---- | --------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
| 3900002 | There is currently no keyboard device connected. |
**Example**
```js
import { inputDevice } from '@kit.InputKit';
try {
inputDevice.isFunctionKeyEnabled(inputDevice.FunctionKey.CAPS_LOCK).then((state: boolean) => {
console.log(`capslock state: ${JSON.stringify(state)}`);
});
} catch (error) {
console.log(`Failed to get capslock state, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.setFunctionKeyEnabled15+
setFunctionKeyEnabled(functionKey: FunctionKey, enabled: boolean): Promise<void>
Sets the status of the function key . This API uses a promise to return the result.
**Required permissions**: ohos.permission.INPUT_KEYBOARD_CONTROLLER
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------- | ---- | ------------------------- |
| functionKey | [FunctionKey](#functionkey15) | Yes | Type of the function key.|
| enabled | boolean | Yes | Status of the function key. The value **true** indicates that the function key is enabled, and the value **false** indicates the opposite.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Input Device Error Codes](errorcode-inputdevice.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 201 | Permission denied. |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. |
| 3900002 | There is currently no keyboard device connected. |
| 3900003 | It is prohibited for non-input applications. |
**Example**
```js
import { inputDevice } from '@kit.InputKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
inputDevice.setFunctionKeyEnabled(inputDevice.FunctionKey.CAPS_LOCK, true).then(() => {
console.info(`Set capslock state success`);
}).catch((error: BusinessError) => {
console.info(`Set capslock state failed, error=${JSON.stringify(error)}`);
});
} catch (error) {
console.info(`Set capslock enable error`);
}
```
## inputDevice.getIntervalSinceLastInput14+
getIntervalSinceLastInput(): Promise<number>
Obtains the interval since the last system input event. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
**Return value**
| Parameters | Description |
| --------------------------------------------- | ------------------------------- |
| Promise<number> | Promise used to return the interval since the last system input event, in μs.|
**Example**
```js
inputDevice.getIntervalSinceLastInput().then((timeInterval: number) => {
console.log(`Interval since last input: ${JSON.stringify(timeInterval)}`);
});
```
## DeviceListener9+
Defines the listener for hot swap events of an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Readable | Writable | Description |
| --------- | ------ | ---- | ---- | ------- |
| type | [ChangedType](#changedtype9)| Yes| No| Device change type, which indicates whether an input device is inserted or removed.|
| deviceId | number | Yes| No| Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
## InputDeviceData
Defines the information about an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Readable | Writable | Description |
| --------- | ------ | ---- | ---- | ------- |
| id | number | Yes| No| Unique ID of the input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| name | string | Yes| No| Name of the input device. |
| sources | Array<[SourceType](#sourcetype9)> | Yes| No| Source type of the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad.|
| axisRanges | Array<[AxisRange](#axisrange)> | Yes| No| Axis information of the input device. |
| bus9+ | number | Yes| No| Bus type of the input device. |
| product9+ | number | Yes| No| Product information of the input device. |
| vendor9+ | number | Yes| No| Vendor information of the input device. |
| version9+ | number | Yes| No| Version information of the input device. |
| phys9+ | string | Yes| No| Physical address of the input device. |
| uniq9+ | string | Yes| No| Unique ID of the input device. |
## AxisType9+
type AxisType = 'touchmajor' | 'touchminor' | 'orientation' | 'x' | 'y' | 'pressure' | 'toolminor' | 'toolmajor' | 'null'
Defines the axis type of an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Type |Description |
| --------- | ------- |
| 'touchmajor' | Major axis of the elliptical touching area.|
| 'touchminor' | Minor axis of the elliptical touching area.|
| 'toolminor' | Minor axis of the tool area.|
| 'toolmajor' | Major axis of the tool area.|
| 'orientation' | Orientation axis.|
|'pressure' | Pressure axis. |
| 'x' | Horizontal axis. |
| 'y' | Vertical axis. |
|'null' | None. |
## AxisRange
Defines the axis range of an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Type | Readable | Writable | Description |
| --------- | ------ | ---- | ---- | ------- |
| source | [SourceType](#sourcetype9) | Yes| No| Input source type of the axis.|
| axis | [AxisType](#axistype9) | Yes| No| Axis type. |
| max | number | Yes| No| Maximum value of the axis. |
| min | number | Yes| No| Minimum value of the axis. |
| fuzz9+ | number | Yes| No| Fuzzy value of the axis. |
| flat9+ | number | Yes| No| Benchmark value of the axis. |
| resolution9+ | number | Yes| No| Resolution of the axis. |
## SourceType9+
type SourceType = 'keyboard' | 'mouse' | 'touchpad' | 'touchscreen' | 'joystick' | 'trackball'
Enumerates input source types of the axis. For example, if a mouse reports an x-axis event, the input source of the x-axis is the mouse.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Type |Description |
| --------- | ------- |
| 'keyboard' | The input device is a keyboard. |
| 'touchscreen' | The input device is a touchscreen.|
| 'mouse' | The input device is a mouse. |
| 'trackball' | The input device is a trackball.|
| 'touchpad' | The input device is a touchpad.|
| 'joystick' | The input device is a joystick.|
## ChangedType9+
type ChangedType = 'add' | 'remove'
Defines the change type for the hot swap event of an input device.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Type | Description |
| --------- | ------- |
| 'add' | An input device is inserted.|
| 'remove' | An input device is removed.|
## KeyboardType9+
Enumerates the keyboard types.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Value | Description |
| ------------------- | ---- | --------- |
| NONE | 0 | Keyboard without keys. |
| UNKNOWN | 1 | Keyboard with unknown keys.|
| ALPHABETIC_KEYBOARD | 2 | Full keyboard. |
| DIGITAL_KEYBOARD | 3 | Keypad. |
| HANDWRITING_PEN | 4 | Stylus. |
| REMOTE_CONTROL | 5 | Remote control. |
## FunctionKey15+
Defines the type of a function key.
**System capability**: SystemCapability.MultimodalInput.Input.InputDevice
| Name | Value | Description |
| ------------------- | ---- | --------- |
| CAPS_LOCK | 1 | CapsLock key. This key can be enabled or disabled only for the input keyboard extension.|