openharmony 鸿蒙 js-apis-inputdevice-sys

2025-06-12 浏览 (1)

@ohos.multimodalInput.inputDevice (Input Device) (System API)

The inputDevice module implements input device management functions such as querying input device information.

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.

This topic describes only system APIs provided by the module. For details about its public APIs, see @ohos.multimodalInput.inputDevice (Input Device).

Modules to Import

import { inputDevice } from '@kit.InputKit';

inputDevice.setKeyboardRepeatDelay10+

setKeyboardRepeatDelay(delay: number, callback: AsyncCallback<void>): void

Sets the keyboard repeat delay. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.MultimodalInput.Input.InputDevice

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
delaynumberYesKeyboard repeat delay, in ms. The value range is [300, 1000] and the default value is 500.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202SystemAPI permission error.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

try {
  inputDevice.setKeyboardRepeatDelay(350, (error: Error) => {
    if (error) {
      console.error(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
      return;
    }
    console.log(`Set keyboard repeat delay success`);
  });
} catch (error) {
  console.error(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

inputDevice.setKeyboardRepeatDelay10+

setKeyboardRepeatDelay(delay: number): Promise<void>

Sets the keyboard repeat delay. This API uses a promise to return the result.

System capability: SystemCapability.MultimodalInput.Input.InputDevice

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
delaynumberYesKeyboard repeat delay, in ms. The value range is [300, 1000] and the default value is 500.

Return value

TypeDescription
Promise<void>A promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202SystemAPI permission error.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

try {
  inputDevice.setKeyboardRepeatDelay(350).then(() => {
    console.log(`Set keyboard repeat delay success`);
  });
} catch (error) {
  console.error(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

inputDevice.getKeyboardRepeatDelay10+

getKeyboardRepeatDelay(callback: AsyncCallback<number>): void

Obtains the keyboard repeat delay. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.MultimodalInput.Input.InputDevice

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback used to return the keyboard repeat delay.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202SystemAPI permission error.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

try {
  inputDevice.getKeyboardRepeatDelay((error: Error, delay: Number) => {
    if (error) {
      console.error(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
      return;
    }
    console.log(`Get keyboard repeat delay success`);
  });
} catch (error) {
  console.error(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

inputDevice.getKeyboardRepeatDelay10+

getKeyboardRepeatDelay(): Promise<number>

Obtains the keyboard repeat delay. This API uses a promise to return the result.

System capability: SystemCapability.MultimodalInput.Input.InputDevice

System API: This is a system API.

Return value

TypeDescription
Promise<number>Promise used to return the keyboard repeat delay.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202SystemAPI permission error.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

try {
  inputDevice.getKeyboardRepeatDelay().then((delay: Number) => {
    console.log(`Get keyboard repeat delay success`);
  });
} catch (error) {
  console.error(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

inputDevice.setKeyboardRepeatRate10+

setKeyboardRepeatRate(rate: number, callback: AsyncCallback<void>): void

Sets the keyboard repeat rate. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.MultimodalInput.Input.InputDevice

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
ratenumberYesKeyboard repeat rate, in ms/time. The value range is [36, 100] and the default value is 50.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202SystemAPI permission error.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

try {
  inputDevice.setKeyboardRepeatRate(60, (error: Error) => {
    if (error) {
      console.error(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
      return;
    }
    console.log(`Set keyboard repeat rate success`);
  });
} catch (error) {
  console.error(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

inputDevice.setKeyboardRepeatRate10+

setKeyboardRepeatRate(rate: number): Promise<void>

Sets the keyboard repeat rate. This API uses a promise to return the result.

System capability: SystemCapability.MultimodalInput.Input.InputDevice

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
ratenumberYesKeyboard repeat rate, in ms/time. The value range is [36, 100] and the default value is 50.

Return value

TypeDescription
Promise<void>A promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202SystemAPI permission error.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

try {
  inputDevice.setKeyboardRepeatRate(60).then(() => {
    console.log(`Set keyboard repeat rate success`);
  });
} catch (error) {
  console.error(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

inputDevice.getKeyboardRepeatRate10+

getKeyboardRepeatRate(callback: AsyncCallback<number>): void

Obtains the keyboard repeat rate. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.MultimodalInput.Input.InputDevice

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback used to return the keyboard repeat rate.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202SystemAPI permission error.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

try {
  inputDevice.getKeyboardRepeatRate((error: Error, rate: Number) => {
    if (error) {
      console.error(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
      return;
    }
    console.log(`Get keyboard repeat rate success`);
  });
} catch (error) {
  console.error(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

inputDevice.getKeyboardRepeatRate10+

getKeyboardRepeatRate(): Promise<number>

Obtains the keyboard repeat rate. This API uses a promise to return the result.

System capability: SystemCapability.MultimodalInput.Input.InputDevice

System API: This is a system API.

Return value

TypeDescription
Promise<number>Promise used to return the keyboard repeat rate.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
202SystemAPI permission error.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.

Example

try {
  inputDevice.getKeyboardRepeatRate().then((rate: Number) => {
    console.log(`Get keyboard repeat rate success`);
  });
} catch (error) {
  console.error(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}

inputDevice.setInputDeviceEnabled18+

setInputDeviceEnabled(deviceId: number, enabled: boolean): Promise<void>

Sets the input switch status of an input device. Take the touchscreen as an example. If the input switch is off, the touchscreen does not respond when being touched. If the input switch is on, the touchscreen wakes up when being touched.

Required permissions: ohos.permission.INPUT_DEVICE_CONTROLLER

System capability: SystemCapability.MultimodalInput.Input.InputDevice

System API: This is a system API.

Parameters

NameTypeMandatoryDescription
deviceIdnumberYesDevice ID.
enabledbooleanYesSwitch status of the input device. The value true indicates that the input device is enabled, and the value false indicates the opposite.

Error codes

For details about the error codes, see Universal Error Codes and Input Device Error Codes.

IDError Message
201Permission denied.
202Not system application.
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed.
3900001The specified device does not exist.

Example

try {
  inputDevice.setInputDeviceEnabled(0, true).then(() => {
    console.info(`Set input device enable success`);
  });
} catch (error) {
    console.error(`Set input device enable error`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Input Kit

harmony 鸿蒙Input_DeviceListener

harmony 鸿蒙Input_InterceptorEventCallback

harmony 鸿蒙Input_AxisEvent

harmony 鸿蒙Input_DeviceInfo

harmony 鸿蒙Input_DeviceListener

harmony 鸿蒙Input_Hotkey

harmony 鸿蒙Input_InterceptorEventCallback

harmony 鸿蒙Input_InterceptorOptions

harmony 鸿蒙Input_KeyEvent

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/WayOl4