1# @ohos.multimodalInput.inputDevice (输入设备)(系统接口) 2 3<!--Kit: Input Kit--> 4<!--Subsystem: MultimodalInput--> 5<!--Owner: @zhaoxueyuan--> 6<!--Designer: @hanruofei--> 7<!--Tester: @Lyuxin--> 8<!--Adviser: @Brilliantry_Rui--> 9 10本模块提供输入设备管理能力,包括查询输入设备信息等。 11 12 13> **说明**: 14> 15> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 16> 17> 当前页面仅包含模块的系统接口,其他公开接口请参考[@ohos.multimodalInput.inputDevice (输入设备)](js-apis-inputdevice.md)。 18 19 20## 导入模块 21 22```js 23import { inputDevice } from '@kit.InputKit'; 24``` 25 26## inputDevice.setKeyboardRepeatDelay<sup>10+</sup> 27 28setKeyboardRepeatDelay(delay: number, callback: AsyncCallback<void>): void 29 30设置键盘按键的重复时延,使用Callback异步回调。 31 32**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice 33 34**系统API**:此接口为系统接口。 35 36**参数**: 37 38| 参数名 | 类型 | 必填 | 说明 | 39| -------- | ------ | ---- | ------------------------------------------------------------ | 40| delay | number | 是 | 键盘按键重复延迟时间,默认值500ms,调节范围[300ms,1000ms]。 | 41| callback | AsyncCallback<void> | 是 | 回调函数。 | 42 43**错误码**: 44 45以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 46 47| 错误码ID | 错误信息 | 48| ---- | --------------------- | 49| 202 | SystemAPI permission error. | 50| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 51 52**示例**: 53 54```js 55import { inputDevice } from '@kit.InputKit'; 56 57@Entry 58@Component 59struct Index { 60 build() { 61 RelativeContainer() { 62 Text() 63 .onClick(() => { 64 try { 65 inputDevice.setKeyboardRepeatDelay(350, (error: Error) => { 66 if (error) { 67 console.error(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 68 return; 69 } 70 console.log(`Set keyboard repeat delay success`); 71 }); 72 } catch (error) { 73 console.error(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 74 } 75 }) 76 } 77 } 78} 79``` 80 81## inputDevice.setKeyboardRepeatDelay<sup>10+</sup> 82 83setKeyboardRepeatDelay(delay: number): Promise<void> 84 85设置键盘按键的重复时延,使用Promise异步回调。 86 87**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice 88 89**系统API**:此接口为系统接口。 90 91**参数**: 92 93| 参数名 | 类型 | 必填 | 说明 | 94| ----- | ------ | ---- | ----------------------------------- | 95| delay | number | 是 | 键盘按键重复延迟时间,默认值500ms,调节范围[300ms,1000ms]。 | 96 97**返回值**: 98 99| 类型 | 说明 | 100| ------------------- | ---------------- | 101| Promise<void> | 无返回结果的Promise对象。 | 102 103**错误码**: 104 105以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 106 107| 错误码ID | 错误信息 | 108| ---- | --------------------- | 109| 202 | SystemAPI permission error. | 110| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 111 112**示例**: 113 114```js 115import { inputDevice } from '@kit.InputKit'; 116 117@Entry 118@Component 119struct Index { 120 build() { 121 RelativeContainer() { 122 Text() 123 .onClick(() => { 124 try { 125 inputDevice.setKeyboardRepeatDelay(350).then(() => { 126 console.log(`Set keyboard repeat delay success`); 127 }); 128 } catch (error) { 129 console.error(`Set keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 130 } 131 }) 132 } 133 } 134} 135``` 136 137## inputDevice.getKeyboardRepeatDelay<sup>10+</sup> 138 139getKeyboardRepeatDelay(callback: AsyncCallback<number>): void 140 141获取键盘按键的重复时延,使用Callback异步回调。 142 143**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice 144 145**系统API**:此接口为系统接口。 146 147**参数**: 148 149| 参数名 | 类型 | 必填 | 说明 | 150| -------- | ------ | ---- | ------------------------------------------------------------ | 151| callback | AsyncCallback<number> | 是 | 回调函数,返回键盘按键重复延迟时间。 | 152 153**错误码**: 154 155以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 156 157| 错误码ID | 错误信息 | 158| ---- | --------------------- | 159| 202 | SystemAPI permission error. | 160| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 161 162**示例**: 163 164```js 165import { inputDevice } from '@kit.InputKit'; 166 167@Entry 168@Component 169struct Index { 170 build() { 171 RelativeContainer() { 172 Text() 173 .onClick(() => { 174 try { 175 inputDevice.getKeyboardRepeatDelay((error: Error, delay: Number) => { 176 if (error) { 177 console.error(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 178 return; 179 } 180 console.log(`Get keyboard repeat delay success`); 181 }); 182 } catch (error) { 183 console.error(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 184 } 185 }) 186 } 187 } 188} 189``` 190 191## inputDevice.getKeyboardRepeatDelay<sup>10+</sup> 192 193getKeyboardRepeatDelay(): Promise<number> 194 195获取键盘按键的重复时延,使用Promise异步回调。 196 197**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice 198 199**系统API**:此接口为系统接口。 200 201**返回值**: 202 203| 类型 | 说明 | 204| --------------------- | ------------------- | 205| Promise<number> | Promise对象,返回键盘按键的重复时延。 | 206 207**错误码**: 208 209以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 210 211| 错误码ID | 错误信息 | 212| ---- | --------------------- | 213| 202 | SystemAPI permission error. | 214| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 215 216**示例**: 217 218```js 219import { inputDevice } from '@kit.InputKit'; 220 221@Entry 222@Component 223struct Index { 224 build() { 225 RelativeContainer() { 226 Text() 227 .onClick(() => { 228 try { 229 inputDevice.getKeyboardRepeatDelay().then((delay: Number) => { 230 console.log(`Get keyboard repeat delay success`); 231 }); 232 } catch (error) { 233 console.error(`Get keyboard repeat delay failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 234 } 235 }) 236 } 237 } 238} 239``` 240 241## inputDevice.setKeyboardRepeatRate<sup>10+</sup> 242 243setKeyboardRepeatRate(rate: number, callback: AsyncCallback<void>): void 244 245设置键盘按键的重复速率,使用Callback异步回调。 246 247**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice 248 249**系统API**:此接口为系统接口。 250 251**参数**: 252 253| 参数名 | 类型 | 必填 | 说明 | 254| -------- | ------ | ---- | ------------------------------------------------------------ | 255| rate | number | 是 | 键盘按键重复速率,默认值50ms/次,调节范围[36ms/次,100ms/次]。 | 256| callback | AsyncCallback<void> | 是 | 回调函数。 | 257 258**错误码**: 259 260以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 261 262| 错误码ID | 错误信息 | 263| ---- | --------------------- | 264| 202 | SystemAPI permission error. | 265| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 266 267**示例**: 268 269```js 270import { inputDevice } from '@kit.InputKit'; 271 272@Entry 273@Component 274struct Index { 275 build() { 276 RelativeContainer() { 277 Text() 278 .onClick(() => { 279 try { 280 inputDevice.setKeyboardRepeatRate(60, (error: Error) => { 281 if (error) { 282 console.error(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 283 return; 284 } 285 console.log(`Set keyboard repeat rate success`); 286 }); 287 } catch (error) { 288 console.error(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 289 } 290 }) 291 } 292 } 293} 294``` 295 296## inputDevice.setKeyboardRepeatRate<sup>10+</sup> 297 298setKeyboardRepeatRate(rate: number): Promise<void> 299 300设置键盘按键的重复速率,使用Promise异步回调。 301 302**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice 303 304**系统API**:此接口为系统接口。 305 306**参数**: 307 308| 参数名 | 类型 | 必填 | 说明 | 309| ----- | ------ | ---- | ----------------------------------- | 310| rate | number | 是 | 键盘按键重复速率,默认值50ms/次,调节范围[36ms/次,100ms/次]。 | 311 312**返回值**: 313 314| 类型 | 说明 | 315| ------------------- | ---------------- | 316| Promise<void> | 无返回结果的Promise对象。 | 317 318**错误码**: 319 320以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 321 322| 错误码ID | 错误信息 | 323| ---- | --------------------- | 324| 202 | SystemAPI permission error. | 325| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 326 327**示例**: 328 329```js 330import { inputDevice } from '@kit.InputKit'; 331 332@Entry 333@Component 334struct Index { 335 build() { 336 RelativeContainer() { 337 Text() 338 .onClick(() => { 339 try { 340 inputDevice.setKeyboardRepeatRate(60).then(() => { 341 console.log(`Set keyboard repeat rate success`); 342 }); 343 } catch (error) { 344 console.error(`Set keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 345 } 346 }) 347 } 348 } 349} 350``` 351 352## inputDevice.getKeyboardRepeatRate<sup>10+</sup> 353 354getKeyboardRepeatRate(callback: AsyncCallback<number>): void 355 356获取键盘按键的重复速率,使用Callback异步回调。 357 358**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice 359 360**系统API**:此接口为系统接口。 361 362**参数**: 363 364| 参数名 | 类型 | 必填 | 说明 | 365| -------- | --------------------------- | ---- | -------------- | 366| callback | AsyncCallback<number> | 是 | 回调函数,返回键盘按键的重复速率。 | 367 368**错误码**: 369 370以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 371 372| 错误码ID | 错误信息 | 373| ---- | --------------------- | 374| 202 | SystemAPI permission error. | 375| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 376 377**示例**: 378 379```js 380import { inputDevice } from '@kit.InputKit'; 381 382@Entry 383@Component 384struct Index { 385 build() { 386 RelativeContainer() { 387 Text() 388 .onClick(() => { 389 try { 390 inputDevice.getKeyboardRepeatRate((error: Error, rate: Number) => { 391 if (error) { 392 console.error(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 393 return; 394 } 395 console.log(`Get keyboard repeat rate success`); 396 }); 397 } catch (error) { 398 console.error(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 399 } 400 }) 401 } 402 } 403} 404``` 405 406## inputDevice.getKeyboardRepeatRate<sup>10+</sup> 407 408getKeyboardRepeatRate(): Promise<number> 409 410获取键盘按键的重复速率,使用Promise异步回调。 411 412**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice 413 414**系统API**:此接口为系统接口。 415 416**返回值**: 417 418| 类型 | 说明 | 419| --------------------- | ------------------- | 420| Promise<number> | Promise对象,返回键盘按键的重复速率。 | 421 422**错误码**: 423 424以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 425 426| 错误码ID | 错误信息 | 427| ---- | --------------------- | 428| 202 | SystemAPI permission error. | 429| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 430 431**示例**: 432 433```js 434import { inputDevice } from '@kit.InputKit'; 435 436@Entry 437@Component 438struct Index { 439 build() { 440 RelativeContainer() { 441 Text() 442 .onClick(() => { 443 try { 444 inputDevice.getKeyboardRepeatRate().then((rate: Number) => { 445 console.log(`Get keyboard repeat rate success`); 446 }); 447 } catch (error) { 448 console.error(`Get keyboard repeat rate failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 449 } 450 }) 451 } 452 } 453} 454``` 455 456## inputDevice.setInputDeviceEnabled<sup>18+</sup> 457 458setInputDeviceEnabled(deviceId: number, enabled: boolean): Promise<void> 459 460设置输入设备的开关状态。以触摸屏为例:关闭时,点击触摸屏设备不响应;开启时,可正常操作触摸屏。 461 462**需要权限**:ohos.permission.INPUT_DEVICE_CONTROLLER 463 464**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice 465 466**系统API**:此接口为系统接口。 467 468**参数**: 469 470| 参数名 | 类型 | 必填 | 说明 | 471| -------- | ------- | ---- | ------------------------- | 472| deviceId | number | 是 | 目标设备Id。 | 473| enabled | boolean | 是 | 输入设备的开关状态,取值为true表示开启输入设备,取值为false表示关闭输入设备。 | 474 475**错误码**: 476 477以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[模块错误码](errorcode-inputdevice.md)。 478 479 480| 错误码ID | 错误信息 | 481| -------- | ------------------------------------------------------------ | 482| 201 | Permission denied. | 483| 202 | Not system application. | 484| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified;2. Incorrect parameter types; 3. Parameter verification failed. | 485| 3900001 | The specified device does not exist. | 486 487**示例**: 488 489```js 490import { inputDevice } from '@kit.InputKit'; 491 492@Entry 493@Component 494struct Index { 495 build() { 496 RelativeContainer() { 497 Text() 498 .onClick(() => { 499 try { 500 inputDevice.setInputDeviceEnabled(0, true).then(() => { 501 console.info(`Set input device enable success`); 502 }); 503 } catch (error) { 504 console.error(`Set input device enable error`); 505 } 506 }) 507 } 508 } 509} 510``` 511