1# @ohos.inputMethod (输入法框架) 2 3本模块主要面向普通前台应用(备忘录、信息、设置等系统应用与三方应用),提供对输入法(输入法应用)的控制、管理能力,包括显示/隐藏输入法软键盘、切换输入法、获取所有输入法列表等等。 4 5> **说明:** 6> 7> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9 10## 导入模块 11 12```ts 13import { inputMethod } from '@kit.IMEKit'; 14``` 15 16## 常量 17 18常量值。 19 20**系统能力:** SystemCapability.MiscServices.InputMethodFramework 21 22| 参数名 | 类型 | 常量值 | 说明 | 23| -------- | -------- | -------- | -------- | 24| MAX_TYPE_NUM<sup>8+</sup> | number | 128 | 可支持的最大输入法个数。 | 25 26## InputMethodProperty<sup>8+</sup> 27 28输入法应用属性。 29 30**系统能力:** SystemCapability.MiscServices.InputMethodFramework 31 32| 名称 | 类型 | 只读 | 可选 | 说明 | 33| -------- | -------- | -------- | -------- | -------- | 34| name<sup>9+</sup> | string | 是 | 否 | 必填。输入法包名。| 35| id<sup>9+</sup> | string | 是 | 否 | 必填。输入法扩展在应用内唯一标识,与name一起组成输入法扩展的全局唯一标识。| 36| label<sup>9+</sup> | string | 是 | 是 | 非必填。输入法扩展对外显示名称。优先使用InputmethodExtensionAbility中配置的label,若未配置,自动使用应用入口ability的label,当应用入口ability未配置label时,自动使用应用AppScope中配置的label。| 37| labelId<sup>10+</sup> | number | 是 | 是 | 非必填。输入法对外显示名称资源号。| 38| icon<sup>9+</sup> | string | 是 | 是 | 非必填。输入法图标数据,可以通过iconId查询获取。预留字段,暂不支持使用。| 39| iconId<sup>9+</sup> | number | 是 | 是 | 非必填。输入法图标资源号。 | 40| extra<sup>9+</sup> | object | 否 | 是 | 输入法扩展信息。预留字段,当前无具体含义,暂不支持使用。<br/>- API version 10起:非必填;<br/>- API version 9:必填。| 41| packageName<sup>(deprecated)</sup> | string | 是 | 否 | 输入法包名。必填。<br/>说明:从API version 8开始支持,从API version 9开始废弃,建议使用name替代。 | 42| methodId<sup>(deprecated)</sup> | string | 是 | 否 | 输入法唯一标识。必填。<br/>说明:从API version 8开始支持,从API version 9开始废弃,建议使用id替代。 | 43 44## inputMethod.getController<sup>9+</sup> 45 46getController(): InputMethodController 47 48获取客户端实例[InputMethodController](#inputmethodcontroller)。 49 50**系统能力:** SystemCapability.MiscServices.InputMethodFramework 51 52**返回值:** 53 54| 类型 | 说明 | 55| ----------------------------------------------- | ---------------------- | 56| [InputMethodController](#inputmethodcontroller) | 返回当前客户端实例。 | 57 58**错误码:** 59 60以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 61 62| 错误码ID | 错误信息 | 63| -------- | ------------------------------ | 64| 12800006 | input method controller error. | 65 66**示例:** 67 68```ts 69let inputMethodController = inputMethod.getController(); 70``` 71 72## inputMethod.getDefaultInputMethod<sup>11+</sup> 73 74getDefaultInputMethod(): InputMethodProperty 75 76获取默认输入法。 77 78**系统能力:** SystemCapability.MiscServices.InputMethodFramework 79 80**返回值:** 81 82| 类型 | 说明 | 83| -------------------------------------------- | ------------------------ | 84| [InputMethodProperty](#inputmethodproperty8) | 返回默认输入法属性对象。 | 85 86**错误码:** 87 88以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 89 90| 错误码ID | 错误信息 | 91| -------- | -------------------------------------- | 92| 12800008 | input method manager service error. | 93 94**示例:** 95 96```ts 97try { 98 let defaultIme = inputMethod.getDefaultInputMethod(); 99} catch(err) { 100 console.error(`Failed to getDefaultInputMethod: ${JSON.stringify(err)}`); 101} 102``` 103 104## inputMethod.getSystemInputMethodConfigAbility<sup>11+</sup> 105 106getSystemInputMethodConfigAbility(): ElementName 107 108获取系统输入法设置界面Ability信息。 109 110**系统能力:** SystemCapability.MiscServices.InputMethodFramework 111 112**返回值:** 113 114| 类型 | 说明 | 115| -------------------------------------------- | ------------------------ | 116| [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md) | 系统输入法设置界面Ability的ElementName。 | 117 118**错误码:** 119 120以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 121 122| 错误码ID | 错误信息 | 123| -------- | -------------------------------------- | 124| 12800008 | input method manager service error. | 125 126**示例:** 127 128```ts 129try { 130 let inputMethodConfig = inputMethod.getSystemInputMethodConfigAbility(); 131} catch(err) { 132 console.error(`Failed to get getSystemInputMethodConfigAbility: ${JSON.stringify(err)}`); 133} 134``` 135 136## inputMethod.getSetting<sup>9+</sup> 137 138getSetting(): InputMethodSetting 139 140获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)。 141 142**系统能力:** SystemCapability.MiscServices.InputMethodFramework 143 144**返回值:** 145 146| 类型 | 说明 | 147| ----------------------------------------- | -------------------------- | 148| [InputMethodSetting](#inputmethodsetting8) | 返回当前客户端设置实例。 | 149 150**错误码:** 151 152以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 153 154| 错误码ID | 错误信息 | 155| -------- | -------------------------------------- | 156| 12800007 | setter error. | 157 158**示例:** 159 160```ts 161let inputMethodSetting = inputMethod.getSetting(); 162``` 163 164## inputMethod.switchInputMethod<sup>9+</sup> 165 166switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolean>): void 167 168切换输入法,使用callback异步回调。 169> **说明:** 170> 171> - 在API version 9-10版本,仅支持系统应用调用且需要权限ohos.permission.CONNECT_IME_ABILITY。 172> - 在API version 11版本起,仅支持当前输入法应用调用。 173 174**系统能力:** SystemCapability.MiscServices.InputMethodFramework 175 176**参数:** 177 178| 参数名 | 类型 | 必填 | 说明 | 179| -------- | -------- | -------- | -------- | 180| target | [InputMethodProperty](#inputmethodproperty8) | 是 | 目标输入法。 | 181| callback | AsyncCallback<boolean> | 是 | 回调函数。当输入法切换成功,err为undefined,data为true;否则为错误对象。 | 182 183**错误码:** 184 185以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 186 187| 错误码ID | 错误信息 | 188| -------- | -------------------------------------- | 189| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 190| 12800005 | configuration persistence error. | 191| 12800008 | input method manager service error. | 192 193**示例:** 194 195```ts 196import { BusinessError } from '@kit.BasicServicesKit'; 197 198let currentIme = inputMethod.getCurrentInputMethod(); 199try{ 200 inputMethod.switchInputMethod(currentIme, (err: BusinessError, result: boolean) => { 201 if (err) { 202 console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); 203 return; 204 } 205 if (result) { 206 console.log('Succeeded in switching inputmethod.'); 207 } else { 208 console.error('Failed to switchInputMethod.'); 209 } 210 }); 211} catch(err) { 212 console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); 213} 214``` 215 216> **说明:** 217> 218> 在 api11 中 ` 201 permissions check fails.` 这个错误码被移除。 219 220## inputMethod.switchInputMethod<sup>9+</sup> 221switchInputMethod(target: InputMethodProperty): Promise<boolean> 222 223切换输入法,使用promise异步回调。 224> **说明:** 225> 226> - 在API version 9-10版本,仅支持系统应用调用且需要权限ohos.permission.CONNECT_IME_ABILITY。 227> - 在API version 11版本起,仅支持当前输入法应用调用。 228 229**系统能力:** SystemCapability.MiscServices.InputMethodFramework 230 231**参数:** 232 233 | 参数名 | 类型 | 必填 | 说明 | 234 | -------- | -------- | -------- | -------- | 235 |target | [InputMethodProperty](#inputmethodproperty8)| 是 | 目标输入法。 | 236 237**返回值:** 238 239 | 类型 | 说明 | 240 | ----------------------------------------- | ---------------------------- | 241 | Promise\<boolean> | Promise对象。返回true表示切换输入法成功,返回false表示切换输入法失败。 | 242 243**错误码:** 244 245以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 246 247| 错误码ID | 错误信息 | 248| -------- | -------------------------------------- | 249| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 250| 12800005 | configuration persistence error. | 251| 12800008 | input method manager service error. | 252 253**示例:** 254 255```ts 256import { BusinessError } from '@kit.BasicServicesKit'; 257 258let currentIme = inputMethod.getCurrentInputMethod(); 259try { 260 inputMethod.switchInputMethod(currentIme).then((result: boolean) => { 261 if (result) { 262 console.log('Succeeded in switching inputmethod.'); 263 } else { 264 console.error('Failed to switchInputMethod.'); 265 } 266 }).catch((err: BusinessError) => { 267 console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); 268 }) 269} catch (err) { 270 console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); 271} 272``` 273 274> **说明:** 275> 276> 在 api11 中 ` 201 permissions check fails.` 这个错误码被移除。 277 278## inputMethod.getCurrentInputMethod<sup>9+</sup> 279 280getCurrentInputMethod(): InputMethodProperty 281 282使用同步方法获取当前输入法。 283 284**系统能力:** SystemCapability.MiscServices.InputMethodFramework 285 286**返回值:** 287 288| 类型 | 说明 | 289| -------------------------------------------- | ------------------------ | 290| [InputMethodProperty](#inputmethodproperty8) | 返回当前输入法属性对象。 | 291 292**示例:** 293 294```ts 295let currentIme = inputMethod.getCurrentInputMethod(); 296``` 297 298## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup> 299 300switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback\<boolean>): void 301 302切换当前输入法的子类型。使用callback异步回调。 303 304> **说明:** 305> 306> - 在API version 9版本,仅支持系统应用调用且需要权限ohos.permission.CONNECT_IME_ABILITY。 307> - 在API version 10版本,支持系统应用和当前输入法应用调用;需要权限ohos.permission.CONNECT_IME_ABILITY。 308> - 在API version 11版本起,仅支持当前输入法调用。 309 310**系统能力:** SystemCapability.MiscServices.InputMethodFramework 311 312**参数:** 313 314| 参数名 | 类型 | 必填 | 说明 | 315| -------- | -------- | -------- | -------- | 316| target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 目标输入法子类型。 | 317| callback | AsyncCallback<boolean> | 是 | 回调函数。当输入法子类型切换成功,err为undefined,data为true;否则为错误对象。| 318 319**错误码:** 320 321以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 322 323| 错误码ID | 错误信息 | 324| -------- | -------------------------------------- | 325| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 326| 12800005 | configuration persistence error. | 327| 12800008 | input method manager service error. | 328 329**示例:** 330 331```ts 332import { BusinessError } from '@kit.BasicServicesKit'; 333 334try { 335 let extra: Record<string, string> = {} 336 inputMethod.switchCurrentInputMethodSubtype({ 337 id: "ServiceExtAbility", 338 label: "", 339 name: "com.example.kikakeyboard", 340 mode: "upper", 341 locale: "", 342 language: "", 343 icon: "", 344 iconId: 0, 345 extra: extra 346 }, (err: BusinessError, result: boolean) => { 347 if (err) { 348 console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 349 return; 350 } 351 if (result) { 352 console.log('Succeeded in switching currentInputMethodSubtype.'); 353 } else { 354 console.error('Failed to switchCurrentInputMethodSubtype'); 355 } 356 }); 357} catch(err) { 358 console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 359} 360``` 361 362> **说明:** 363> 364> 在 api11 中 ` 201 permissions check fails.` 这个错误码被移除。 365 366## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup> 367 368switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean> 369 370切换当前输入法的子类型。使用promise异步回调。 371 372> **说明:** 373> 374> - 在API version 9版本,仅支持系统应用调用且需要权限ohos.permission.CONNECT_IME_ABILITY。 375> - 在API version 10版本,支持系统应用和当前输入法应用调用;需要权限ohos.permission.CONNECT_IME_ABILITY。 376> - 在API version 11版本起,仅支持当前输入法调用。 377 378**系统能力:** SystemCapability.MiscServices.InputMethodFramework 379 380**参数:** 381 382| 参数名 | 类型 | 必填 | 说明 | 383| -------- | -------- | -------- | -------- | 384|target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 目标输入法子类型。 | 385 386**返回值:** 387 388| 类型 | 说明 | 389| ----------------------------------------- | ---------------------------- | 390| Promise\<boolean> | Promise对象。返回true表示当前输入法切换子类型成功,返回false表示当前输入法切换子类型成功失败。 | 391 392**错误码:** 393 394以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 395 396| 错误码ID | 错误信息 | 397| -------- | -------------------------------------- | 398| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 399| 12800005 | configuration persistence error. | 400| 12800008 | input method manager service error. | 401 402**示例:** 403 404```ts 405import { BusinessError } from '@kit.BasicServicesKit'; 406 407try { 408 let extra: Record<string, string> = {} 409 inputMethod.switchCurrentInputMethodSubtype({ 410 id: "ServiceExtAbility", 411 label: "", 412 name: "com.example.kikakeyboard", 413 mode: "upper", 414 locale: "", 415 language: "", 416 icon: "", 417 iconId: 0, 418 extra: extra 419 }).then((result: boolean) => { 420 if (result) { 421 console.log('Succeeded in switching currentInputMethodSubtype.'); 422 } else { 423 console.error('Failed to switchCurrentInputMethodSubtype.'); 424 } 425 }).catch((err: BusinessError) => { 426 console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 427 }) 428} catch(err) { 429 console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 430} 431``` 432 433> **说明:** 434> 435> 在 api11 中 ` 201 permissions check fails.` 这个错误码被移除。 436 437## inputMethod.getCurrentInputMethodSubtype<sup>9+</sup> 438 439getCurrentInputMethodSubtype(): InputMethodSubtype 440 441获取当前输入法的子类型。 442 443**系统能力:** SystemCapability.MiscServices.InputMethodFramework 444 445**返回值:** 446 447| 类型 | 说明 | 448| -------------------------------------------- | ------------------------ | 449| [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype) | 返回当前输入法子类型对象。 | 450 451**示例:** 452 453```ts 454let currentImeSubType = inputMethod.getCurrentInputMethodSubtype(); 455``` 456 457## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup> 458 459switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback\<boolean>): void 460 461切换至指定输入法的指定子类型,适用于跨输入法切换子类型。使用callback异步回调。 462 463> **说明:** 464> 465> - 在API version 9-10版本,仅支持系统应用调用且需要权限ohos.permission.CONNECT_IME_ABILITY。 466> - 在API version 11版本起,仅支持当前输入法调用。 467 468**系统能力:** SystemCapability.MiscServices.InputMethodFramework 469 470**参数:** 471 472| 参数名 | 类型 | 必填 | 说明 | 473| -------- | -------- | -------- | -------- | 474|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 目标输入法。 | 475|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 目标输入法子类型。 | 476| callback | AsyncCallback<boolean> | 是 | 回调函数。当输入法和子类型切换成功,err为undefined,data为获取到的切换子类型结果true;否则为错误对象。 | 477 478**错误码:** 479 480以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 481 482| 错误码ID | 错误信息 | 483| -------- | -------------------------------------- | 484| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 485| 12800005 | configuration persistence error. | 486| 12800008 | input method manager service error. | 487 488**示例:** 489 490```ts 491import { BusinessError } from '@kit.BasicServicesKit'; 492 493let currentIme = inputMethod.getCurrentInputMethod(); 494let imSubType = inputMethod.getCurrentInputMethodSubtype(); 495try { 496 inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err: BusinessError, result: boolean) => { 497 if (err) { 498 console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); 499 return; 500 } 501 if (result) { 502 console.log('Succeeded in switching currentInputMethodAndSubtype.'); 503 } else { 504 console.error('Failed to switchCurrentInputMethodAndSubtype.'); 505 } 506 }); 507} catch (err) { 508 console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); 509} 510``` 511 512> **说明:** 513> 514> 在 api11 中 ` 201 permissions check fails.` 这个错误码被移除。 515 516## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup> 517 518switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise<boolean> 519 520切换至指定输入法的指定子类型,适用于跨输入法切换子类型。使用promise异步回调。 521 522> **说明:** 523> 524> - 在API version 9-10版本,仅支持系统应用调用且需要权限ohos.permission.CONNECT_IME_ABILITY。 525> - 在API version 11版本起,仅支持当前输入法调用。 526 527**系统能力:** SystemCapability.MiscServices.InputMethodFramework 528 529**参数:** 530 531| 参数名 | 类型 | 必填 | 说明 | 532| -------- | -------- | -------- | -------- | 533|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 目标输入法。 | 534|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| 是 | 目标输入法子类型。 | 535 536**返回值:** 537 538| 类型 | 说明 | 539| ----------------------------------------- | ---------------------------- | 540| Promise\<boolean> | Promise对象。返回true表示切换至指定输入法的指定子类型成功,返回false表示切换至指定输入法的指定子类型失败。 | 541 542**错误码:** 543 544以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 545 546| 错误码ID | 错误信息 | 547| -------- | -------------------------------------- | 548| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 549| 12800005 | configuration persistence error. | 550| 12800008 | input method manager service error. | 551 552**示例:** 553 554```ts 555import { BusinessError } from '@kit.BasicServicesKit'; 556 557let currentIme = inputMethod.getCurrentInputMethod(); 558let imSubType = inputMethod.getCurrentInputMethodSubtype(); 559try { 560 inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType).then((result: boolean) => { 561 if (result) { 562 console.log('Succeeded in switching currentInputMethodAndSubtype.'); 563 } else { 564 console.error('Failed to switchCurrentInputMethodAndSubtype.'); 565 } 566 }).catch((err: BusinessError) => { 567 console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); 568 }) 569} catch(err) { 570 console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); 571} 572``` 573 574> **说明:** 575> 576> 在 api11 中 ` 201 permissions check fails.` 这个错误码被移除。 577 578## inputMethod.getInputMethodController<sup>(deprecated)</sup> 579 580getInputMethodController(): InputMethodController 581 582获取客户端实例[InputMethodController](#inputmethodcontroller)。 583 584> **说明:** 585> 586> 从API version 6开始支持,从API version 9开始废弃,建议使用[getController()](#inputmethodgetcontroller9)替代。 587 588**系统能力:** SystemCapability.MiscServices.InputMethodFramework 589 590**返回值:** 591 592| 类型 | 说明 | 593| ----------------------------------------------- | ------------------------ | 594| [InputMethodController](#inputmethodcontroller) | 回调返回当前客户端实例。 | 595 596**示例:** 597 598```ts 599let inputMethodController = inputMethod.getInputMethodController(); 600``` 601 602## inputMethod.getInputMethodSetting<sup>(deprecated)</sup> 603 604getInputMethodSetting(): InputMethodSetting 605 606获取客户端设置实例[InputMethodSetting](#inputmethodsetting8)。 607 608> **说明:** 609> 610> 从API version 6开始支持,从API version 9开始废弃,建议使用[getSetting()](#inputmethodgetsetting9)替代。 611 612**系统能力:** SystemCapability.MiscServices.InputMethodFramework 613 614**返回值:** 615 616| 类型 | 说明 | 617| ----------------------------------------- | -------------------------- | 618| [InputMethodSetting](#inputmethodsetting8) | 返回当前客户端设置实例。 | 619 620**示例:** 621 622```ts 623let inputMethodSetting = inputMethod.getInputMethodSetting(); 624``` 625 626## TextInputType<sup>10+</sup> 627 628文本输入类型。 629 630**系统能力:** SystemCapability.MiscServices.InputMethodFramework 631 632| 名称 | 值 |说明 | 633| -------- | -------- |-------- | 634| NONE | -1 |NONE。 | 635| TEXT | 0 |文本类型。 | 636| MULTILINE | 1 |多行类型。 | 637| NUMBER | 2 |数字类型。 | 638| PHONE | 3 |电话号码类型。 | 639| DATETIME | 4 |日期类型。 | 640| EMAIL_ADDRESS | 5 |邮箱地址类型。 | 641| URL | 6 |链接类型。 | 642| VISIBLE_PASSWORD | 7 |密码类型。 | 643| NUMBER_PASSWORD<sup>11+</sup> | 8 |数字密码类型。 | 644 645## EnterKeyType<sup>10+</sup> 646 647Enter键的功能类型。 648 649**系统能力:** SystemCapability.MiscServices.InputMethodFramework 650 651| 名称 | 值 |说明 | 652| -------- | -------- |-------- | 653| UNSPECIFIED | 0 |未指定。 | 654| NONE | 1 |NONE。 | 655| GO | 2 |前往。 | 656| SEARCH | 3 |查找。 | 657| SEND | 4 |发送。 | 658| NEXT | 5 |下一步。 | 659| DONE | 6 |完成。 | 660| PREVIOUS | 7 |上一步。 | 661| NEWLINE<sup>12+</sup> | 8 | 换行。| 662 663## KeyboardStatus<sup>10+</sup> 664 665输入法软键盘状态。 666 667**系统能力:** SystemCapability.MiscServices.InputMethodFramework 668 669| 名称 | 值 |说明 | 670| -------- | -------- |-------- | 671| NONE | 0 |NONE。 | 672| HIDE | 1 |隐藏状态。 | 673| SHOW | 2 |显示状态。 | 674 675## Direction<sup>10+</sup> 676 677光标移动方向。 678 679**系统能力:** SystemCapability.MiscServices.InputMethodFramework 680 681| 名称 | 值 |说明 | 682| -------- | -------- |-------- | 683| CURSOR_UP | 1 |向上。 | 684| CURSOR_DOWN | 2 |向下。 | 685| CURSOR_LEFT | 3 |向左。 | 686| CURSOR_RIGHT | 4 |向右。 | 687 688## ExtendAction<sup>10+</sup> 689 690编辑框中文本的扩展编辑操作类型,如剪切、复制等。 691 692**系统能力:** SystemCapability.MiscServices.InputMethodFramework 693 694| 名称 | 值 |说明 | 695| -------- | -------- |-------- | 696| SELECT_ALL | 0 |全选。 | 697| CUT | 3 |剪切。 | 698| COPY | 4 |复制。 | 699| PASTE | 5 |粘贴。 | 700 701## FunctionKey<sup>10+</sup> 702 703输入法功能键类型。 704 705**系统能力:** SystemCapability.MiscServices.InputMethodFramework 706 707| 名称 | 类型 | 只读 | 可选 | 说明 | 708| -------- | -------- | -------- | -------- | -------- | 709| enterKeyType<sup>10+</sup> | [EnterKeyType](#enterkeytype10) | 否 | 否 | 输入法enter键类型。| 710 711## InputAttribute<sup>10+</sup> 712 713编辑框属性,包含文本输入类型和Enter键功能类型。 714 715**系统能力:** SystemCapability.MiscServices.InputMethodFramework 716 717| 名称 | 类型 | 只读 | 可选 | 说明 | 718| -------- | -------- | -------- | -------- | -------- | 719| textInputType<sup>10+</sup> | [TextInputType](#textinputtype10) | 否 | 否 | 文本输入类型。| 720| enterKeyType<sup>10+</sup> | [EnterKeyType](#enterkeytype10) | 否 | 否 | Enter键功能类型。| 721 722## TextConfig<sup>10+</sup> 723 724编辑框的配置信息。 725 726**系统能力:** SystemCapability.MiscServices.InputMethodFramework 727 728| 名称 | 类型 | 只读 | 可选 | 说明 | 729| -------- | -------- | -------- | -------- | -------- | 730| inputAttribute<sup>10+</sup> | [InputAttribute](#inputattribute10) | 否 | 否 | 编辑框属性。| 731| cursorInfo<sup>10+</sup> | [CursorInfo](#cursorinfo10) | 否 | 是 | 光标信息。| 732| selection<sup>10+</sup> | [Range](#range10) | 否 | 是 | 文本选中的范围。| 733| windowId<sup>10+</sup> | number | 否 | 是 | 编辑框所在的窗口Id。| 734 735## CursorInfo<sup>10+</sup> 736 737光标信息。 738 739**系统能力:** SystemCapability.MiscServices.InputMethodFramework 740 741| 名称 | 类型 | 只读 | 可选 | 说明 | 742| -------- | -------- | -------- | -------- | -------- | 743| left | number | 否 | 否 | 光标的left坐标。| 744| top | number | 否 | 否 | 光标的top坐标。| 745| width | number | 否 | 否 | 光标的宽度。| 746| height | number | 否 | 否 | 光标的高度。| 747 748## Range<sup>10+</sup> 749 750文本的选中范围。 751 752**系统能力:** SystemCapability.MiscServices.InputMethodFramework 753 754| 名称 | 类型 | 只读 | 可选 | 说明 | 755| -------- | -------- | -------- | -------- | -------- | 756| start | number | 否 | 否 | 选中文本的首字符在编辑框的索引值。| 757| end | number | 否 | 否 | 选中文本的末字符在编辑框的索引值。| 758 759## Movement<sup>10+</sup> 760 761选中文本时,光标移动的方向。 762 763**系统能力:** SystemCapability.MiscServices.InputMethodFramework 764 765| 名称 | 类型 | 只读 | 可选 | 说明 | 766| -------- | -------- | -------- | -------- | -------- | 767| direction | [Direction](#direction10) | 否 | 否 | 选中文本时,光标的移动方向。| 768 769## InputWindowInfo<sup>10+</sup> 770 771输入法软键盘的窗口信息。 772 773**系统能力:** SystemCapability.MiscServices.InputMethodFramework 774 775| 名称 | 类型 | 只读 | 可选 | 说明 | 776| -------- | -------- | -------- | -------- | -------- | 777| name | string | 否 | 否 | 输入法窗口的名称。| 778| left | number | 否 | 否 | 输入法窗口左上顶点的横坐标,单位为px。| 779| top | number | 否 | 否 | 输入法窗口左上顶点的纵坐标,单位为px。| 780| width | number | 否 | 否 | 输入法窗口的宽度,单位为px。| 781| height | number | 否 | 否 | 输入法窗口的高度,单位为px。| 782 783## EnabledState<sup>15+</sup> 784 785输入法启用状态。 786 787**系统能力:** SystemCapability.MiscServices.InputMethodFramework 788 789| 名称 | 值 |说明 | 790| -------- | -------- |-------- | 791| DISABLED | 0 |未启用。 | 792| BASIC_MODE | 1 |基础模式。 | 793| FULL_EXPERIENCE_MODE | 2 |完整体验模式。 | 794 795## RequestKeyboardReason<sup>15+</sup> 796 797请求键盘输入原因。 798 799**系统能力:** SystemCapability.MiscServices.InputMethodFramework 800 801| 名称 | 值 |说明 | 802| -------- | -------- |-------- | 803| NONE | 0 |表示没有特定的原因触发键盘请求。 | 804| MOUSE | 1 |表示键盘请求是由鼠标操作触发的。 | 805| TOUCH | 2 |表示键盘请求是由触摸操作触发的。 | 806| OTHER | 20 |表示键盘请求是由其他原因触发的。 | 807 808## MessageHandler<sup>15+</sup> 809 810自定义通信对象。 811 812> **说明** 813> 814> 开发者可通过注册此对象来接收输入法应用发送的自定义通信数据,接收到自定义通信数据时会触发此对象中[onMessage](#onmessage15)回调函数。 815> 816> 此对象全局唯一,多次注册仅保留最后一次注册的对象及有效性,并触发上一个已注册对象的[onTerminated](#onterminated15)回调函数。 817> 818> 若取消注册全局已注册的对象时,会触发被取消对象中[onTerminated](#onterminated15)回调函数。 819 820### onMessage<sup>15+</sup> 821 822onMessage(msgId: string, msgParam?: ArrayBuffer): void 823 824接收输入法应用发送的自定义数据回调函数。 825 826> **说明** 827> 828> 当已注册的MeesageHandler接收到来自输入法应用发送的自定义通信数据时,会触发该回调函数。 829> 830> msgId为必选参数,msgParam为可选参数。存在收到仅有msgId自定义数据的可能,需与数据发送方确认自定义数据。 831 832**系统能力:** SystemCapability.MiscServices.InputMethodFramework 833 834**参数:** 835 836| 参数名 | 类型 | 必填 | 说明 | 837| -------- | ----------- | ---- | -------------------------------- | 838| msgId | string | 是 | 接收到的自定义通信数据的标识符。 | 839| msgParam | ArrayBuffer | 否 | 接收到的自定义通信数据的消息体。 | 840 841**示例:** 842 843```ts 844import { BusinessError } from '@kit.BasicServicesKit'; 845 846let inputMethodController = inputMethod.getController(); 847try { 848 let messageHandler: inputMethod.MessageHandler = { 849 onTerminated(): void { 850 console.log('OnTerminated.'); 851 }, 852 onMessage(msgId: string, msgParam?:ArrayBuffer): void { 853 console.log('recv message.'); 854 } 855 } 856 inputMethodController.recvMessage(messageHandler); 857} catch(err) { 858 console.error(`Failed to recvMessage: ${JSON.stringify(err)}`); 859} 860``` 861 862### onTerminated<sup>15+</sup> 863 864onTerminated(): void 865 866监听对象终止回调函数。 867 868> **说明** 869> 870> 当应用注册新的MessageHandler对象时,会触发上一个已注册MessageHandler对象的OnTerminated回调函数。 871> 872> 当应用取消注册时,会触发当前已注册MessageHandler对象的OnTerminated回调函数。 873 874**系统能力:** SystemCapability.MiscServices.InputMethodFramework 875 876**示例:** 877 878```ts 879import { BusinessError } from '@kit.BasicServicesKit'; 880 881let inputMethodController = inputMethod.getController(); 882try { 883 let messageHandler: inputMethod.MessageHandler = { 884 onTerminated(): void { 885 console.log('OnTerminated.'); 886 }, 887 onMessage(msgId: string, msgParam?:ArrayBuffer): void { 888 console.log('recv message.'); 889 } 890 } 891 inputMethodController.recvMessage(messageHandler); 892} catch(err) { 893 console.error(`Failed to recvMessage: ${JSON.stringify(err)}`); 894} 895``` 896 897## InputMethodController 898 899下列API示例中都需使用[getController](#inputmethodgetcontroller9)获取到InputMethodController实例,再通过实例调用对应方法。 900 901### attach<sup>10+</sup> 902 903attach(showKeyboard: boolean, textConfig: TextConfig, callback: AsyncCallback<void>): void 904 905自绘控件绑定输入法。使用callback异步回调。 906 907> **说明** 908> 909> 需要先调用此接口,完成自绘控件与输入法的绑定,才能使用以下功能:显示/隐藏键盘、更新光标信息、更改编辑框选中范围、保存配置信息、监听处理由输入法应用发送的信息或命令等。 910 911**系统能力:** SystemCapability.MiscServices.InputMethodFramework 912 913**参数:** 914 915| 参数名 | 类型 | 必填 | 说明 | 916| -------- | -------- | -------- | -------- | 917| showKeyboard | boolean | 是 | 绑定输入法成功后,是否拉起输入法键盘。<br>- true表示拉起。<br>- false表示不拉起。 | 918| textConfig | [TextConfig](#textconfig10) | 是 | 编辑框的配置信息。 | 919| callback | AsyncCallback<void> | 是 | 回调函数。当绑定输入法成功后,err为undefined;否则为错误对象。 | 920 921**错误码:** 922 923以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 924 925| 错误码ID | 错误信息 | 926| -------- | -------------------------------------- | 927| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 928| 12800003 | input method client error. | 929| 12800008 | input method manager service error. | 930 931**示例:** 932 933```ts 934import { BusinessError } from '@kit.BasicServicesKit'; 935 936try { 937 let textConfig: inputMethod.TextConfig = { 938 inputAttribute: { 939 textInputType: 0, 940 enterKeyType: 1 941 } 942 }; 943 inputMethodController.attach(true, textConfig, (err: BusinessError) => { 944 if (err) { 945 console.error(`Failed to attach: ${JSON.stringify(err)}`); 946 return; 947 } 948 console.log('Succeeded in attaching the inputMethod.'); 949 }); 950} catch(err) { 951 console.error(`Failed to attach: ${JSON.stringify(err)}`); 952} 953``` 954 955### attach<sup>10+</sup> 956 957attach(showKeyboard: boolean, textConfig: TextConfig): Promise<void> 958 959自绘控件绑定输入法。使用promise异步回调。 960 961> **说明** 962> 963> 需要先调用此接口,完成自绘控件与输入法的绑定,才能使用以下功能:显示/隐藏键盘、更新光标信息、更改编辑框选中范围、保存配置信息、监听处理由输入法应用发送的信息或命令等。 964 965**系统能力:** SystemCapability.MiscServices.InputMethodFramework 966 967**参数:** 968 969| 参数名 | 类型 | 必填 | 说明 | 970| -------- | -------- | -------- | -------- | 971| showKeyboard | boolean | 是 | 绑定输入法成功后,是否拉起输入法键盘。<br>- true表示拉起。<br>- false表示不拉起。| 972| textConfig | [TextConfig](#textconfig10) | 是 | 编辑框的配置信息。 | 973 974**返回值:** 975 976| 类型 | 说明 | 977| -------- | -------- | 978| Promise<void> | 无返回结果的Promise对象。 | 979 980**错误码:** 981 982以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 983 984| 错误码ID | 错误信息 | 985| -------- | -------------------------------------- | 986| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 987| 12800003 | input method client error. | 988| 12800008 | input method manager service error. | 989 990**示例:** 991 992```ts 993import { BusinessError } from '@kit.BasicServicesKit'; 994 995try { 996 let textConfig: inputMethod.TextConfig = { 997 inputAttribute: { 998 textInputType: 0, 999 enterKeyType: 1 1000 } 1001 }; 1002 inputMethodController.attach(true, textConfig).then(() => { 1003 console.log('Succeeded in attaching inputMethod.'); 1004 }).catch((err: BusinessError) => { 1005 console.error(`Failed to attach: ${JSON.stringify(err)}`); 1006 }) 1007} catch(err) { 1008 console.error(`Failed to attach: ${JSON.stringify(err)}`); 1009} 1010``` 1011 1012### attach<sup>15+</sup> 1013 1014attach(showKeyboard: boolean, textConfig: TextConfig, requestKeyboardReason: RequestKeyboardReason): Promise<void> 1015 1016自绘控件绑定输入法。使用promise异步回调。 1017 1018> **说明:** 1019> 1020> 需要先调用此接口,完成自绘控件与输入法的绑定,才能使用以下功能:显示/隐藏键盘、更新光标信息、更改编辑框选中范围、保存配置信息、监听处理由输入法应用发送的信息或命令等。 1021 1022**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1023 1024**参数:** 1025 1026| 参数名 | 类型 | 必填 | 说明 | 1027| -------- | -------- | -------- | -------- | 1028| showKeyboard | boolean | 是 | 绑定输入法成功后,是否拉起输入法键盘。<br>- true表示拉起。<br>- false表示不拉起。| 1029| textConfig | [TextConfig](#textconfig10) | 是 | 编辑框的配置信息。 | 1030| requestKeyboardReason | [RequestKeyboardReason](#requestkeyboardreason15) | 是 | 请求键盘输入原因。 | 1031 1032**返回值:** 1033 1034| 类型 | 说明 | 1035| -------- | -------- | 1036| Promise<void> | 无返回结果的Promise对象。 | 1037 1038**错误码:** 1039 1040以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)和[通用错误码说明文档](../errorcode-universal.md)。 1041 1042| 错误码ID | 错误信息 | 1043| -------- | -------------------------------------- | 1044| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1045| 12800003 | input method client error. | 1046| 12800008 | input method manager service error. | 1047 1048**示例:** 1049 1050```ts 1051import { BusinessError } from '@kit.BasicServicesKit'; 1052 1053try { 1054 let textConfig: inputMethod.TextConfig = { 1055 inputAttribute: { 1056 textInputType: 0, 1057 enterKeyType: 1 1058 } 1059 }; 1060 1061 let requestKeyboardReason: inputMethod.RequestKeyboardReason = inputMethod.RequestKeyboardReason.MOUSE; 1062 1063 inputMethodController.attach(true, textConfig, requestKeyboardReason).then(() => { 1064 console.log('Succeeded in attaching inputMethod.'); 1065 }).catch((err: BusinessError) => { 1066 console.error(`Failed to attach: ${JSON.stringify(err)}`); 1067 }) 1068} catch(err) { 1069 console.error(`Failed to attach: ${JSON.stringify(err)}`); 1070} 1071``` 1072 1073### showTextInput<sup>10+</sup> 1074 1075showTextInput(callback: AsyncCallback<void>): void 1076 1077进入文本编辑状态。使用callback异步回调。 1078 1079> **说明** 1080> 1081> 编辑框与输入法绑定成功后,可调用该接口拉起软键盘,进入文本编辑状态。 1082 1083**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1084 1085**参数:** 1086 1087| 参数名 | 类型 | 必填 | 说明 | 1088| -------- | -------- | -------- | -------- | 1089| callback | AsyncCallback<void> | 是 | 回调函数。若成功进入编辑状态,err为undefined;否则为错误对象。 | 1090 1091**错误码:** 1092 1093以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 1094 1095| 错误码ID | 错误信息 | 1096| -------- | -------------------------------------- | 1097| 12800003 | input method client error. | 1098| 12800008 | input method manager service error. | 1099| 12800009 | input method client detached. | 1100 1101**示例:** 1102 1103```ts 1104import { BusinessError } from '@kit.BasicServicesKit'; 1105 1106inputMethodController.showTextInput((err: BusinessError) => { 1107 if (err) { 1108 console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); 1109 return; 1110 } 1111 console.log('Succeeded in showing the inputMethod.'); 1112}); 1113``` 1114 1115### showTextInput<sup>10+</sup> 1116 1117showTextInput(): Promise<void> 1118 1119进入文本编辑状态。使用promise异步回调。 1120 1121> **说明** 1122> 1123> 编辑框与输入法绑定成功后,可调用该接口拉起软键盘,进入文本编辑状态。 1124 1125**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1126 1127**返回值:** 1128 1129| 类型 | 说明 | 1130| -------- | -------- | 1131| Promise<void> | 无返回结果的Promise对象。 | 1132 1133**错误码:** 1134 1135以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 1136 1137| 错误码ID | 错误信息 | 1138| -------- | -------------------------------------- | 1139| 12800003 | input method client error. | 1140| 12800008 | input method manager service error. | 1141| 12800009 | input method client detached. | 1142 1143**示例:** 1144 1145```ts 1146import { BusinessError } from '@kit.BasicServicesKit'; 1147 1148inputMethodController.showTextInput().then(() => { 1149 console.log('Succeeded in showing text input.'); 1150}).catch((err: BusinessError) => { 1151 console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); 1152}); 1153``` 1154 1155### showTextInput<sup>15+</sup> 1156 1157showTextInput(requestKeyboardReason: RequestKeyboardReason): Promise<void> 1158 1159进入文本编辑状态。使用promise异步回调。 1160 1161> **说明:** 1162> 1163> 编辑框与输入法绑定成功后,可调用该接口拉起软键盘,进入文本编辑状态。 1164 1165**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1166 1167**参数:** 1168 1169| 参数名 | 类型 | 必填 | 说明 | 1170| -------- | -------- | -------- | -------- | 1171| requestKeyboardReason | [RequestKeyboardReason](#requestkeyboardreason15) | 是 | 请求键盘输入原因。 | 1172 1173**返回值:** 1174 1175| 类型 | 说明 | 1176| -------- | -------- | 1177| Promise<void> | 无返回结果的Promise对象。 | 1178 1179**错误码:** 1180 1181以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 1182 1183| 错误码ID | 错误信息 | 1184| -------- | -------------------------------------- | 1185| 12800003 | input method client error. | 1186| 12800008 | input method manager service error. | 1187| 12800009 | input method client detached. | 1188 1189**示例:** 1190 1191```ts 1192import { BusinessError } from '@kit.BasicServicesKit'; 1193 1194let requestKeyboardReason = inputMethod.RequestKeyboardReason.MOUSE; 1195 1196inputMethodController.showTextInput(requestKeyboardReason).then(() => { 1197 console.log('Succeeded in showing text input.'); 1198}).catch((err: BusinessError) => { 1199 console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); 1200}); 1201``` 1202 1203### hideTextInput<sup>10+</sup> 1204 1205hideTextInput(callback: AsyncCallback<void>): void 1206 1207退出文本编辑状态。使用callback异步回调。 1208 1209> **说明** 1210> 1211> 调用接口时,若软键盘处于显示状态,调用接口后软键盘会被隐藏。 1212> 1213> 调用该接口不会解除与输入法的绑定,再次调用[showTextInput](#showtextinput10)时,可重新进入文本编辑状态。 1214 1215**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1216 1217**参数:** 1218 1219| 参数名 | 类型 | 必填 | 说明 | 1220| -------- | -------- | -------- | -------- | 1221| callback | AsyncCallback<void> | 是 | 回调函数。当成功退出编辑状态时,err为undefined;否则为错误对象。 | 1222 1223**错误码:** 1224 1225以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 1226 1227| 错误码ID | 错误信息 | 1228| -------- | -------------------------------------- | 1229| 12800003 | input method client error. | 1230| 12800008 | input method manager service error. | 1231| 12800009 | input method client detached. | 1232 1233**示例:** 1234 1235```ts 1236import { BusinessError } from '@kit.BasicServicesKit'; 1237 1238inputMethodController.hideTextInput((err: BusinessError) => { 1239 if (err) { 1240 console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); 1241 return; 1242 } 1243 console.log('Succeeded in hiding text input.'); 1244}); 1245``` 1246 1247### hideTextInput<sup>10+</sup> 1248 1249hideTextInput(): Promise<void> 1250 1251退出文本编辑状态。使用promise异步回调。 1252 1253> **说明** 1254> 1255> 调用接口时,若软键盘处于显示状态,调用接口后软键盘会被隐藏。 1256> 1257> 调用该接口不会解除与输入法的绑定,再次调用[showTextInput](#showtextinput10)时,可重新进入文本编辑状态。 1258 1259**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1260 1261**返回值:** 1262 1263| 类型 | 说明 | 1264| -------- | -------- | 1265| Promise<void> | 无返回结果的Promise对象。 | 1266 1267**错误码:** 1268 1269以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 1270 1271| 错误码ID | 错误信息 | 1272| -------- | -------------------------------------- | 1273| 12800003 | input method client error. | 1274| 12800008 | input method manager service error. | 1275| 12800009 | input method client detached. | 1276 1277**示例:** 1278 1279```ts 1280import { BusinessError } from '@kit.BasicServicesKit'; 1281 1282inputMethodController.hideTextInput().then(() => { 1283 console.log('Succeeded in hiding inputMethod.'); 1284}).catch((err: BusinessError) => { 1285 console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); 1286}) 1287``` 1288 1289### detach<sup>10+</sup> 1290 1291detach(callback: AsyncCallback<void>): void 1292 1293自绘控件解除与输入法的绑定。使用callback异步回调。 1294 1295**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1296 1297**参数:** 1298 1299| 参数名 | 类型 | 必填 | 说明 | 1300| -------- | -------- | -------- | -------- | 1301| callback | AsyncCallback<void> | 是 | 回调函数。当解绑定输入法成功时,err为undefined;否则为错误对象。 | 1302 1303**错误码:** 1304 1305以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 1306 1307| 错误码ID | 错误信息 | 1308| -------- | -------------------------------------- | 1309| 12800003 | input method client error. | 1310| 12800008 | input method manager service error. | 1311 1312**示例:** 1313 1314```ts 1315import { BusinessError } from '@kit.BasicServicesKit'; 1316 1317inputMethodController.detach((err: BusinessError) => { 1318 if (err) { 1319 console.error(`Failed to detach: ${JSON.stringify(err)}`); 1320 return; 1321 } 1322 console.log('Succeeded in detaching inputMethod.'); 1323}); 1324``` 1325 1326### detach<sup>10+</sup> 1327 1328detach(): Promise<void> 1329 1330自绘控件解除与输入法的绑定。使用promise异步回调。 1331 1332**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1333 1334**返回值:** 1335 1336| 类型 | 说明 | 1337| -------- | -------- | 1338| Promise<void> | 无返回结果的Promise对象。 | 1339 1340**错误码:** 1341 1342以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 1343 1344| 错误码ID | 错误信息 | 1345| -------- | -------------------------------------- | 1346| 12800003 | input method client error. | 1347| 12800008 | input method manager service error. | 1348 1349**示例:** 1350 1351```ts 1352import { BusinessError } from '@kit.BasicServicesKit'; 1353 1354inputMethodController.detach().then(() => { 1355 console.log('Succeeded in detaching inputMethod.'); 1356}).catch((err: BusinessError) => { 1357 console.error(`Failed to detach: ${JSON.stringify(err)}`); 1358}); 1359``` 1360 1361### setCallingWindow<sup>10+</sup> 1362 1363setCallingWindow(windowId: number, callback: AsyncCallback<void>): void 1364 1365设置要避让软键盘的窗口。使用callback异步回调。 1366 1367> **说明** 1368> 1369> 将绑定到输入法的应用程序所在的窗口Id传入,此窗口可以避让输入法窗口。 1370 1371**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1372 1373**参数:** 1374 1375| 参数名 | 类型 | 必填 | 说明 | 1376| -------- | -------- | -------- | -------- | 1377| windowId | number | 是 | 绑定输入法应用的应用程序所在的窗口Id。 | 1378| callback | AsyncCallback<void> | 是 | 回调函数。当设置成功时,err为undefined;否则为错误对象。 | 1379 1380**错误码:** 1381 1382以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 1383 1384| 错误码ID | 错误信息 | 1385| -------- | -------------------------------------- | 1386| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1387| 12800003 | input method client error. | 1388| 12800008 | input method manager service error. | 1389| 12800009 | input method client detached. | 1390 1391**示例:** 1392 1393```ts 1394import { BusinessError } from '@kit.BasicServicesKit'; 1395 1396try { 1397 let windowId: number = 2000; 1398 inputMethodController.setCallingWindow(windowId, (err: BusinessError) => { 1399 if (err) { 1400 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 1401 return; 1402 } 1403 console.log('Succeeded in setting callingWindow.'); 1404 }); 1405} catch(err) { 1406 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 1407} 1408``` 1409 1410### setCallingWindow<sup>10+</sup> 1411 1412setCallingWindow(windowId: number): Promise<void> 1413 1414设置要避让软键盘的窗口。使用promise异步回调。 1415 1416> **说明** 1417> 1418> 将绑定到输入法的应用程序所在的窗口Id传入,此窗口可以避让输入法窗口。 1419 1420**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1421 1422**参数:** 1423 1424| 参数名 | 类型 | 必填 | 说明 | 1425| -------- | -------- | -------- | -------- | 1426| windowId | number | 是 | 绑定输入法应用的应用程序所在的窗口Id。 | 1427 1428**返回值:** 1429 1430| 类型 | 说明 | 1431| -------- | -------- | 1432| Promise<void> | 无返回结果的Promise对象。 | 1433 1434**错误码:** 1435 1436以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 1437 1438| 错误码ID | 错误信息 | 1439| -------- | -------------------------------------- | 1440| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1441| 12800003 | input method client error. | 1442| 12800008 | input method manager service error. | 1443| 12800009 | input method client detached. | 1444 1445**示例:** 1446 1447```ts 1448import { BusinessError } from '@kit.BasicServicesKit'; 1449 1450try { 1451 let windowId: number = 2000; 1452 inputMethodController.setCallingWindow(windowId).then(() => { 1453 console.log('Succeeded in setting callingWindow.'); 1454 }).catch((err: BusinessError) => { 1455 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 1456 }) 1457} catch(err) { 1458 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 1459} 1460``` 1461 1462### updateCursor<sup>10+</sup> 1463 1464updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback<void>): void 1465 1466当编辑框内的光标信息发生变化时,调用该接口使输入法感知到光标变化。使用callback异步回调。 1467 1468**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1469 1470**参数:** 1471 1472| 参数名 | 类型 | 必填 | 说明 | 1473| -------- | -------- | -------- | -------- | 1474| cursorInfo | [CursorInfo](#cursorinfo10) | 是 | 光标信息。 | 1475| callback | AsyncCallback<void> | 是 | 回调函数。当光标信息更新成功时,err为undefined;否则为错误对象。 | 1476 1477**错误码:** 1478 1479以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 1480 1481| 错误码ID | 错误信息 | 1482| -------- | -------------------------------------- | 1483| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1484| 12800003 | input method client error. | 1485| 12800008 | input method manager service error. | 1486| 12800009 | input method client detached. | 1487 1488**示例:** 1489 1490```ts 1491import { BusinessError } from '@kit.BasicServicesKit'; 1492 1493try { 1494 let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 }; 1495 inputMethodController.updateCursor(cursorInfo, (err: BusinessError) => { 1496 if (err) { 1497 console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); 1498 return; 1499 } 1500 console.log('Succeeded in updating cursorInfo.'); 1501 }); 1502} catch(err) { 1503 console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); 1504} 1505``` 1506 1507### updateCursor<sup>10+</sup> 1508 1509updateCursor(cursorInfo: CursorInfo): Promise<void> 1510 1511当编辑框内的光标信息发生变化时,调用该接口使输入法感知到光标变化。使用promise异步回调。 1512 1513**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1514 1515**参数:** 1516 1517| 参数名 | 类型 | 必填 | 说明 | 1518| -------- | -------- | -------- | -------- | 1519| cursorInfo | [CursorInfo](#cursorinfo10) | 是 | 光标信息。 | 1520 1521**返回值:** 1522 1523| 类型 | 说明 | 1524| -------- | -------- | 1525| Promise<void> | 无返回结果的Promise对象。 | 1526 1527**错误码:** 1528 1529以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 1530 1531| 错误码ID | 错误信息 | 1532| -------- | -------------------------------------- | 1533| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1534| 12800003 | input method client error. | 1535| 12800008 | input method manager service error. | 1536| 12800009 | input method client detached. | 1537 1538**示例:** 1539 1540```ts 1541import { BusinessError } from '@kit.BasicServicesKit'; 1542 1543try { 1544 let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 }; 1545 inputMethodController.updateCursor(cursorInfo).then(() => { 1546 console.log('Succeeded in updating cursorInfo.'); 1547 }).catch((err: BusinessError) => { 1548 console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); 1549 }) 1550} catch(err) { 1551 console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); 1552} 1553``` 1554 1555### changeSelection<sup>10+</sup> 1556 1557changeSelection(text: string, start: number, end: number, callback: AsyncCallback<void>): void 1558 1559当编辑框内被选中的文本信息内容或文本范围发生变化时,可调用该接口更新文本信息,使输入法应用感知到变化。使用callback异步回调。 1560 1561**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1562 1563**参数:** 1564 1565| 参数名 | 类型 | 必填 | 说明 | 1566| -------- | -------- | -------- | -------- | 1567| text | string | 是 | 整个输入文本。 | 1568| start | number | 是 | 所选文本的起始位置。 | 1569| end | number | 是 | 所选文本的结束位置。 | 1570| callback | AsyncCallback<void> | 是 | 回调函数。当文本信息更新成功时,err为undefined;否则为错误对象。 | 1571 1572**错误码:** 1573 1574以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 1575 1576| 错误码ID | 错误信息 | 1577| -------- | -------------------------------------- | 1578| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1579| 12800003 | input method client error. | 1580| 12800008 | input method manager service error. | 1581| 12800009 | input method client detached. | 1582 1583**示例:** 1584 1585```ts 1586import { BusinessError } from '@kit.BasicServicesKit'; 1587 1588try { 1589 inputMethodController.changeSelection('text', 0, 5, (err: BusinessError) => { 1590 if (err) { 1591 console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); 1592 return; 1593 } 1594 console.log('Succeeded in changing selection.'); 1595 }); 1596} catch(err) { 1597 console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); 1598} 1599``` 1600 1601### changeSelection<sup>10+</sup> 1602 1603changeSelection(text: string, start: number, end: number): Promise<void> 1604 1605当编辑框内被选中的文本信息内容或文本范围发生变化时,可调用该接口更新文本信息,使输入法应用感知到变化。使用promise异步回调。 1606 1607**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1608 1609**参数:** 1610 1611| 参数名 | 类型 | 必填 | 说明 | 1612| -------- | -------- | -------- | -------- | 1613| text | string | 是 | 整个输入文本。 | 1614| start | number | 是 | 所选文本的起始位置。 | 1615| end | number | 是 | 所选文本的结束位置。 | 1616 1617**返回值:** 1618 1619| 类型 | 说明 | 1620| -------- | -------- | 1621| Promise<void> | 无返回结果的Promise对象。 | 1622 1623**错误码:** 1624 1625以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 1626 1627| 错误码ID | 错误信息 | 1628| -------- | -------------------------------------- | 1629| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1630| 12800003 | input method client error. | 1631| 12800008 | input method manager service error. | 1632| 12800009 | input method client detached. | 1633 1634**示例:** 1635 1636```ts 1637import { BusinessError } from '@kit.BasicServicesKit'; 1638 1639try { 1640 inputMethodController.changeSelection('test', 0, 5).then(() => { 1641 console.log('Succeeded in changing selection.'); 1642 }).catch((err: BusinessError) => { 1643 console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); 1644 }) 1645} catch(err) { 1646 console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); 1647} 1648``` 1649 1650### updateAttribute<sup>10+</sup> 1651 1652updateAttribute(attribute: InputAttribute, callback: AsyncCallback<void>): void 1653 1654更新编辑框属性信息。使用callback异步回调。 1655 1656**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1657 1658**参数:** 1659 1660| 参数名 | 类型 | 必填 | 说明 | 1661| -------- | -------- | -------- | -------- | 1662| attribute | [InputAttribute](#inputattribute10) | 是 | 编辑框属性对象。 | 1663| callback | AsyncCallback<void> | 是 | 回调函数。当编辑框属性信息更新成功时,err为undefined;否则为错误对象。 | 1664 1665**错误码:** 1666 1667以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 1668 1669| 错误码ID | 错误信息 | 1670| -------- | -------------------------------------- | 1671| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1672| 12800003 | input method client error. | 1673| 12800008 | input method manager service error. | 1674| 12800009 | input method client detached. | 1675 1676**示例:** 1677 1678```ts 1679import { BusinessError } from '@kit.BasicServicesKit'; 1680 1681try { 1682 let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; 1683 inputMethodController.updateAttribute(inputAttribute, (err: BusinessError) => { 1684 if (err) { 1685 console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); 1686 return; 1687 } 1688 console.log('Succeeded in updating attribute.'); 1689 }); 1690} catch(err) { 1691 console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); 1692} 1693``` 1694 1695### updateAttribute<sup>10+</sup> 1696 1697updateAttribute(attribute: InputAttribute): Promise<void> 1698 1699更新编辑框属性信息。使用promise异步回调。 1700 1701**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1702 1703**参数:** 1704 1705| 参数名 | 类型 | 必填 | 说明 | 1706| -------- | -------- | -------- | -------- | 1707| attribute | [InputAttribute](#inputattribute10) | 是 | 编辑框属性对象。 | 1708 1709**返回值:** 1710 1711| 类型 | 说明 | 1712| -------- | -------- | 1713| Promise<void> | 无返回结果的Promise对象。 | 1714 1715**错误码:** 1716 1717以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 1718 1719| 错误码ID | 错误信息 | 1720| -------- | -------------------------------------- | 1721| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1722| 12800003 | input method client error. | 1723| 12800008 | input method manager service error. | 1724| 12800009 | input method client detached. | 1725 1726**示例:** 1727 1728```ts 1729import { BusinessError } from '@kit.BasicServicesKit'; 1730 1731try { 1732 let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; 1733 inputMethodController.updateAttribute(inputAttribute).then(() => { 1734 console.log('Succeeded in updating attribute.'); 1735 }).catch((err: BusinessError) => { 1736 console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); 1737 }) 1738} catch(err) { 1739 console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); 1740} 1741``` 1742 1743### stopInputSession<sup>9+</sup> 1744 1745stopInputSession(callback: AsyncCallback<boolean>): void 1746 1747结束输入会话。使用callback异步回调。 1748 1749> **说明:** 1750> 1751> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用该接口结束输入会话。 1752 1753**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1754 1755**参数:** 1756 1757| 参数名 | 类型 | 必填 | 说明 | 1758| -------- | -------- | -------- | -------- | 1759| callback | AsyncCallback<boolean> | 是 | 回调函数。当结束输入会话成功时,err为undefined,data为true;否则为错误对象。 | 1760 1761**错误码:** 1762 1763以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 1764 1765| 错误码ID | 错误信息 | 1766| -------- | -------------------------------------- | 1767| 12800003 | input method client error. | 1768| 12800008 | input method manager service error. | 1769 1770**示例:** 1771 1772```ts 1773import { BusinessError } from '@kit.BasicServicesKit'; 1774 1775try { 1776 inputMethodController.stopInputSession((err: BusinessError, result: boolean) => { 1777 if (err) { 1778 console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); 1779 return; 1780 } 1781 if (result) { 1782 console.log('Succeeded in stopping inputSession.'); 1783 } else { 1784 console.error('Failed to stopInputSession.'); 1785 } 1786 }); 1787} catch(err) { 1788 console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); 1789} 1790``` 1791 1792### stopInputSession<sup>9+</sup> 1793 1794stopInputSession(): Promise<boolean> 1795 1796结束输入会话。使用promise异步回调。 1797 1798> **说明:** 1799> 1800> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用该接口结束输入会话。 1801 1802**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1803 1804**返回值:** 1805 1806| 类型 | 说明 | 1807| -------- | -------- | 1808| Promise<boolean> | Promise对象。返回true表示结束输入会话成功,返回false表示结束输入会话失败。 | 1809 1810**错误码:** 1811 1812以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 1813 1814| 错误码ID | 错误信息 | 1815| -------- | -------------------------------------- | 1816| 12800003 | input method client error. | 1817| 12800008 | input method manager service error. | 1818 1819**示例:** 1820 1821```ts 1822import { BusinessError } from '@kit.BasicServicesKit'; 1823 1824try { 1825 inputMethodController.stopInputSession().then((result: boolean) => { 1826 if (result) { 1827 console.log('Succeeded in stopping inputSession.'); 1828 } else { 1829 console.error('Failed to stopInputSession.'); 1830 } 1831 }).catch((err: BusinessError) => { 1832 console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); 1833 }) 1834} catch(err) { 1835 console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); 1836} 1837``` 1838 1839### showSoftKeyboard<sup>9+</sup> 1840 1841showSoftKeyboard(callback: AsyncCallback<void>): void 1842 1843显示输入法软键盘。使用callback异步回调。 1844 1845> **说明:** 1846> 1847> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用显示当前输入法的软键盘。 1848 1849**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 1850 1851**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1852 1853**参数:** 1854 1855| 参数名 | 类型 | 必填 | 说明 | 1856| -------- | ------------------------- | ---- | ---------- | 1857| callback | AsyncCallback<void> | 是 | 回调函数。当软键盘显示成功。err为undefined,否则为错误对象。 | 1858 1859**错误码:** 1860 1861以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 1862 1863| 错误码ID | 错误信息 | 1864| -------- | -------------------------------------- | 1865| 201 | permissions check fails. | 1866| 12800003 | input method client error. | 1867| 12800008 | input method manager service error. | 1868 1869**示例:** 1870 1871```ts 1872import { BusinessError } from '@kit.BasicServicesKit'; 1873 1874inputMethodController.showSoftKeyboard((err: BusinessError) => { 1875 if (!err) { 1876 console.log('Succeeded in showing softKeyboard.'); 1877 } else { 1878 console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); 1879 } 1880}) 1881``` 1882 1883### showSoftKeyboard<sup>9+</sup> 1884 1885showSoftKeyboard(): Promise<void> 1886 1887显示输入法软键盘。使用Promise异步回调。 1888 1889> **说明:** 1890> 1891> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用显示当前输入法的软键盘。 1892 1893**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 1894 1895**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1896 1897**返回值:** 1898 1899| 类型 | 说明 | 1900| ------------------- | ------------------------- | 1901| Promise<void> | 无返回结果的Promise对象。 | 1902 1903**错误码:** 1904 1905以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 1906 1907| 错误码ID | 错误信息 | 1908| -------- | -------------------------------------- | 1909| 201 | permissions check fails. | 1910| 12800003 | input method client error. | 1911| 12800008 | input method manager service error. | 1912 1913**示例:** 1914 1915```ts 1916import { BusinessError } from '@kit.BasicServicesKit'; 1917 1918inputMethodController.showSoftKeyboard().then(() => { 1919 console.log('Succeeded in showing softKeyboard.'); 1920}).catch((err: BusinessError) => { 1921 console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); 1922}); 1923``` 1924 1925### hideSoftKeyboard<sup>9+</sup> 1926 1927hideSoftKeyboard(callback: AsyncCallback<void>): void 1928 1929隐藏输入法软键盘。使用callback异步回调。 1930 1931> **说明:** 1932> 1933> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用隐藏当前输入法的软键盘。 1934 1935**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 1936 1937**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1938 1939**参数:** 1940 1941| 参数名 | 类型 | 必填 | 说明 | 1942| -------- | ------------------------- | ---- | ---------- | 1943| callback | AsyncCallback<void> | 是 | 回调函数。当软键盘隐藏成功。err为undefined,否则为错误对象。 | 1944 1945**错误码:** 1946 1947以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 1948 1949| 错误码ID | 错误信息 | 1950| -------- | -------------------------------------- | 1951| 201 | permissions check fails. | 1952| 12800003 | input method client error. | 1953| 12800008 | input method manager service error. | 1954 1955**示例:** 1956 1957```ts 1958import { BusinessError } from '@kit.BasicServicesKit'; 1959 1960inputMethodController.hideSoftKeyboard((err: BusinessError) => { 1961 if (!err) { 1962 console.log('Succeeded in hiding softKeyboard.'); 1963 } else { 1964 console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); 1965 } 1966}) 1967``` 1968 1969### hideSoftKeyboard<sup>9+</sup> 1970 1971hideSoftKeyboard(): Promise<void> 1972 1973隐藏输入法软键盘。使用Promise异步回调。 1974 1975> **说明:** 1976> 1977> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用隐藏当前输入法的软键盘。 1978 1979**需要权限:** ohos.permission.CONNECT_IME_ABILITY,仅系统应用可用。 1980 1981**系统能力:** SystemCapability.MiscServices.InputMethodFramework 1982 1983**返回值:** 1984 1985| 类型 | 说明 | 1986| ------------------- | ------------------------- | 1987| Promise<void> | 无返回结果的Promise对象。 | 1988 1989**错误码:** 1990 1991以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 1992 1993| 错误码ID | 错误信息 | 1994| -------- | -------------------------------------- | 1995| 201 | permissions check fails. | 1996| 12800003 | input method client error. | 1997| 12800008 | input method manager service error. | 1998 1999**示例:** 2000 2001```ts 2002import { BusinessError } from '@kit.BasicServicesKit'; 2003 2004inputMethodController.hideSoftKeyboard().then(() => { 2005 console.log('Succeeded in hiding softKeyboard.'); 2006}).catch((err: BusinessError) => { 2007 console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); 2008}); 2009``` 2010 2011### sendMessage<sup>15+</sup> 2012 2013sendMessage(msgId: string, msgParam?: ArrayBuffer): Promise<void> 2014 2015发送自定义通信至输入法应用。使用Promise异步回调。 2016 2017> **说明:** 2018> 2019> 该接口需要编辑框与输入法绑定并进入编辑状态,且输入法应用处于完整体验模式时才能调用。 2020> 2021> msgId最大限制256B,msgParam最大限制128KB。 2022 2023**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2024 2025**参数:** 2026 2027| 参数名 | 类型 | 必填 | 说明 | 2028| -------- | ----------- | ---- | ------------------------------------------ | 2029| msgId | string | 是 | 需要发送至输入法应用的自定义数据的标识符。 | 2030| msgParam | ArrayBuffer | 否 | 需要发送至输入法应用的自定义数据的消息体。 | 2031 2032**返回值:** 2033 2034| 类型 | 说明 | 2035| ------------------- | ------------------------- | 2036| Promise<void> | 无返回结果的Promise对象。 | 2037 2038**错误码:** 2039 2040以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 2041 2042| 错误码ID | 错误信息 | 2043| -------- | ------------------------------------------- | 2044| 401 | parameter error. Possible causes: 1. Incorrect parameter types. 2. Incorrect parameter length. | 2045| 12800003 | input method client error. | 2046| 12800009 | input method client detached. | 2047| 12800014 | the input method is in basic mode. | 2048| 12800015 | the other side does not accept the request. | 2049| 12800016 | input method client is not editable. | 2050 2051**示例:** 2052 2053```ts 2054import { BusinessError } from '@kit.BasicServicesKit'; 2055 2056let msgId: string = "testMsgId"; 2057let msgParam: ArrayBuffer = new ArrayBuffer(128); 2058inputMethodController.sendMessage(msgId, msgParam).then(() => { 2059 console.log('Succeeded send message.'); 2060}).catch((err: BusinessError) => { 2061 console.error(`Failed to send message: ${JSON.stringify(err)}`); 2062}); 2063``` 2064 2065### recvMessage<sup>15+</sup> 2066 2067recvMessage(msgHandler?: MessageHandler): void 2068 2069注册或取消注册Messagehandler。 2070 2071> **说明:** 2072> 2073> [MessageHandler](#messagehandler15)对象全局唯一,多次注册仅保留最后一次注册的对象及有效性,并触发上一个已注册对象的[onTerminated](#onterminated15)回调函数。 2074> 2075> 未填写参数,则取消全局已注册的[MessageHandler](#messagehandler15),并会触发被取消注册对象中[onTerminated](#onterminated15)回调函数。 2076 2077**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2078 2079**参数:** 2080 2081| 参数名 | 类型 | 必填 | 说明 | 2082| ---------- | ----------------------------------- | ---- | ------------------------------------------------------------ | 2083| msgHandler | [MessageHandler](#messagehandler15) | 否 | 该对象将通过[onMessage](#onmessage15)接收来自输入法应用所发送的自定义通信数据,以及[onTerminated](#onterminated15)接收终止此对象订阅的消息。若不填写此参数,则取消全局已注册的[MessageHandler](#messagehandler15)对象,并触发其[onTerminated](#onterminated15)回调函数。 | 2084 2085**返回值:** 2086 2087| 类型 | 说明 | 2088| ---- | ------------ | 2089| void | 无返回结果。 | 2090 2091**错误码:** 2092 2093以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 2094 2095| 错误码ID | 错误信息 | 2096| -------- | ---------------- | 2097| 401 | parameter error. Possible causes: 1. Incorrect parameter types. | 2098 2099**示例:** 2100 2101```ts 2102import { BusinessError } from '@kit.BasicServicesKit'; 2103 2104let inputMethodController = inputMethod.getController(); 2105let messageHandler: inputMethod.MessageHandler = { 2106 onTerminated(): void { 2107 console.log('OnTerminated.'); 2108 }, 2109 onMessage(msgId: string, msgParam?:ArrayBuffer): void { 2110 console.log('recv message.'); 2111 } 2112} 2113inputMethodController.recvMessage(messageHandler); 2114inputMethodController.recvMessage(); 2115``` 2116 2117### stopInput<sup>(deprecated)</sup> 2118 2119stopInput(callback: AsyncCallback<boolean>): void 2120 2121结束输入会话。使用callback异步回调。 2122 2123> **说明:** 2124> 2125> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用该接口结束输入会话。 2126> 2127> 从API version 6开始支持,从API version 9开始废弃,建议使用[stopInputSession()](#stopinputsession9)替代。 2128 2129**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2130 2131**参数:** 2132 2133| 参数名 | 类型 | 必填 | 说明 | 2134| -------- | -------- | -------- | -------- | 2135| callback | AsyncCallback<boolean> | 是 | 回调函数。当会话结束成功,err为undefined,data为true;否则为错误对象。 | 2136 2137**示例:** 2138 2139```ts 2140import { BusinessError } from '@kit.BasicServicesKit'; 2141 2142inputMethodController.stopInput((err: BusinessError, result: boolean) => { 2143 if (err) { 2144 console.error(`Failed to stopInput: ${JSON.stringify(err)}`); 2145 return; 2146 } 2147 if (result) { 2148 console.log('Succeeded in stopping input.'); 2149 } else { 2150 console.error('Failed to stopInput.'); 2151 } 2152}); 2153``` 2154 2155### stopInput<sup>(deprecated)</sup> 2156 2157stopInput(): Promise<boolean> 2158 2159结束输入会话。使用promise异步回调。 2160 2161> **说明:** 2162> 2163> 该接口需要编辑框与输入法绑定时才能调用,即点击编辑控件后,才可调用该接口结束输入会话。 2164> 2165> 从API version 6开始支持,从API version 9开始废弃,建议使用[stopInputSession()](#stopinputsession9)替代。 2166 2167**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2168 2169**返回值:** 2170 2171| 类型 | 说明 | 2172| -------- | -------- | 2173| Promise<boolean> | Promise对象。返回true表示会话结束成功;返回false表示会话结束失败。 | 2174 2175**示例:** 2176 2177```ts 2178import { BusinessError } from '@kit.BasicServicesKit'; 2179 2180inputMethodController.stopInput().then((result: boolean) => { 2181 if (result) { 2182 console.log('Succeeded in stopping input.'); 2183 } else { 2184 console.error('Failed to stopInput.'); 2185 } 2186}).catch((err: BusinessError) => { 2187 console.error(`Failed to stopInput: ${JSON.stringify(err)}`); 2188}) 2189``` 2190 2191### on('insertText')<sup>10+</sup> 2192 2193on(type: 'insertText', callback: (text: string) => void): void 2194 2195订阅输入法应用插入文本事件。使用callback异步回调。 2196 2197**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2198 2199**参数:** 2200 2201| 参数名 | 类型 | 必填 | 说明 | 2202| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2203| type | string | 是 | 设置监听类型,固定取值为'insertText'。 | 2204| callback | (text: string) => void | 是 | 回调函数,返回需要插入的文本内容。<br/>根据传入的文本,在回调函数中操作编辑框中的内容。 | 2205 2206**错误码:** 2207 2208以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 2209 2210| 错误码ID | 错误信息 | 2211| -------- | -------------------------------------- | 2212| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2213| 12800009 | input method client detached. | 2214 2215**示例:** 2216 2217```ts 2218function callback1(text: string) { 2219 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(text)); 2220} 2221 2222function callback2(text: string) { 2223 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(text)); 2224} 2225 2226try { 2227 inputMethodController.on('insertText', callback1); 2228 inputMethodController.on('insertText', callback2); 2229 //仅取消insertText的callback1的回调 2230 inputMethodController.off('insertText', callback1); 2231 //取消insertText的所有回调 2232 inputMethodController.off('insertText'); 2233} catch(err) { 2234 console.error(`Failed to subscribe insertText: ${JSON.stringify(err)}`); 2235} 2236``` 2237 2238### off('insertText')<sup>10+</sup> 2239 2240off(type: 'insertText', callback?: (text: string) => void): void 2241 2242取消订阅输入法应用插入文本事件。 2243 2244**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2245 2246**参数:** 2247 2248| 参数名 | 类型 | 必填 | 说明 | 2249| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 2250| type | string | 是 | 设置监听类型,固定取值为'insertText'。 | 2251| callback | (text: string) => void | 否 | 取消订阅的回调函数,需要与on接口传入的保持一致。<br/>参数不填写时,取消订阅type对应的所有回调事件。 | 2252 2253**示例:** 2254 2255```ts 2256let onInsertTextCallback = (text: string) => { 2257 console.log(`Succeeded in subscribing insertText: ${text}`); 2258}; 2259inputMethodController.off('insertText', onInsertTextCallback); 2260inputMethodController.off('insertText'); 2261``` 2262 2263### on('deleteLeft')<sup>10+</sup> 2264 2265on(type: 'deleteLeft', callback: (length: number) => void): void 2266 2267订阅输入法应用向左删除事件。使用callback异步回调。 2268 2269**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2270 2271**参数:** 2272 2273| 参数名 | 类型 | 必填 | 说明 | 2274| -------- | ----- | ---- | ----- | 2275| type | string | 是 | 设置监听类型,固定取值为'deleteLeft'。| 2276| callback | (length: number) => void | 是 | 回调函数,返回需要向左删除的文本长度。<br/>根据传入的删除长度,在回调函数中操作编辑框中的文本。 | 2277 2278**错误码:** 2279 2280以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 2281 2282| 错误码ID | 错误信息 | 2283| -------- | -------------------------------------- | 2284| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2285| 12800009 | input method client detached. | 2286 2287**示例:** 2288 2289```ts 2290try { 2291 inputMethodController.on('deleteLeft', (length: number) => { 2292 console.log(`Succeeded in subscribing deleteLeft, length: ${length}`); 2293 }); 2294} catch(err) { 2295 console.error(`Failed to subscribe deleteLeft: ${JSON.stringify(err)}`); 2296} 2297``` 2298 2299### off('deleteLeft')<sup>10+</sup> 2300 2301off(type: 'deleteLeft', callback?: (length: number) => void): void 2302 2303取消订阅输入法应用向左删除文本事件。 2304 2305**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2306 2307**参数:** 2308 2309| 参数名 | 类型 | 必填 | 说明 | 2310| -------- | ------------------------ | ---- | ------------------------------------------------------------ | 2311| type | string | 是 | 设置监听,固定取值为'deleteLeft'。 | 2312| callback | (length: number) => void | 否 | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 | 2313 2314**示例:** 2315 2316```ts 2317let onDeleteLeftCallback = (length: number) => { 2318 console.log(`Succeeded in subscribing deleteLeft, length: ${length}`); 2319}; 2320inputMethodController.off('deleteLeft', onDeleteLeftCallback); 2321inputMethodController.off('deleteLeft'); 2322``` 2323 2324### on('deleteRight')<sup>10+</sup> 2325 2326on(type: 'deleteRight', callback: (length: number) => void): void 2327 2328订阅输入法应用向右删除事件。使用callback异步回调。 2329 2330**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2331 2332**参数:** 2333 2334| 参数名 | 类型 | 必填 | 说明 | 2335| -------- | ----- | ---- | ----- | 2336| type | string | 是 | 设置监听类型,固定取值为'deleteRight'。| 2337| callback | (length: number) => void | 是 | 回调函数,返回需要向右删除的文本长度。<br/>根据传入的删除长度,在回调函数中操作编辑框中的文本。 | 2338 2339**错误码:** 2340 2341以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 2342 2343| 错误码ID | 错误信息 | 2344| -------- | -------------------------------------- | 2345| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2346| 12800009 | input method client detached. | 2347 2348**示例:** 2349 2350```ts 2351try { 2352 inputMethodController.on('deleteRight', (length: number) => { 2353 console.log(`Succeeded in subscribing deleteRight, length: ${length}`); 2354 }); 2355} catch(err) { 2356 console.error(`Failed to subscribe deleteRight: ${JSON.stringify(err)}`); 2357} 2358``` 2359 2360### off('deleteRight')<sup>10+</sup> 2361 2362off(type: 'deleteRight', callback?: (length: number) => void): void 2363 2364取消订阅输入法应用向右删除文本事件。 2365 2366**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2367 2368**参数:** 2369 2370| 参数名 | 类型 | 必填 | 说明 | 2371| -------- | ------------------------ | ---- | ------------------------------------------------------------ | 2372| type | string | 是 | 设置监听类型,固定取值为`deleteRight`。 | 2373| callback | (length: number) => void | 否 | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 | 2374 2375**示例:** 2376 2377```ts 2378let onDeleteRightCallback = (length: number) => { 2379 console.log(`Succeeded in subscribing deleteRight, length: ${length}`); 2380}; 2381inputMethodController.off('deleteRight', onDeleteRightCallback); 2382inputMethodController.off('deleteRight'); 2383``` 2384 2385### on('sendKeyboardStatus')<sup>10+</sup> 2386 2387on(type: 'sendKeyboardStatus', callback: (keyboardStatus: KeyboardStatus) => void): void 2388 2389订阅输入法应用发送输入法软键盘状态事件。使用callback异步回调。 2390 2391**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2392 2393**参数:** 2394 2395| 参数名 | 类型 | 必填 | 说明 | 2396| -------- | ------ | ---- | ---- | 2397| type | string | 是 | 设置监听类型,固定取值为'sendKeyboardStatus'。 | 2398| callback | (keyboardStatus: [KeyboardStatus](#keyboardstatus10)) => void | 是 | 回调函数,返回软键盘状态。<br/>根据传入的软键盘状态,在回调函数中做相应操作。 | 2399 2400**错误码:** 2401 2402以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 2403 2404| 错误码ID | 错误信息 | 2405| -------- | -------------------------------------- | 2406| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2407| 12800009 | input method client detached. | 2408 2409**示例:** 2410 2411```ts 2412try { 2413 inputMethodController.on('sendKeyboardStatus', (keyboardStatus: inputMethod.KeyboardStatus) => { 2414 console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`); 2415 }); 2416} catch(err) { 2417 console.error(`Failed to subscribe sendKeyboardStatus: ${JSON.stringify(err)}`); 2418} 2419``` 2420 2421### off('sendKeyboardStatus')<sup>10+</sup> 2422 2423off(type: 'sendKeyboardStatus', callback?: (keyboardStatus: KeyboardStatus) => void): void 2424 2425取消订阅输入法应用发送软键盘状态事件。 2426 2427**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2428 2429**参数:** 2430 2431| 参数名 | 类型 | 必填 | 说明 | 2432| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2433| type | string | 是 | 设置监听类型,固定取值为'sendKeyboardStatus'。 | 2434| callback | (keyboardStatus: [KeyboardStatus](#keyboardstatus10)) => void | 否 | 取消订阅的回调函数。参数不填写时,取消订阅type对应的所有回调事件。 | 2435 2436**示例:** 2437 2438```ts 2439let onSendKeyboardStatus = (keyboardStatus: inputMethod.KeyboardStatus) => { 2440 console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`); 2441}; 2442inputMethodController.off('sendKeyboardStatus', onSendKeyboardStatus); 2443inputMethodController.off('sendKeyboardStatus'); 2444``` 2445 2446### on('sendFunctionKey')<sup>10+</sup> 2447 2448on(type: 'sendFunctionKey', callback: (functionKey: FunctionKey) => void): void 2449 2450订阅输入法应用发送功能键事件。使用callback异步回调。 2451 2452**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2453 2454**参数:** 2455 2456| 参数名 | 类型 | 必填 | 说明 | 2457| -------- | -------- | ---- | ----- | 2458| type | string | 是 | 设置监听类型,固定取值为'sendFunctionKey'。| 2459| callback | (functionKey: [FunctionKey](#functionkey10)) => void | 是 | 回调函数,返回输入法应用发送的功能键信息。<br/>根据返回的功能键信息,做相应操作。 | 2460 2461**错误码:** 2462 2463以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 2464 2465| 错误码ID | 错误信息 | 2466| -------- | -------------------------------------- | 2467| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2468| 12800009 | input method client detached. | 2469 2470**示例:** 2471 2472```ts 2473try { 2474 inputMethodController.on('sendFunctionKey', (functionKey: inputMethod.FunctionKey) => { 2475 console.log(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`); 2476 }); 2477} catch(err) { 2478 console.error(`Failed to subscribe sendFunctionKey: ${JSON.stringify(err)}`); 2479} 2480``` 2481 2482### off('sendFunctionKey')<sup>10+</sup> 2483 2484off(type: 'sendFunctionKey', callback?: (functionKey: FunctionKey) => void): void 2485 2486取消订阅输入法应用发送功能键事件。 2487 2488**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2489 2490**参数:** 2491 2492| 参数名 | 类型 | 必填 | 说明 | 2493| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 2494| type | string | 是 | 设置监听类型,固定取值为'sendFunctionKey'。 | 2495| callback | (functionKey: [FunctionKey](#functionkey10)) => void | 否 | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 | 2496 2497**示例:** 2498 2499```ts 2500let onSendFunctionKey = (functionKey: inputMethod.FunctionKey) => { 2501 console.log(`Succeeded in subscribing sendFunctionKey, functionKey: ${functionKey.enterKeyType}`); 2502}; 2503inputMethodController.off('sendFunctionKey', onSendFunctionKey); 2504inputMethodController.off('sendFunctionKey'); 2505``` 2506 2507### on('moveCursor')<sup>10+</sup> 2508 2509on(type: 'moveCursor', callback: (direction: Direction) => void): void 2510 2511订阅输入法应用移动光标事件。使用callback异步回调。 2512 2513**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2514 2515**参数:** 2516 2517| 参数名 | 类型 | 必填 | 说明 | 2518| -------- | ------ | ---- | ------ | 2519| type | string | 是 | 设置监听类型,固定取值为'moveCursor'。 | 2520| callback | callback: (direction: [Direction<sup>10+</sup>](#direction10)) => void | 是 | 回调函数,返回光标信息。<br/>根据返回的光标移动方向,改变光标位置,如光标向上或向下。 | 2521 2522**错误码:** 2523 2524以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 2525 2526| 错误码ID | 错误信息 | 2527| -------- | -------------------------------- | 2528| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2529| 12800009 | input method client detached. | 2530 2531**示例:** 2532 2533```ts 2534try { 2535 inputMethodController.on('moveCursor', (direction: inputMethod.Direction) => { 2536 console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`); 2537 }); 2538} catch(err) { 2539 console.error(`Failed to subscribe moveCursor: ${JSON.stringify(err)}`); 2540} 2541``` 2542 2543### off('moveCursor')<sup>10+</sup> 2544 2545off(type: 'moveCursor', callback?: (direction: Direction) => void): void 2546 2547取消订阅输入法应用移动光标事件。 2548 2549**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2550 2551**参数:** 2552 2553| 参数名 | 类型 | 必填 | 说明 | 2554| ------ | ------ | ---- | ---- | 2555| type | string | 是 | 设置监听类型,固定取值为'moveCursor'。 | 2556| callback | (direction: [Direction<sup>10+</sup>](#direction10)) => void | 否 | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 | 2557 2558**示例:** 2559 2560```ts 2561let onMoveCursorCallback = (direction: inputMethod.Direction) => { 2562 console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`); 2563}; 2564inputMethodController.off('moveCursor', onMoveCursorCallback); 2565inputMethodController.off('moveCursor'); 2566``` 2567 2568### on('handleExtendAction')<sup>10+</sup> 2569 2570on(type: 'handleExtendAction', callback: (action: ExtendAction) => void): void 2571 2572订阅输入法应用发送扩展编辑操作事件。使用callback异步回调。 2573 2574**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2575 2576**参数:** 2577 2578| 参数名 | 类型 | 必填 | 说明 | 2579| -------- | ------ | ---- | -------- | 2580| type | string | 是 | 设置监听类型,固定取值为'handleExtendAction'。 | 2581| callback | callback: (action: [ExtendAction](#extendaction10)) => void | 是 | 回调函数,返回扩展编辑操作类型。<br/>根据传入的扩展编辑操作类型,做相应的操作,如剪切、复制等。| 2582 2583**错误码:** 2584 2585以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 2586 2587| 错误码ID | 错误信息 | 2588| -------- | -------------------------------------- | 2589| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2590| 12800009 | input method client detached. | 2591 2592**示例:** 2593 2594```ts 2595try { 2596 inputMethodController.on('handleExtendAction', (action: inputMethod.ExtendAction) => { 2597 console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`); 2598 }); 2599} catch(err) { 2600 console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`); 2601} 2602``` 2603 2604### off('handleExtendAction')<sup>10+</sup> 2605 2606off(type: 'handleExtendAction', callback?: (action: ExtendAction) => void): void 2607 2608取消订阅输入法应用发送扩展编辑操作事件。使用callback异步回调。 2609 2610**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2611 2612**参数:** 2613 2614| 参数名 | 类型 | 必填 | 说明 | 2615| ------ | ------ | ---- | ------- | 2616| type | string | 是 | 设置监听类型,固定取值为'handleExtendAction'。 | 2617| callback | (action: [ExtendAction](#extendaction10)) => void | 否 | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 | 2618 2619**示例:** 2620 2621```ts 2622try { 2623 let onHandleExtendActionCallback = (action: inputMethod.ExtendAction) => { 2624 console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`); 2625 }; 2626 inputMethodController.off('handleExtendAction', onHandleExtendActionCallback); 2627 inputMethodController.off('handleExtendAction'); 2628} catch(err) { 2629 console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`); 2630} 2631``` 2632 2633### on('selectByRange')<sup>10+</sup> 2634 2635on(type: 'selectByRange', callback: Callback<Range>): void 2636 2637订阅输入法应用按范围选中文本事件。使用callback异步回调。 2638 2639**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2640 2641**参数:** 2642 2643| 参数名 | 类型 | 必填 | 说明 | 2644| -------- | ---- | ---- | ------- | 2645| type | string | 是 | 设置监听类型,固定取值为'selectByRange'。 | 2646| callback | Callback<[Range](#range10)> | 是 | 回调函数,返回需要选中的文本范围。<br/>根据传入的文本范围,开发者在回调函数中编辑框中相应文本。| 2647 2648**错误码:** 2649 2650以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。 2651 2652| 错误码ID | 错误信息 | 2653| -------- | ------------------------------------------------------- | 2654| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2655 2656**示例:** 2657 2658```ts 2659try { 2660 inputMethodController.on('selectByRange', (range: inputMethod.Range) => { 2661 console.log(`Succeeded in subscribing selectByRange: start: ${range.start} , end: ${range.end}`); 2662 }); 2663} catch(err) { 2664 console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`); 2665} 2666``` 2667 2668### off('selectByRange')<sup>10+</sup> 2669 2670off(type: 'selectByRange', callback?: Callback<Range>): void 2671 2672取消订阅输入法应用按范围选中文本事件。使用callback异步回调。 2673 2674**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2675 2676**参数:** 2677 2678| 参数名 | 类型 | 必填 | 说明 | 2679| -------- | --------------------------------- | ---- | ------------------------------------------------------------ | 2680| type | string | 是 | 设置监听类型,固定取值为'selectByRange'。 | 2681| callback | Callback<[Range](#range10)> | 否 | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 | 2682 2683**示例:** 2684 2685```ts 2686try { 2687 let onSelectByRangeCallback = (range: inputMethod.Range) => { 2688 console.log(`Succeeded in subscribing selectByRange, start: ${range.start} , end: ${range.end}`); 2689 }; 2690 inputMethodController.off('selectByRange', onSelectByRangeCallback); 2691 inputMethodController.off('selectByRange'); 2692} catch(err) { 2693 console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`); 2694} 2695``` 2696 2697### on('selectByMovement')<sup>10+</sup> 2698 2699on(type: 'selectByMovement', callback: Callback<Movement>): void 2700 2701订阅输入法应用按光标移动方向,选中文本事件。使用callback异步回调。 2702 2703**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2704 2705**参数:** 2706 2707| 参数名 | 类型 | 必填 | 说明 | 2708| -------- | ----- | ---- | ------ | 2709| type | string | 是 | 设置监听类型,固定取值为'selectByMovement'。 | 2710| callback | Callback<[Movement](#movement10)> | 是 | 回调函数,返回光标移动的方向。<br/>根据传入的光标移动方向,选中编辑框中相应文本。 | 2711 2712**错误码:** 2713 2714以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。 2715 2716| 错误码ID | 错误信息 | 2717| -------- | ------------------------------------------------------- | 2718| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2719 2720**示例:** 2721 2722```ts 2723try { 2724 inputMethodController.on('selectByMovement', (movement: inputMethod.Movement) => { 2725 console.log('Succeeded in subscribing selectByMovement: direction: ' + movement.direction); 2726 }); 2727} catch(err) { 2728 console.error(`Failed to subscribe selectByMovement: ${JSON.stringify(err)}`); 2729} 2730``` 2731 2732### off('selectByMovement')<sup>10+</sup> 2733 2734off(type: 'selectByMovement', callback?: Callback<Movement>): void 2735 2736取消订阅输入法应用按光标移动方向,选中文本事件。使用callback异步回调。 2737 2738**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2739 2740**参数:** 2741 2742| 参数名 | 类型 | 必填 | 说明 | 2743| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 2744| type | string | 是 | 设置监听类型,固定取值为'selectByMovement'。 | 2745| callback | Callback<[Movement](#movement10)> | 否 | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。 | 2746 2747**示例:** 2748 2749```ts 2750try { 2751 let onSelectByMovementCallback = (movement: inputMethod.Movement) => { 2752 console.log(`Succeeded in subscribing selectByMovement, movement.direction: ${movement.direction}`); 2753 }; 2754 inputMethodController.off('selectByMovement', onSelectByMovementCallback); 2755 inputMethodController.off('selectByMovement'); 2756} catch(err) { 2757 console.error(`Failed to unsubscribing selectByMovement: ${JSON.stringify(err)}`); 2758} 2759``` 2760 2761### on('getLeftTextOfCursor')<sup>10+</sup> 2762 2763on(type: 'getLeftTextOfCursor', callback: (length: number) => string): void 2764 2765订阅输入法应用获取光标左侧指定长度文本事件。使用callback异步回调。 2766 2767**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2768 2769**参数:** 2770 2771| 参数名 | 类型 | 必填 | 说明 | 2772| -------- | ----- | ---- | ------ | 2773| type | string | 是 | 设置监听类型,固定取值为'getLeftTextOfCursor'。 | 2774| callback | (length: number) => string | 是 | 回调函数,获取编辑框最新状态下光标左侧指定长度的文本内容并返回。 | 2775 2776**错误码:** 2777 2778以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 2779 2780| 错误码ID | 错误信息 | 2781| -------- | -------------------------------------- | 2782| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2783| 12800009 | input method client detached. | 2784 2785**示例:** 2786 2787```ts 2788try { 2789 inputMethodController.on('getLeftTextOfCursor', (length: number) => { 2790 console.info(`Succeeded in subscribing getLeftTextOfCursor, length: ${length}`); 2791 let text:string = ""; 2792 return text; 2793 }); 2794} catch(err) { 2795 console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`); 2796} 2797``` 2798 2799### off('getLeftTextOfCursor')<sup>10+</sup> 2800 2801off(type: 'getLeftTextOfCursor', callback?: (length: number) => string): void 2802 2803取消订阅输入法应用获取光标左侧指定长度文本事件。使用callback异步回调。 2804 2805**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2806 2807**参数:** 2808 2809| 参数名 | 类型 | 必填 | 说明 | 2810| ------ | ------ | ---- | ------------------------------------------------------------ | 2811| type | string | 是 | 设置监听类型,固定取值为'getLeftTextOfCursor'。 | 2812| callback | (length: number) => string | 否 | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。| 2813 2814**示例:** 2815 2816```ts 2817try { 2818 let getLeftTextOfCursorCallback = (length: number) => { 2819 console.info(`Succeeded in unsubscribing getLeftTextOfCursor, length: ${length}`); 2820 let text:string = ""; 2821 return text; 2822 }; 2823 inputMethodController.off('getLeftTextOfCursor', getLeftTextOfCursorCallback); 2824 inputMethodController.off('getLeftTextOfCursor'); 2825} catch(err) { 2826 console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`); 2827} 2828``` 2829 2830### on('getRightTextOfCursor')<sup>10+</sup> 2831 2832on(type: 'getRightTextOfCursor', callback: (length: number) => string): void 2833 2834订阅输入法应用获取光标右侧指定长度文本事件。使用callback异步回调。 2835 2836**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2837 2838**参数:** 2839 2840| 参数名 | 类型 | 必填 | 说明 | 2841| -------- | ----- | ---- | ------ | 2842| type | string | 是 | 设置监听类型,固定取值为'getRightTextOfCursor'。 | 2843| callback | (length: number) => string | 是 | 回调函数,获取编辑框最新状态下光标右侧指定长度的文本内容并返回。 | 2844 2845**错误码:** 2846 2847以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 2848 2849| 错误码ID | 错误信息 | 2850| -------- | -------------------------------------- | 2851| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2852| 12800009 | input method client detached. | 2853 2854**示例:** 2855 2856```ts 2857try { 2858 inputMethodController.on('getRightTextOfCursor', (length: number) => { 2859 console.info(`Succeeded in subscribing getRightTextOfCursor, length: ${length}`); 2860 let text:string = ""; 2861 return text; 2862 }); 2863} catch(err) { 2864 console.error(`Failed to subscribe getRightTextOfCursor. err: ${JSON.stringify(err)}`); 2865} 2866``` 2867 2868### off('getRightTextOfCursor')<sup>10+</sup> 2869 2870off(type: 'getRightTextOfCursor', callback?: (length: number) => string): void 2871 2872取消订阅输入法应用获取光标右侧指定长度文本事件。使用callback异步回调。 2873 2874**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2875 2876**参数:** 2877 2878| 参数名 | 类型 | 必填 | 说明 | 2879| ------ | ------ | ---- | ------------------------------------------------------------ | 2880| type | string | 是 | 设置监听类型,固定取值为'getRightTextOfCursor'。 | 2881| callback | (length: number) => string | 否 |取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。| 2882 2883**示例:** 2884 2885```ts 2886try { 2887 let getRightTextOfCursorCallback = (length: number) => { 2888 console.info(`Succeeded in unsubscribing getRightTextOfCursor, length: ${length}`); 2889 let text:string = ""; 2890 return text; 2891 }; 2892 inputMethodController.off('getRightTextOfCursor', getRightTextOfCursorCallback); 2893 inputMethodController.off('getRightTextOfCursor'); 2894} catch(err) { 2895 console.error(`Failed to unsubscribing getRightTextOfCursor. err: ${JSON.stringify(err)}`); 2896} 2897``` 2898 2899### on('getTextIndexAtCursor')<sup>10+</sup> 2900 2901on(type: 'getTextIndexAtCursor', callback: () => number): void 2902 2903订阅输入法应用获取光标处文本索引事件。使用callback异步回调。 2904 2905**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2906 2907**参数:** 2908 2909| 参数名 | 类型 | 必填 | 说明 | 2910| -------- | ----- | ---- | ------ | 2911| type | string | 是 | 设置监听类型,固定取值为'getTextIndexAtCursor'。 | 2912| callback | () => number | 是 | 回调函数,获取编辑框最新状态下光标处文本索引并返回。 | 2913 2914**错误码:** 2915 2916以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 2917 2918| 错误码ID | 错误信息 | 2919| -------- | -------------------------------------- | 2920| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2921| 12800009 | input method client detached. | 2922 2923**示例:** 2924 2925```ts 2926try { 2927 inputMethodController.on('getTextIndexAtCursor', () => { 2928 console.info(`Succeeded in subscribing getTextIndexAtCursor.`); 2929 let index:number = 0; 2930 return index; 2931 }); 2932} catch(err) { 2933 console.error(`Failed to subscribe getTextIndexAtCursor. err: ${JSON.stringify(err)}`); 2934} 2935``` 2936 2937### off('getTextIndexAtCursor')<sup>10+</sup> 2938 2939off(type: 'getTextIndexAtCursor', callback?: () => number): void 2940 2941取消订阅输入法应用获取光标处文本索引事件。使用callback异步回调。 2942 2943**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2944 2945**参数:** 2946 2947| 参数名 | 类型 | 必填 | 说明 | 2948| ------ | ------ | ---- | ------------------------------------------------------------ | 2949| type | string | 是 | 设置监听类型,固定取值为'getTextIndexAtCursor'。 | 2950| callback | () => number | 否 | 取消订阅的回调函数,需要与on接口传入的保持一致。<br>参数不填写时,取消订阅type对应的所有回调事件。| 2951 2952**示例:** 2953 2954```ts 2955try { 2956 let getTextIndexAtCursorCallback = () => { 2957 console.info(`Succeeded in unsubscribing getTextIndexAtCursor.`); 2958 let index:number = 0; 2959 return index; 2960 }; 2961 inputMethodController.off('getTextIndexAtCursor', getTextIndexAtCursorCallback); 2962 inputMethodController.off('getTextIndexAtCursor'); 2963} catch(err) { 2964 console.error(`Failed to unsubscribing getTextIndexAtCursor. err: ${JSON.stringify(err)}`); 2965} 2966``` 2967 2968## InputMethodSetting<sup>8+</sup> 2969 2970下列API均需使用[getSetting](#inputmethodgetsetting9)获取到InputMethodSetting实例后,通过实例调用。 2971 2972### on('imeChange')<sup>9+</sup> 2973 2974on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void 2975 2976订阅输入法及子类型变化监听事件。使用callback异步回调。 2977 2978**系统能力:** SystemCapability.MiscServices.InputMethodFramework 2979 2980**参数:** 2981 2982| 参数名 | 类型 | 必填 | 说明 | 2983| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | 2984| type | string | 是 | 设置监听类型,固定取值为'imeChange'。 | 2985| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void | 是 | 回调函数,返回输入法属性对象及子类型对象。 | 2986 2987**示例:** 2988 2989```ts 2990import { InputMethodSubtype } from '@kit.IMEKit'; 2991try { 2992 inputMethodSetting.on('imeChange', (inputMethodProperty: inputMethod.InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => { 2993 console.log('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype)); 2994 }); 2995} catch(err) { 2996 console.error(`Failed to unsubscribing inputMethodProperty. err: ${JSON.stringify(err)}`); 2997} 2998``` 2999 3000### off('imeChange')<sup>9+</sup> 3001 3002off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void 3003 3004取消订阅输入法及子类型变化监听事件。使用callback异步回调。 3005 3006**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3007 3008**参数:** 3009 3010| 参数名 | 类型 | 必填 | 说明 | 3011| -------- | --------- | ---- | --------------- | 3012| type | string | 是 | 设置监听类型,固定取值为'imeChange'。 | 3013| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void | 否 | 回调函数,返回取消订阅的输入法属性对象及子类型对象。 | 3014 3015**示例:** 3016 3017```ts 3018inputMethodSetting.off('imeChange'); 3019``` 3020 3021### listInputMethodSubtype<sup>9+</sup> 3022 3023listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback<Array<InputMethodSubtype>>): void 3024 3025获取指定输入法应用的所有子类型。使用callback异步回调。 3026 3027**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3028 3029**参数:** 3030 3031| 参数名 | 类型 | 必填 | 说明 | 3032| -------- | -------------------------------------------------- | ---- | ---------------------- | 3033| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 输入法应用。 | 3034| callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | 是 | 回调函数,返回指定输入法应用的所有子类型。 | 3035 3036**错误码:** 3037 3038以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 3039 3040| 错误码ID | 错误信息 | 3041| -------- | -------------------------------------- | 3042| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3043| 12800001 | bundle manager error. | 3044| 12800008 | input method manager service error. | 3045 3046**示例:** 3047 3048```ts 3049import { InputMethodSubtype } from '@kit.IMEKit'; 3050import { BusinessError } from '@kit.BasicServicesKit'; 3051 3052let inputMethodProperty: inputMethod.InputMethodProperty = { 3053 name: 'com.example.kikakeyboard', 3054 id: 'propertyId', 3055 packageName: 'com.example.kikakeyboard', 3056 methodId: 'propertyId', 3057} 3058let inputMethodSetting = inputMethod.getSetting(); 3059try { 3060 inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err: BusinessError, data: Array<InputMethodSubtype>) => { 3061 if (err) { 3062 console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); 3063 return; 3064 } 3065 console.log('Succeeded in listing inputMethodSubtype.'); 3066 }); 3067} catch (err) { 3068 console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); 3069} 3070``` 3071 3072### listInputMethodSubtype<sup>9+</sup> 3073 3074listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Array<InputMethodSubtype>> 3075 3076获取指定输入法应用的所有子类型。使用promise异步回调。 3077 3078**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3079 3080**参数:** 3081 3082| 参数名 | 类型 | 必填 | 说明 | 3083| -------- | -------------------------------------------------- | ---- | ---------------------- | 3084| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| 是 | 输入法应用。 | 3085 3086**返回值:** 3087 3088| 类型 | 说明 | 3089| ----------------------------------------------------------- | ---------------------- | 3090| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise对象,返回指定输入法应用的所有子类型。 | 3091 3092**错误码:** 3093 3094以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 3095 3096| 错误码ID | 错误信息 | 3097| -------- | -------------------------------------- | 3098| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3099| 12800001 | bundle manager error. | 3100| 12800008 | input method manager service error. | 3101 3102**示例:** 3103 3104```ts 3105import { InputMethodSubtype } from '@kit.IMEKit'; 3106import { BusinessError } from '@kit.BasicServicesKit'; 3107 3108let inputMethodProperty: inputMethod.InputMethodProperty = { 3109 name: 'com.example.kikakeyboard', 3110 id: 'propertyId', 3111 packageName: 'com.example.kikakeyboard', 3112 methodId: 'propertyId', 3113} 3114let inputMethodSetting = inputMethod.getSetting(); 3115try { 3116 inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data: Array<InputMethodSubtype>) => { 3117 console.log('Succeeded in listing inputMethodSubtype.'); 3118 }).catch((err: BusinessError) => { 3119 console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); 3120 }) 3121} catch(err) { 3122 console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); 3123} 3124``` 3125 3126### listCurrentInputMethodSubtype<sup>9+</sup> 3127 3128listCurrentInputMethodSubtype(callback: AsyncCallback<Array<InputMethodSubtype>>): void 3129 3130查询当前输入法应用的所有子类型。使用callback异步回调。 3131 3132**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3133 3134**参数:** 3135 3136| 参数名 | 类型 | 必填 | 说明 | 3137| -------- | -------------------------------------------------- | ---- | ---------------------- | 3138| callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | 是 | 回调函数,返回当前输入法应用的所有子类型。 | 3139 3140**错误码:** 3141 3142以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 3143 3144| 错误码ID | 错误信息 | 3145| -------- | -------------------------------------- | 3146| 12800001 | bundle manager error. | 3147| 12800008 | input method manager service error. | 3148 3149**示例:** 3150 3151```ts 3152import { InputMethodSubtype } from '@kit.IMEKit'; 3153import { BusinessError } from '@kit.BasicServicesKit'; 3154 3155let inputMethodSetting = inputMethod.getSetting(); 3156try { 3157 inputMethodSetting.listCurrentInputMethodSubtype((err: BusinessError, data: Array<InputMethodSubtype>) => { 3158 if (err) { 3159 console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 3160 return; 3161 } 3162 console.log('Succeeded in listing currentInputMethodSubtype.'); 3163 }); 3164} catch(err) { 3165 console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 3166} 3167``` 3168 3169### listCurrentInputMethodSubtype<sup>9+</sup> 3170 3171listCurrentInputMethodSubtype(): Promise<Array<InputMethodSubtype>> 3172 3173查询当前输入法应用的所有子类型。使用promise异步回调。 3174 3175**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3176 3177**返回值:** 3178 3179| 类型 | 说明 | 3180| ----------------------------------------------------------- | ---------------------- | 3181| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise对象,返回当前输入法应用的所有子类型。 | 3182 3183**错误码:** 3184 3185以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 3186 3187| 错误码ID | 错误信息 | 3188| -------- | -------------------------------------- | 3189| 12800001 | bundle manager error. | 3190| 12800008 | input method manager service error. | 3191 3192**示例:** 3193 3194```ts 3195import { InputMethodSubtype } from '@kit.IMEKit'; 3196import { BusinessError } from '@kit.BasicServicesKit'; 3197 3198let inputMethodSetting = inputMethod.getSetting(); 3199try { 3200 inputMethodSetting.listCurrentInputMethodSubtype().then((data: Array<InputMethodSubtype>) => { 3201 console.log('Succeeded in listing currentInputMethodSubtype.'); 3202 }).catch((err: BusinessError) => { 3203 console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 3204 }) 3205} catch(err) { 3206 console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 3207} 3208``` 3209 3210### getInputMethods<sup>9+</sup> 3211 3212getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void 3213 3214获取已激活/未激活的输入法应用列表。使用callback异步回调。 3215 3216> **说明:** 3217> 3218> 已激活输入法为使能的输入法应用。默认输入法默认使能,其他输入法可被设置为使能或非使能。 3219> 3220> 已激活输入法列表包括默认输入法和已被设置为使能的输入法应用,未激活输入法列表包括除使能输入法以外的其他已安装的输入法。 3221 3222**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3223 3224**参数:** 3225 3226| 参数名 | 类型 | 必填 | 说明 | 3227| -------- | --------------------------------------------------- | ---- | ----------------------------- | 3228| enable | boolean | 是 |true表示返回已激活输入法列表,false表示返回未激活输入法列表。 | 3229| callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | 是 | 回调函数,返回已激活/未激活输入法列表。 | 3230 3231**错误码:** 3232 3233以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 3234 3235| 错误码ID | 错误信息 | 3236| -------- | ----------------------------------- | 3237| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3238| 12800001 | bundle manager error. | 3239| 12800008 | input method manager service error. | 3240 3241**示例:** 3242 3243```ts 3244import { BusinessError } from '@kit.BasicServicesKit'; 3245 3246try { 3247 inputMethodSetting.getInputMethods(true, (err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => { 3248 if (err) { 3249 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 3250 return; 3251 } 3252 console.log('Succeeded in getting inputMethods.'); 3253 }); 3254} catch (err) { 3255 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 3256} 3257``` 3258 3259### getInputMethods<sup>9+</sup> 3260 3261getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>> 3262 3263获取已激活/未激活的输入法应用列表。使用promise异步回调。 3264 3265> **说明:** 3266> 3267> 已激活输入法为使能的输入法应用。默认输入法默认使能,其他输入法可被设置为使能或非使能。 3268> 3269> 已激活输入法列表包括默认输入法和已被设置为使能的输入法应用,未激活输入法列表包括除使能输入法以外的其他已安装的输入法。 3270 3271**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3272 3273**参数:** 3274 3275| 参数名 | 类型 | 必填 | 说明 | 3276| ------ | ------- | ---- | ----------------------- | 3277| enable | boolean | 是 |- true表示返回已激活输入法列表,false表示返回未激活输入法列表。 | 3278 3279**返回值:** 3280 3281| 类型 | 说明 | 3282| ------------------------------------------------------------ | ------------------------------------------ | 3283| Promise\<Array\<[InputMethodProperty](#inputmethodproperty8)>> | Promise对象,返回已激活/未激活输入法列表。 | 3284 3285**错误码:** 3286 3287以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 3288 3289| 错误码ID | 错误信息 | 3290| -------- | ----------------------------------- | 3291| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3292| 12800001 | bundle manager error. | 3293| 12800008 | input method manager service error. | 3294 3295**示例:** 3296 3297```ts 3298import { BusinessError } from '@kit.BasicServicesKit'; 3299 3300try { 3301 inputMethodSetting.getInputMethods(true).then((data: Array<inputMethod.InputMethodProperty>) => { 3302 console.log('Succeeded in getting inputMethods.'); 3303 }).catch((err: BusinessError) => { 3304 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 3305 }) 3306} catch(err) { 3307 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 3308} 3309``` 3310 3311### getInputMethodsSync<sup>11+</sup> 3312 3313getInputMethodsSync(enable: boolean): Array<InputMethodProperty> 3314 3315获取已激活/未激活的输入法应用列表。同步接口。 3316 3317> **说明:** 3318> 3319> 已激活输入法为使能的输入法应用。默认输入法默认使能,其他输入法可被设置为使能或非使能。 3320> 3321> 已激活输入法列表包括默认输入法和已被设置为使能的输入法应用,未激活输入法列表包括除使能输入法以外的其他已安装的输入法。 3322 3323**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3324 3325**参数:** 3326 3327| 参数名 | 类型 | 必填 | 说明 | 3328| ------ | ------- | ---- | ----------------------- | 3329| enable | boolean | 是 |- true表示返回已激活输入法列表,false表示返回未激活输入法列表。 | 3330 3331**返回值:** 3332 3333| 类型 | 说明 | 3334| ---------------------------------------------------- | ----------------------------- | 3335| Array\<[InputMethodProperty](#inputmethodproperty8)> | 返回已激活/未激活输入法列表。 | 3336 3337**错误码:** 3338 3339以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 3340 3341| 错误码ID | 错误信息 | 3342| -------- | -------------------------------------- | 3343| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3344| 12800001 | bundle manager error. | 3345| 12800008 |input method manager service error. | 3346 3347**示例:** 3348 3349```ts 3350try { 3351 let imeProp = inputMethodSetting.getInputMethodsSync(true); 3352} catch(err) { 3353 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 3354} 3355``` 3356 3357### getAllInputMethods<sup>11+</sup> 3358 3359getAllInputMethods(callback: AsyncCallback<Array<InputMethodProperty>>): void 3360 3361获取所有输入法应用列表。使用callback异步回调。 3362 3363**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3364 3365**参数:** 3366 3367| 参数名 | 类型 | 必填 | 说明 | 3368| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | 3369| callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | 是 | 回调函数,返回所有输入法列表。 | 3370 3371**错误码:** 3372 3373以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 3374 3375| 错误码ID | 错误信息 | 3376| -------- | ----------------------------------- | 3377| 12800001 | bundle manager error. | 3378| 12800008 | input method manager service error. | 3379 3380**示例:** 3381 3382```ts 3383import { BusinessError } from '@kit.BasicServicesKit'; 3384 3385try { 3386 inputMethodSetting.getAllInputMethods((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => { 3387 if (err) { 3388 console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`); 3389 return; 3390 } 3391 console.log('Succeeded in getting all inputMethods.'); 3392 }); 3393} catch (err) { 3394 console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`); 3395} 3396``` 3397 3398### getAllInputMethods<sup>11+</sup> 3399 3400getAllInputMethods(): Promise<Array<InputMethodProperty>> 3401 3402获取所有输入法应用列表。使用promise异步回调。 3403 3404**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3405 3406**返回值:** 3407 3408| 类型 | 说明 | 3409| ------------------------------------------------------------ | --------------------------------- | 3410| Promise\<Array\<[InputMethodProperty](#inputmethodproperty8)>> | Promise对象,返回所有输入法列表。 | 3411 3412**错误码:** 3413 3414以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 3415 3416| 错误码ID | 错误信息 | 3417| -------- | ----------------------------------- | 3418| 12800001 | bundle manager error. | 3419| 12800008 | input method manager service error. | 3420 3421**示例:** 3422 3423```ts 3424import { BusinessError } from '@kit.BasicServicesKit'; 3425 3426inputMethodSetting.getAllInputMethods().then((data: Array<inputMethod.InputMethodProperty>) => { 3427 console.log('Succeeded in getting all inputMethods.'); 3428}).catch((err: BusinessError) => { 3429 console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`); 3430}) 3431``` 3432 3433### getAllInputMethodsSync<sup>11+</sup> 3434 3435getAllInputMethodsSync(): Array<InputMethodProperty> 3436 3437获取所有输入法应用列表。同步接口。 3438 3439**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3440 3441**返回值:** 3442 3443| 类型 | 说明 | 3444| ---------------------------------------------------- | ------------------ | 3445| Array\<[InputMethodProperty](#inputmethodproperty8)> | 返回所有输入法列表 | 3446 3447**错误码:** 3448 3449以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 3450 3451| 错误码ID | 错误信息 | 3452| -------- | ----------------------------------- | 3453| 12800001 | bundle manager error. | 3454| 12800008 | input method manager service error. | 3455 3456**示例:** 3457 3458```ts 3459try { 3460 let imeProp = inputMethodSetting.getAllInputMethodsSync(); 3461} catch(err) { 3462 console.error(`Failed to getAllInputMethodsSync: ${JSON.stringify(err)}`); 3463} 3464``` 3465 3466### showOptionalInputMethods<sup>9+</sup> 3467 3468showOptionalInputMethods(callback: AsyncCallback<boolean>): void 3469 3470显示输入法选择对话框。使用callback异步回调。 3471 3472**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3473 3474**参数:** 3475 3476| 参数名 | 类型 | 必填 | 说明 | 3477| -------- | -------- | -------- | -------- | 3478| callback | AsyncCallback<boolean> | 是 | 回调函数。当输入法选择对话框显示成功,err为undefined,data为true;否则为错误对象。 | 3479 3480**错误码:** 3481 3482以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 3483 3484| 错误码ID | 错误信息 | 3485| -------- | -------------------------------------- | 3486| 12800008 | input method manager service error. | 3487 3488**示例:** 3489 3490```ts 3491import { BusinessError } from '@kit.BasicServicesKit'; 3492 3493try { 3494 inputMethodSetting.showOptionalInputMethods((err: BusinessError, data: boolean) => { 3495 if (err) { 3496 console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); 3497 return; 3498 } 3499 console.log('Succeeded in showing optionalInputMethods.'); 3500 }); 3501} catch (err) { 3502 console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); 3503} 3504``` 3505 3506### showOptionalInputMethods<sup>9+</sup> 3507 3508showOptionalInputMethods(): Promise<boolean> 3509 3510显示输入法选择对话框。使用promise异步回调。 3511 3512**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3513 3514**返回值:** 3515 3516| 类型 | 说明 | 3517| -------- | -------- | 3518| Promise<boolean> | Promise对象。当输入法选择对话框显示成功,err为undefined,data为true;否则为错误对象。 | 3519 3520**错误码:** 3521 3522以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md)。 3523 3524| 错误码ID | 错误信息 | 3525| -------- | -------------------------------------- | 3526| 12800008 | input method manager service error. | 3527 3528**示例:** 3529 3530```ts 3531import { BusinessError } from '@kit.BasicServicesKit'; 3532 3533inputMethodSetting.showOptionalInputMethods().then((data: boolean) => { 3534 console.log('Succeeded in showing optionalInputMethods.'); 3535}).catch((err: BusinessError) => { 3536 console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); 3537}) 3538``` 3539 3540### listInputMethod<sup>(deprecated)</sup> 3541 3542listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void 3543 3544查询已安装的输入法列表。使用callback异步回调。 3545 3546> **说明:** 3547> 3548> 从API version 8开始支持,从API version 9开始废弃,建议使用[getInputMethods](#getinputmethods9)替代。 3549 3550**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3551 3552**参数:** 3553 3554| 参数名 | 类型 | 必填 | 说明 | 3555| -------- | -------------------------------------------------- | ---- | ---------------------- | 3556| callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | 是 | 回调函数,返回已安装的输入法列表。 | 3557 3558**示例:** 3559 3560```ts 3561import { BusinessError } from '@kit.BasicServicesKit'; 3562 3563inputMethodSetting.listInputMethod((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => { 3564 if (err) { 3565 console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); 3566 return; 3567 } 3568 console.log('Succeeded in listing inputMethod.'); 3569 }); 3570``` 3571 3572### listInputMethod<sup>(deprecated)</sup> 3573 3574listInputMethod(): Promise<Array<InputMethodProperty>> 3575 3576查询已安装的输入法列表。使用promise异步回调。 3577 3578> **说明:** 3579> 3580> 从API version 8开始支持,从API version 9开始废弃,建议使用[getInputMethods](#getinputmethods9-1)替代。 3581 3582**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3583 3584**返回值:** 3585 3586| 类型 | 说明 | 3587| ----------------------------------------------------------- | ---------------------- | 3588| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise对象,返回已安装输入法列表。 | 3589 3590**示例:** 3591 3592```ts 3593import { BusinessError } from '@kit.BasicServicesKit'; 3594 3595inputMethodSetting.listInputMethod().then((data: Array<inputMethod.InputMethodProperty>) => { 3596 console.log('Succeeded in listing inputMethod.'); 3597}).catch((err: BusinessError) => { 3598 console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); 3599}) 3600``` 3601 3602### displayOptionalInputMethod<sup>(deprecated)</sup> 3603 3604displayOptionalInputMethod(callback: AsyncCallback<void>): void 3605 3606显示输入法选择对话框。使用callback异步回调。 3607 3608> **说明:** 3609> 3610> 从API version 8开始支持,从API version 9开始废弃,建议使用[showOptionalInputMethods()](#showoptionalinputmethods9)替代。 3611 3612**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3613 3614**参数:** 3615 3616| 参数名 | 类型 | 必填 | 说明 | 3617| -------- | -------- | -------- | -------- | 3618| callback | AsyncCallback<void> | 是 | 回调函数。当输入法选择对话框显示成功。err为undefined,否则为错误对象。 | 3619 3620**示例:** 3621 3622```ts 3623import { BusinessError } from '@kit.BasicServicesKit'; 3624 3625inputMethodSetting.displayOptionalInputMethod((err: BusinessError) => { 3626 if (err) { 3627 console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); 3628 return; 3629 } 3630 console.log('Succeeded in displaying optionalInputMethod.'); 3631}); 3632``` 3633 3634### displayOptionalInputMethod<sup>(deprecated)</sup> 3635 3636displayOptionalInputMethod(): Promise<void> 3637 3638显示输入法选择对话框。使用promise异步回调。 3639 3640> **说明:** 3641> 3642> 从API version 8开始支持,从API version 9开始废弃,建议使用[showOptionalInputMethods()](#showoptionalinputmethods9-1)替代。 3643 3644**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3645 3646**返回值:** 3647 3648| 类型 | 说明 | 3649| -------- | -------- | 3650| Promise<void> | 无返回结果的Promise对象。 | 3651 3652**示例:** 3653 3654```ts 3655import { BusinessError } from '@kit.BasicServicesKit'; 3656 3657inputMethodSetting.displayOptionalInputMethod().then(() => { 3658 console.log('Succeeded in displaying optionalInputMethod.'); 3659}).catch((err: BusinessError) => { 3660 console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); 3661}) 3662``` 3663 3664### getInputMethodState<sup>15+</sup> 3665 3666getInputMethodState(): Promise<EnabledState> 3667 3668查询输入法的启用状态。使用promise异步回调。 3669 3670**系统能力:** SystemCapability.MiscServices.InputMethodFramework 3671 3672**返回值:** 3673 3674| 类型 | 说明 | 3675| --------------------------------------- | ------------------------------------------------------------ | 3676| Promise\<[EnabledState](#enabledstate15)> | Promise对象,返回EnabledState.DISABLED表示未启用; 返回EnabledState.BASIC_MODE表示基础模式; 返回EnabledState.FULL_EXPERIENCE_MODE表示完整体验模式。 | 3677 3678**错误码:** 3679 3680以下错误码的详细介绍请参见[输入法框架错误码](errorcode-inputmethod-framework.md),[通用错误码说明文档](../errorcode-universal.md)。 3681 3682| 错误码ID | 错误信息 | 3683| -------- | ----------------------------------- | 3684| 12800004 | not an input method application. | 3685| 12800008 | input method manager service error. | 3686 3687**示例:** 3688 3689```ts 3690import { BusinessError } from '@kit.BasicServicesKit'; 3691 3692inputMethodSetting.getInputMethodState().then((status: inputMethod.EnabledState) => { 3693 console.log(`Succeeded in getInputMethodState, status: ${status}`); 3694}).catch((err: BusinessError) => { 3695 console.error(`Failed to getInputMethodState: ${JSON.stringify(err)}`); 3696}) 3697```