1# @ohos.inputMethod (Input Method Framework) 2 3The **inputMethod** module is oriented to common foreground applications (third-party applications and system applications such as Notes, Messaging, and Settings). It provides input method control and management capabilities, including displaying or hiding the soft keyboard, switching between input methods, and obtaining the list of all input methods. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9 10## Modules to Import 11 12```ts 13import { inputMethod } from '@kit.IMEKit'; 14``` 15 16## Constants<sup>8+</sup> 17 18Provides the constants. 19 20**System capability**: SystemCapability.MiscServices.InputMethodFramework 21 22| Name| Type| Value| Description| 23| -------- | -------- | -------- | -------- | 24| MAX_TYPE_NUM | number | 128 | Maximum number of supported input methods.| 25 26## InputMethodProperty<sup>8+</sup> 27 28Describes the input method application attributes. 29 30**System capability**: SystemCapability.MiscServices.InputMethodFramework 31 32| Name| Type| Read-only| Optional| Description| 33| -------- | -------- | -------- | -------- | -------- | 34| name<sup>9+</sup> | string | Yes| No| Mandatory. Name of the input method package.| 35| id<sup>9+</sup> | string | Yes| No| Mandatory. Unique ID of the input method.| 36| label<sup>9+</sup> | string | Yes| No| Optional. External name of the input method.| 37| labelId<sup>10+</sup> | number | Yes| No| Optional. External ID of the input method.| 38| icon<sup>9+</sup> | string | Yes| No| Optional. Icon of the input method. It can be obtained by using **iconId**. This parameter is reserved.| 39| iconId<sup>9+</sup> | number | Yes| No| Optional. Icon ID of the input method.| 40| extra<sup>9+</sup> | object | Yes| Yes| Extra information about the input method. This parameter is reserved and currently has no specific meaning.<br>- API version 10 and later: optional<br>- API version 9: mandatory| 41| packageName<sup>(deprecated)</sup> | string | Yes| No| Name of the input method package. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name** instead.| 42| methodId<sup>(deprecated)</sup> | string | Yes| No| Unique ID of the input method. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id** instead.| 43 44## inputMethod.getController<sup>9+</sup> 45 46getController(): InputMethodController 47 48Obtains an [InputMethodController](#inputmethodcontroller) instance. 49 50**System capability**: SystemCapability.MiscServices.InputMethodFramework 51 52**Return value** 53 54| Type | Description | 55| ----------------------------------------------- | ---------------------- | 56| [InputMethodController](#inputmethodcontroller) | **InputMethodController** instance.| 57 58**Error codes** 59 60For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 61 62| ID| Error Message | 63| -------- | ------------------------------ | 64| 12800006 | input method controller error. | 65 66**Example** 67 68```ts 69let inputMethodController = inputMethod.getController(); 70``` 71 72## inputMethod.getDefaultInputMethod<sup>11+</sup> 73 74getDefaultInputMethod(): InputMethodProperty 75 76Obtains the default input method. 77 78**System capability**: SystemCapability.MiscServices.InputMethodFramework 79 80**Return value** 81 82| Type | Description | 83| -------------------------------------------- | ------------------------ | 84| [InputMethodProperty](#inputmethodproperty8) | Default input method.| 85 86**Error codes** 87 88For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 89 90| ID| Error Message | 91| -------- | -------------------------------------- | 92| 12800008 | input method manager service error. | 93 94**Example** 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 108Obtains the information about the input method configuration page ability. 109 110**System capability**: SystemCapability.MiscServices.InputMethodFramework 111 112**Return value** 113 114| Type | Description | 115| -------------------------------------------- | ------------------------ | 116| [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md) | Element name of the input method configuration page ability.| 117 118**Error codes** 119 120For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 121 122| ID| Error Message | 123| -------- | -------------------------------------- | 124| 12800008 | input method manager service error. | 125 126**Example** 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 140Obtains an [InputMethodSetting](#inputmethodsetting8) instance. 141 142**System capability**: SystemCapability.MiscServices.InputMethodFramework 143 144**Return value** 145 146| Type | Description | 147| ----------------------------------------- | -------------------------- | 148| [InputMethodSetting](#inputmethodsetting8) | **InputMethodSetting** instance.| 149 150**Error codes** 151 152For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 153 154| ID| Error Message | 155| -------- | -------------------------------------- | 156| 12800007 | settings extension error. | 157 158**Example** 159 160```ts 161let inputMethodSetting = inputMethod.getSetting(); 162``` 163 164## inputMethod.switchInputMethod<sup>9+</sup> 165 166switchInputMethod(target: InputMethodProperty, callback: AsyncCallback<boolean>): void 167 168Switches to another input method. This API uses an asynchronous callback to return the result. 169> **NOTE** 170> 171> - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission. 172> - Since API version 11, this API can only be called by the current input method application. 173 174**System capability**: SystemCapability.MiscServices.InputMethodFramework 175 176**Parameters** 177 178| Name| Type| Mandatory| Description| 179| -------- | -------- | -------- | -------- | 180| target | [InputMethodProperty](#inputmethodproperty8) | Yes| Target input method.| 181| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| 182 183**Error codes** 184 185For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 186 187| ID| Error Message | 188| -------- | -------------------------------------- | 189| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 190| 12800005 | configuration persisting error. | 191| 12800008 | input method manager service error. | 192 193**Example** 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> **NOTE** 217> 218> Since API version 11, the error code "201 permissions check fails" is removed. 219 220## inputMethod.switchInputMethod<sup>9+</sup> 221switchInputMethod(target: InputMethodProperty): Promise<boolean> 222 223Switches to another input method. This API uses a promise to return the result. 224> **NOTE** 225> 226> - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission. 227> - Since API version 11, this API can only be called by the current input method application. 228 229**System capability**: SystemCapability.MiscServices.InputMethodFramework 230 231**Parameters** 232 233 | Name| Type| Mandatory| Description| 234 | -------- | -------- | -------- | -------- | 235 |target | [InputMethodProperty](#inputmethodproperty8)| Yes| Target input method.| 236 237**Return value** 238 239 | Type | Description | 240 | ----------------------------------------- | ---------------------------- | 241 | Promise\<boolean> | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.| 242 243**Error codes** 244 245For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 246 247| ID| Error Message | 248| -------- | -------------------------------------- | 249| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 250| 12800005 | configuration persisting error. | 251| 12800008 | input method manager service error. | 252 253**Example** 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> **NOTE** 275> 276> Since API version 11, the error code "201 permissions check fails" is removed. 277 278## inputMethod.getCurrentInputMethod<sup>9+</sup> 279 280getCurrentInputMethod(): InputMethodProperty 281 282Obtains the current input method. This API returns the result synchronously. 283 284**System capability**: SystemCapability.MiscServices.InputMethodFramework 285 286**Return value** 287 288| Type | Description | 289| -------------------------------------------- | ------------------------ | 290| [InputMethodProperty](#inputmethodproperty8) | **InputmethodProperty** instance of the current input method.| 291 292**Example** 293 294```ts 295let currentIme = inputMethod.getCurrentInputMethod(); 296``` 297 298## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup> 299 300switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback\<boolean>): void 301 302Switches to another subtype of this input method. This API uses an asynchronous callback to return the result. 303 304> **NOTE** 305> 306> - In API version 9 , this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission. 307> - In API version 10, this API can only be called by system applications and the current input method application, and the **ohos.permission.CONNECT_IME_ABILITY** permission is required. 308> - Since API version 11, this API can only be called by the current input method application. 309 310**System capability**: SystemCapability.MiscServices.InputMethodFramework 311 312**Parameters** 313 314| Name| Type| Mandatory| Description| 315| -------- | -------- | -------- | -------- | 316| target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.| 317| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| 318 319**Error codes** 320 321For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 322 323| ID| Error Message | 324| -------- | -------------------------------------- | 325| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 326| 12800005 | configuration persisting error. | 327| 12800008 | input method manager service error. | 328 329**Example** 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> **NOTE** 363> 364> Since API version 11, the error code "201 permissions check fails" is removed. 365 366## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup> 367 368switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise<boolean> 369 370Switches to another subtype of this input method. This API uses a promise to return the result. 371 372> **NOTE** 373> 374> - In API version 9 , this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission. 375> - In API version 10, this API can only be called by system applications and the current input method application, and the **ohos.permission.CONNECT_IME_ABILITY** permission is required. 376> - Since API version 11, this API can only be called by the current input method application. 377 378**System capability**: SystemCapability.MiscServices.InputMethodFramework 379 380**Parameters** 381 382| Name| Type| Mandatory| Description| 383| -------- | -------- | -------- | -------- | 384|target | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.| 385 386**Return value** 387 388| Type | Description | 389| ----------------------------------------- | ---------------------------- | 390| Promise\<boolean> | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.| 391 392**Error codes** 393 394For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 395 396| ID| Error Message | 397| -------- | -------------------------------------- | 398| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 399| 12800005 | configuration persisting error. | 400| 12800008 | input method manager service error. | 401 402**Example** 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> **NOTE** 434> 435> Since API version 11, the error code "201 permissions check fails" is removed. 436 437## inputMethod.getCurrentInputMethodSubtype<sup>9+</sup> 438 439getCurrentInputMethodSubtype(): InputMethodSubtype 440 441Obtains the current input method subtype. 442 443**System capability**: SystemCapability.MiscServices.InputMethodFramework 444 445**Return value** 446 447| Type | Description | 448| -------------------------------------------- | ------------------------ | 449| [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype) | Current input method subtype.| 450 451**Example** 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 461Switches to a specified subtype of a specified input method. This API uses an asynchronous callback to return the result. 462 463> **NOTE** 464> 465> - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission. 466> - Since API version 11, this API can only be called by the current input method application. 467 468**System capability**: SystemCapability.MiscServices.InputMethodFramework 469 470**Parameters** 471 472| Name| Type| Mandatory| Description| 473| -------- | -------- | -------- | -------- | 474|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Target input method.| 475|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.| 476| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| 477 478**Error codes** 479 480For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 481 482| ID| Error Message | 483| -------- | -------------------------------------- | 484| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 485| 12800005 | configuration persisting error. | 486| 12800008 | input method manager service error. | 487 488**Example** 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> **NOTE** 513> 514> Since API version 11, the error code "201 permissions check fails" is removed. 515 516## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup> 517 518switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise<boolean> 519 520Switches to a specified subtype of a specified input method. This API uses a promise to return the result. 521 522> **NOTE** 523> 524> - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission. 525> - Since API version 11, this API can only be called by the current input method application. 526 527**System capability**: SystemCapability.MiscServices.InputMethodFramework 528 529**Parameters** 530 531| Name| Type| Mandatory| Description| 532| -------- | -------- | -------- | -------- | 533|inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Target input method.| 534|inputMethodSubtype | [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.| 535 536**Return value** 537 538| Type | Description | 539| ----------------------------------------- | ---------------------------- | 540| Promise\<boolean> | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.| 541 542**Error codes** 543 544For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 545 546| ID| Error Message | 547| -------- | -------------------------------------- | 548| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 549| 12800005 | configuration persisting error. | 550| 12800008 | input method manager service error. | 551 552**Example** 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> **NOTE** 575> 576> Since API version 11, the error code "201 permissions check fails" is removed. 577 578## inputMethod.getInputMethodController<sup>(deprecated)</sup> 579 580getInputMethodController(): InputMethodController 581 582Obtains an [InputMethodController](#inputmethodcontroller) instance. 583 584> **NOTE** 585> 586> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getController()](#inputmethodgetcontroller9) instead. 587 588**System capability**: SystemCapability.MiscServices.InputMethodFramework 589 590**Return value** 591 592| Type | Description | 593| ----------------------------------------------- | ------------------------ | 594| [InputMethodController](#inputmethodcontroller) | Current **InputMethodController** instance.| 595 596**Example** 597 598```ts 599let inputMethodController = inputMethod.getInputMethodController(); 600``` 601 602## inputMethod.getInputMethodSetting<sup>(deprecated)</sup> 603 604getInputMethodSetting(): InputMethodSetting 605 606Obtains an [InputMethodSetting](#inputmethodsetting8) instance. 607 608> **NOTE** 609> 610> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getSetting()](#inputmethodgetsetting9) instead. 611 612**System capability**: SystemCapability.MiscServices.InputMethodFramework 613 614**Return value** 615 616| Type | Description | 617| ----------------------------------------- | -------------------------- | 618| [InputMethodSetting](#inputmethodsetting8) | **InputMethodSetting** instance.| 619 620**Example** 621 622```ts 623let inputMethodSetting = inputMethod.getInputMethodSetting(); 624``` 625 626## TextInputType<sup>10+</sup> 627 628Enumerates the text input types. 629 630**System capability**: SystemCapability.MiscServices.InputMethodFramework 631 632| Name| Value|Description| 633| -------- | -------- |-------- | 634| NONE | -1 |None.| 635| TEXT | 0 |Text.| 636| MULTILINE | 1 |Multi-line.| 637| NUMBER | 2 |Number.| 638| PHONE | 3 |Phone number.| 639| DATETIME | 4 |Date.| 640| EMAIL_ADDRESS | 5 |Email address.| 641| URL | 6 |URL.| 642| VISIBLE_PASSWORD | 7 |Password.| 643| NUMBER_PASSWORD<sup>11+</sup> | 8 |Numeric password.| 644 645## EnterKeyType<sup>10+</sup> 646 647Enumerates the function types represented by the Enter key of the input method. 648 649**System capability**: SystemCapability.MiscServices.InputMethodFramework 650 651| Name| Value|Description| 652| -------- | -------- |-------- | 653| UNSPECIFIED | 0 |Not specified.| 654| NONE | 1 |None.| 655| GO | 2 |Go.| 656| SEARCH | 3 |Search.| 657| SEND | 4 |Send.| 658| NEXT | 5 |Next.| 659| DONE | 6 |Done.| 660| PREVIOUS | 7 |Previous.| 661| NEWLINE<sup>12+</sup> | 8 | Line break.| 662 663## KeyboardStatus<sup>10+</sup> 664 665Enumerates the soft keyboard states of the input method. 666 667**System capability**: SystemCapability.MiscServices.InputMethodFramework 668 669| Name| Value|Description| 670| -------- | -------- |-------- | 671| NONE | 0 |None.| 672| HIDE | 1 |Hidden.| 673| SHOW | 2 |Shown.| 674 675## Direction<sup>10+</sup> 676 677Enumerates the directions of cursor movement of the input method. 678 679**System capability**: SystemCapability.MiscServices.InputMethodFramework 680 681| Name| Value|Description| 682| -------- | -------- |-------- | 683| CURSOR_UP | 1 |Upward.| 684| CURSOR_DOWN | 2 |Downward.| 685| CURSOR_LEFT | 3 |Leftward.| 686| CURSOR_RIGHT | 4 |Rightward.| 687 688## ExtendAction<sup>10+</sup> 689 690Describes the type of the extended edit action on the text box. 691 692**System capability**: SystemCapability.MiscServices.InputMethodFramework 693 694| Name| Value|Description| 695| -------- | -------- |-------- | 696| SELECT_ALL | 0 |Select all.| 697| CUT | 3 |Cut.| 698| COPY | 4 |Copy.| 699| PASTE | 5 |Paste.| 700 701## FunctionKey<sup>10+</sup> 702 703Describes the type of the input method function key. 704 705**System capability**: SystemCapability.MiscServices.InputMethodFramework 706 707| Name| Type| Read-only| Optional| Description| 708| -------- | -------- | -------- | -------- | -------- | 709| enterKeyType<sup>10+</sup> | [EnterKeyType](#enterkeytype10) | Yes| Yes| Function type represented by the Enter key of the input method.| 710 711## InputAttribute<sup>10+</sup> 712 713Describes the attributes of the edit box, including the text input type and Enter key function type. 714 715**System capability**: SystemCapability.MiscServices.InputMethodFramework 716 717| Name| Type| Read-only| Optional| Description| 718| -------- | -------- | -------- | -------- | -------- | 719| textInputType<sup>10+</sup> | [TextInputType](#textinputtype10) | Yes| Yes| Enumerates the text input types.| 720| enterKeyType<sup>10+</sup> | [EnterKeyType](#enterkeytype10) | Yes| Yes| Function type represented by the Enter key.| 721 722## TextConfig<sup>10+</sup> 723 724Describes the configuration of the edit box. 725 726**System capability**: SystemCapability.MiscServices.InputMethodFramework 727 728| Name| Type| Read-only| Optional| Description| 729| -------- | -------- | -------- | -------- | -------- | 730| inputAttribute<sup>10+</sup> | [InputAttribute](#inputattribute10) | No| Yes| Edit box attribute.| 731| cursorInfo<sup>10+</sup> | [CursorInfo](#cursorinfo10) | No| No| Cursor information.| 732| selection<sup>10+</sup> | [Range](#range10) | No| No| Text selection range.| 733| windowId<sup>10+</sup> | number | No| No| ID of the window where the edit box is located.| 734 735## CursorInfo<sup>10+</sup> 736 737Represents the cursor information. 738 739**System capability**: SystemCapability.MiscServices.InputMethodFramework 740 741| Name| Type| Read-only| Optional| Description| 742| -------- | -------- | -------- | -------- | -------- | 743| left | number | Yes| Yes| Left coordinate of the cursor.| 744| top | number | Yes| Yes| Top coordinate of the cursor.| 745| width | number | Yes| Yes| Width of the cursor.| 746| height | number | Yes| Yes| Height of the cursor.| 747 748## Range<sup>10+</sup> 749 750Describes the range of the selected text. 751 752**System capability**: SystemCapability.MiscServices.InputMethodFramework 753 754| Name| Type| Read-only| Optional| Description| 755| -------- | -------- | -------- | -------- | -------- | 756| start | number | Yes| Yes| Index of the first selected character in the text box.| 757| end | number | Yes| Yes| Index of the last selected character in the text box.| 758 759## Movement<sup>10+</sup> 760 761Describes the direction in which the cursor moves when the text is selected. 762 763**System capability**: SystemCapability.MiscServices.InputMethodFramework 764 765| Name| Type| Read-only| Optional| Description| 766| -------- | -------- | -------- | -------- | -------- | 767| direction | [Direction](#direction10) | Yes| Yes| Direction in which the cursor moves when the text is selected.| 768 769## InputWindowInfo<sup>10+</sup> 770 771Describes the window information of the input method keyboard. 772 773**System capability**: SystemCapability.MiscServices.InputMethodFramework 774 775| Name| Type| Read-only| Optional| Description| 776| -------- | -------- | -------- | -------- | -------- | 777| name | string | Yes| Yes| Name of the input method keyboard window.| 778| left | number | Yes| Yes| Horizontal coordinate of the upper left corner of the input method keyboard window, in px.| 779| top | number | Yes| Yes| Vertical coordinate of the upper left corner of the input method keyboard window, in px.| 780| width | number | Yes| Yes| Width of the input method keyboard window, in px.| 781| height | number | Yes| Yes| Height of the input method keyboard window, in px.| 782 783## InputMethodController 784 785In the following API examples, you must first use [getController](#inputmethodgetcontroller9) to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance. 786 787### attach<sup>10+</sup> 788 789attach(showKeyboard: boolean, textConfig: TextConfig, callback: AsyncCallback<void>): void 790 791Attaches a self-drawing component to the input method. This API uses an asynchronous callback to return the result. 792 793> **NOTE** 794> 795> An input method can use the following features only when it has a self-drawing component attached to it: showing or hiding the keyboard, updating the cursor information, changing the selection range of the edit box, saving the configuration information, and listening for and processing the information or commands sent by the input method. 796 797**System capability**: SystemCapability.MiscServices.InputMethodFramework 798 799**Parameters** 800 801| Name| Type| Mandatory| Description| 802| -------- | -------- | -------- | -------- | 803| showKeyboard | boolean | Yes| Whether to start the input method keyboard after the self-drawing component is attached to the input method.<br>- The value **true** means to start the input method keyboard, and **false** means the opposite.| 804| textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the edit box.| 805| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 806 807**Error codes** 808 809For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 810 811| ID| Error Message | 812| -------- | -------------------------------------- | 813| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 814| 12800003 | input method client error. | 815| 12800008 | input method manager service error. | 816 817**Example** 818 819```ts 820import { BusinessError } from '@kit.BasicServicesKit'; 821 822try { 823 let textConfig: inputMethod.TextConfig = { 824 inputAttribute: { 825 textInputType: 0, 826 enterKeyType: 1 827 } 828 }; 829 inputMethodController.attach(true, textConfig, (err: BusinessError) => { 830 if (err) { 831 console.error(`Failed to attach: ${JSON.stringify(err)}`); 832 return; 833 } 834 console.log('Succeeded in attaching the inputMethod.'); 835 }); 836} catch(err) { 837 console.error(`Failed to attach: ${JSON.stringify(err)}`); 838} 839``` 840 841### attach<sup>10+</sup> 842 843attach(showKeyboard: boolean, textConfig: TextConfig): Promise<void> 844 845Attaches a self-drawing component to the input method. This API uses a promise to return the result. 846 847> **NOTE** 848> 849> An input method can use the following features only when it has a self-drawing component attached to it: showing or hiding the keyboard, updating the cursor information, changing the selection range of the edit box, saving the configuration information, and listening for and processing the information or commands sent by the input method. 850 851**System capability**: SystemCapability.MiscServices.InputMethodFramework 852 853**Parameters** 854 855| Name| Type| Mandatory| Description| 856| -------- | -------- | -------- | -------- | 857| showKeyboard | boolean | Yes| Whether to start the input method keyboard after the self-drawing component is attached to the input method.<br>- The value **true** means to start the input method keyboard, and **false** means the opposite.| 858| textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the edit box.| 859 860**Return value** 861 862| Type| Description| 863| -------- | -------- | 864| Promise<void> | Promise that returns no value.| 865 866**Error codes** 867 868For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 869 870| ID| Error Message | 871| -------- | -------------------------------------- | 872| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 873| 12800003 | input method client error. | 874| 12800008 | input method manager service error. | 875 876**Example** 877 878```ts 879import { BusinessError } from '@kit.BasicServicesKit'; 880 881try { 882 let textConfig: inputMethod.TextConfig = { 883 inputAttribute: { 884 textInputType: 0, 885 enterKeyType: 1 886 } 887 }; 888 inputMethodController.attach(true, textConfig).then(() => { 889 console.log('Succeeded in attaching inputMethod.'); 890 }).catch((err: BusinessError) => { 891 console.error(`Failed to attach: ${JSON.stringify(err)}`); 892 }) 893} catch(err) { 894 console.error(`Failed to attach: ${JSON.stringify(err)}`); 895} 896``` 897 898### showTextInput<sup>10+</sup> 899 900showTextInput(callback: AsyncCallback<void>): void 901 902Enters the text editing mode. This API uses an asynchronous callback to return the result. 903 904> **NOTE** 905> 906> After the edit box is attached to an input method, this API can be called to start the soft keyboard and enter the text editing state. 907 908**System capability**: SystemCapability.MiscServices.InputMethodFramework 909 910**Parameters** 911 912| Name| Type| Mandatory| Description| 913| -------- | -------- | -------- | -------- | 914| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 915 916**Error codes** 917 918For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 919 920| ID| Error Message | 921| -------- | -------------------------------------- | 922| 12800003 | input method client error. | 923| 12800008 | input method manager service error. | 924| 12800009 | input method client is detached. | 925 926**Example** 927 928```ts 929import { BusinessError } from '@kit.BasicServicesKit'; 930 931inputMethodController.showTextInput((err: BusinessError) => { 932 if (err) { 933 console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); 934 return; 935 } 936 console.log('Succeeded in showing the inputMethod.'); 937}); 938``` 939 940### showTextInput<sup>10+</sup> 941 942showTextInput(): Promise<void> 943 944Enters the text editing mode. This API uses a promise to return the result. 945 946> **NOTE** 947> 948> After the edit box is attached to an input method, this API can be called to start the soft keyboard and enter the text editing state. 949 950**System capability**: SystemCapability.MiscServices.InputMethodFramework 951 952**Return value** 953 954| Type| Description| 955| -------- | -------- | 956| Promise<void> | Promise that returns no value.| 957 958**Error codes** 959 960For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 961 962| ID| Error Message | 963| -------- | -------------------------------------- | 964| 12800003 | input method client error. | 965| 12800008 | input method manager service error. | 966| 12800009 | input method client is detached. | 967 968**Example** 969 970```ts 971import { BusinessError } from '@kit.BasicServicesKit'; 972 973inputMethodController.showTextInput().then(() => { 974 console.log('Succeeded in showing text input.'); 975}).catch((err: BusinessError) => { 976 console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); 977}); 978``` 979 980### hideTextInput<sup>10+</sup> 981 982hideTextInput(callback: AsyncCallback<void>): void 983 984Exits the text editing mode. This API uses an asynchronous callback to return the result. 985 986> **NOTE** 987> 988> If the soft keyboard is displayed when this API is called, it will be hidden. 989> 990> Calling this API does not detach the edit box from the input method. The edit box can call [showTextInput](#showtextinput10) again to reenter the text editing mode. 991 992**System capability**: SystemCapability.MiscServices.InputMethodFramework 993 994**Parameters** 995 996| Name| Type| Mandatory| Description| 997| -------- | -------- | -------- | -------- | 998| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 999 1000**Error codes** 1001 1002For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1003 1004| ID| Error Message | 1005| -------- | -------------------------------------- | 1006| 12800003 | input method client error. | 1007| 12800008 | input method manager service error. | 1008| 12800009 | input method client is detached. | 1009 1010**Example** 1011 1012```ts 1013import { BusinessError } from '@kit.BasicServicesKit'; 1014 1015inputMethodController.hideTextInput((err: BusinessError) => { 1016 if (err) { 1017 console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); 1018 return; 1019 } 1020 console.log('Succeeded in hiding text input.'); 1021}); 1022``` 1023 1024### hideTextInput<sup>10+</sup> 1025 1026hideTextInput(): Promise<void> 1027 1028Exits the text editing mode. This API uses a promise to return the result. 1029 1030> **NOTE** 1031> 1032> If the soft keyboard is displayed when this API is called, it will be hidden. 1033> 1034> Calling this API does not detach the edit box from the input method. The edit box can call [showTextInput](#showtextinput10) again to reenter the text editing mode. 1035 1036**System capability**: SystemCapability.MiscServices.InputMethodFramework 1037 1038**Return value** 1039 1040| Type| Description| 1041| -------- | -------- | 1042| Promise<void> | Promise that returns no value.| 1043 1044**Error codes** 1045 1046For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1047 1048| ID| Error Message | 1049| -------- | -------------------------------------- | 1050| 12800003 | input method client error. | 1051| 12800008 | input method manager service error. | 1052| 12800009 | input method client is detached. | 1053 1054**Example** 1055 1056```ts 1057import { BusinessError } from '@kit.BasicServicesKit'; 1058 1059inputMethodController.hideTextInput().then(() => { 1060 console.log('Succeeded in hiding inputMethod.'); 1061}).catch((err: BusinessError) => { 1062 console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); 1063}) 1064``` 1065 1066### detach<sup>10+</sup> 1067 1068detach(callback: AsyncCallback<void>): void 1069 1070Detaches the self-drawing component from the input method. This API uses an asynchronous callback to return the result. 1071 1072**System capability**: SystemCapability.MiscServices.InputMethodFramework 1073 1074**Parameters** 1075 1076| Name| Type| Mandatory| Description| 1077| -------- | -------- | -------- | -------- | 1078| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1079 1080**Error codes** 1081 1082For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1083 1084| ID| Error Message | 1085| -------- | -------------------------------------- | 1086| 12800003 | input method client error. | 1087| 12800008 | input method manager service error. | 1088 1089**Example** 1090 1091```ts 1092import { BusinessError } from '@kit.BasicServicesKit'; 1093 1094inputMethodController.detach((err: BusinessError) => { 1095 if (err) { 1096 console.error(`Failed to detach: ${JSON.stringify(err)}`); 1097 return; 1098 } 1099 console.log('Succeeded in detaching inputMethod.'); 1100}); 1101``` 1102 1103### detach<sup>10+</sup> 1104 1105detach(): Promise<void> 1106 1107Detaches the self-drawing component from the input method. This API uses a promise to return the result. 1108 1109**System capability**: SystemCapability.MiscServices.InputMethodFramework 1110 1111**Return value** 1112 1113| Type| Description| 1114| -------- | -------- | 1115| Promise<void> | Promise that returns no value.| 1116 1117**Error codes** 1118 1119For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1120 1121| ID| Error Message | 1122| -------- | -------------------------------------- | 1123| 12800003 | input method client error. | 1124| 12800008 | input method manager service error. | 1125 1126**Example** 1127 1128```ts 1129import { BusinessError } from '@kit.BasicServicesKit'; 1130 1131inputMethodController.detach().then(() => { 1132 console.log('Succeeded in detaching inputMethod.'); 1133}).catch((err: BusinessError) => { 1134 console.error(`Failed to detach: ${JSON.stringify(err)}`); 1135}); 1136``` 1137 1138### setCallingWindow<sup>10+</sup> 1139 1140setCallingWindow(windowId: number, callback: AsyncCallback<void>): void 1141 1142Sets the window to be avoided by the input method. This API uses an asynchronous callback to return the result. 1143 1144> **NOTE** 1145> 1146> After the window ID of the application bound to the input method is passed in the API, the input method window will not cover the window holding the application. 1147 1148**System capability**: SystemCapability.MiscServices.InputMethodFramework 1149 1150**Parameters** 1151 1152| Name| Type| Mandatory| Description| 1153| -------- | -------- | -------- | -------- | 1154| windowId | number | Yes| Window ID of the application bound to the input method.| 1155| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1156 1157**Error codes** 1158 1159For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1160 1161| ID| Error Message | 1162| -------- | -------------------------------------- | 1163| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1164| 12800003 | input method client error. | 1165| 12800008 | input method manager service error. | 1166| 12800009 | input method client is detached. | 1167 1168**Example** 1169 1170```ts 1171import { BusinessError } from '@kit.BasicServicesKit'; 1172 1173try { 1174 let windowId: number = 2000; 1175 inputMethodController.setCallingWindow(windowId, (err: BusinessError) => { 1176 if (err) { 1177 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 1178 return; 1179 } 1180 console.log('Succeeded in setting callingWindow.'); 1181 }); 1182} catch(err) { 1183 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 1184} 1185``` 1186 1187### setCallingWindow<sup>10+</sup> 1188 1189setCallingWindow(windowId: number): Promise<void> 1190 1191Sets the window to be avoided by the input method. This API uses a promise to return the result. 1192 1193> **NOTE** 1194> 1195> After the window ID of the application bound to the input method is passed in the API, the input method window will not cover the window holding the application. 1196 1197**System capability**: SystemCapability.MiscServices.InputMethodFramework 1198 1199**Parameters** 1200 1201| Name| Type| Mandatory| Description| 1202| -------- | -------- | -------- | -------- | 1203| windowId | number | Yes| Window ID of the application bound to the input method.| 1204 1205**Return value** 1206 1207| Type| Description| 1208| -------- | -------- | 1209| Promise<void> | Promise that returns no value.| 1210 1211**Error codes** 1212 1213For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1214 1215| ID| Error Message | 1216| -------- | -------------------------------------- | 1217| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1218| 12800003 | input method client error. | 1219| 12800008 | input method manager service error. | 1220| 12800009 | input method client is detached. | 1221 1222**Example** 1223 1224```ts 1225import { BusinessError } from '@kit.BasicServicesKit'; 1226 1227try { 1228 let windowId: number = 2000; 1229 inputMethodController.setCallingWindow(windowId).then(() => { 1230 console.log('Succeeded in setting callingWindow.'); 1231 }).catch((err: BusinessError) => { 1232 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 1233 }) 1234} catch(err) { 1235 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 1236} 1237``` 1238 1239### updateCursor<sup>10+</sup> 1240 1241updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback<void>): void 1242 1243Updates the cursor information in this edit box. This API can be called to notify the input method of the cursor changes. This API uses an asynchronous callback to return the result. 1244 1245**System capability**: SystemCapability.MiscServices.InputMethodFramework 1246 1247**Parameters** 1248 1249| Name| Type| Mandatory| Description| 1250| -------- | -------- | -------- | -------- | 1251| cursorInfo | [CursorInfo](#cursorinfo10) | Yes| Cursor information.| 1252| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1253 1254**Error codes** 1255 1256For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1257 1258| ID| Error Message | 1259| -------- | -------------------------------------- | 1260| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1261| 12800003 | input method client error. | 1262| 12800008 | input method manager service error. | 1263| 12800009 | input method client is detached. | 1264 1265**Example** 1266 1267```ts 1268import { BusinessError } from '@kit.BasicServicesKit'; 1269 1270try { 1271 let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 }; 1272 inputMethodController.updateCursor(cursorInfo, (err: BusinessError) => { 1273 if (err) { 1274 console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); 1275 return; 1276 } 1277 console.log('Succeeded in updating cursorInfo.'); 1278 }); 1279} catch(err) { 1280 console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); 1281} 1282``` 1283 1284### updateCursor<sup>10+</sup> 1285 1286updateCursor(cursorInfo: CursorInfo): Promise<void> 1287 1288Updates the cursor information in this edit box. This API can be called to notify the input method of the cursor changes. This API uses a promise to return the result. 1289 1290**System capability**: SystemCapability.MiscServices.InputMethodFramework 1291 1292**Parameters** 1293 1294| Name| Type| Mandatory| Description| 1295| -------- | -------- | -------- | -------- | 1296| cursorInfo | [CursorInfo](#cursorinfo10) | Yes| Cursor information.| 1297 1298**Return value** 1299 1300| Type| Description| 1301| -------- | -------- | 1302| Promise<void> | Promise that returns no value.| 1303 1304**Error codes** 1305 1306For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1307 1308| ID| Error Message | 1309| -------- | -------------------------------------- | 1310| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1311| 12800003 | input method client error. | 1312| 12800008 | input method manager service error. | 1313| 12800009 | input method client is detached. | 1314 1315**Example** 1316 1317```ts 1318import { BusinessError } from '@kit.BasicServicesKit'; 1319 1320try { 1321 let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 }; 1322 inputMethodController.updateCursor(cursorInfo).then(() => { 1323 console.log('Succeeded in updating cursorInfo.'); 1324 }).catch((err: BusinessError) => { 1325 console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); 1326 }) 1327} catch(err) { 1328 console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); 1329} 1330``` 1331 1332### changeSelection<sup>10+</sup> 1333 1334changeSelection(text: string, start: number, end: number, callback: AsyncCallback<void>): void 1335 1336Updates the information about the selected text in this edit box, to notify the input method when the selected text content or text range changes. This API uses an asynchronous callback to return the result. 1337 1338**System capability**: SystemCapability.MiscServices.InputMethodFramework 1339 1340**Parameters** 1341 1342| Name| Type| Mandatory| Description| 1343| -------- | -------- | -------- | -------- | 1344| text | string | Yes| All input text.| 1345| start | number | Yes| Start position of the selected text.| 1346| end | number | Yes| End position of the selected text.| 1347| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1348 1349**Error codes** 1350 1351For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1352 1353| ID| Error Message | 1354| -------- | -------------------------------------- | 1355| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1356| 12800003 | input method client error. | 1357| 12800008 | input method manager service error. | 1358| 12800009 | input method client is detached. | 1359 1360**Example** 1361 1362```ts 1363import { BusinessError } from '@kit.BasicServicesKit'; 1364 1365try { 1366 inputMethodController.changeSelection('text', 0, 5, (err: BusinessError) => { 1367 if (err) { 1368 console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); 1369 return; 1370 } 1371 console.log('Succeeded in changing selection.'); 1372 }); 1373} catch(err) { 1374 console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); 1375} 1376``` 1377 1378### changeSelection<sup>10+</sup> 1379 1380changeSelection(text: string, start: number, end: number): Promise<void> 1381 1382Updates the information about the selected text in this edit box, to notify the input method when the selected text content or text range changes. This API uses a promise to return the result. 1383 1384**System capability**: SystemCapability.MiscServices.InputMethodFramework 1385 1386**Parameters** 1387 1388| Name| Type| Mandatory| Description| 1389| -------- | -------- | -------- | -------- | 1390| text | string | Yes| All input text.| 1391| start | number | Yes| Start position of the selected text.| 1392| end | number | Yes| End position of the selected text.| 1393 1394**Return value** 1395 1396| Type| Description| 1397| -------- | -------- | 1398| Promise<void> | Promise that returns no value.| 1399 1400**Error codes** 1401 1402For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1403 1404| ID| Error Message | 1405| -------- | -------------------------------------- | 1406| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1407| 12800003 | input method client error. | 1408| 12800008 | input method manager service error. | 1409| 12800009 | input method client is detached. | 1410 1411**Example** 1412 1413```ts 1414import { BusinessError } from '@kit.BasicServicesKit'; 1415 1416try { 1417 inputMethodController.changeSelection('test', 0, 5).then(() => { 1418 console.log('Succeeded in changing selection.'); 1419 }).catch((err: BusinessError) => { 1420 console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); 1421 }) 1422} catch(err) { 1423 console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); 1424} 1425``` 1426 1427### updateAttribute<sup>10+</sup> 1428 1429updateAttribute(attribute: InputAttribute, callback: AsyncCallback<void>): void 1430 1431Updates the attribute information of this edit box. This API uses an asynchronous callback to return the result. 1432 1433**System capability**: SystemCapability.MiscServices.InputMethodFramework 1434 1435**Parameters** 1436 1437| Name| Type| Mandatory| Description| 1438| -------- | -------- | -------- | -------- | 1439| attribute | [InputAttribute](#inputattribute10) | Yes| Attribute information.| 1440| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1441 1442**Error codes** 1443 1444For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1445 1446| ID| Error Message | 1447| -------- | -------------------------------------- | 1448| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1449| 12800003 | input method client error. | 1450| 12800008 | input method manager service error. | 1451| 12800009 | input method client is detached. | 1452 1453**Example** 1454 1455```ts 1456import { BusinessError } from '@kit.BasicServicesKit'; 1457 1458try { 1459 let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; 1460 inputMethodController.updateAttribute(inputAttribute, (err: BusinessError) => { 1461 if (err) { 1462 console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); 1463 return; 1464 } 1465 console.log('Succeeded in updating attribute.'); 1466 }); 1467} catch(err) { 1468 console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); 1469} 1470``` 1471 1472### updateAttribute<sup>10+</sup> 1473 1474updateAttribute(attribute: InputAttribute): Promise<void> 1475 1476Updates the attribute information of this edit box. This API uses a promise to return the result. 1477 1478**System capability**: SystemCapability.MiscServices.InputMethodFramework 1479 1480**Parameters** 1481 1482| Name| Type| Mandatory| Description| 1483| -------- | -------- | -------- | -------- | 1484| attribute | [InputAttribute](#inputattribute10) | Yes| Attribute information.| 1485 1486**Return value** 1487 1488| Type| Description| 1489| -------- | -------- | 1490| Promise<void> | Promise that returns no value.| 1491 1492**Error codes** 1493 1494For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1495 1496| ID| Error Message | 1497| -------- | -------------------------------------- | 1498| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1499| 12800003 | input method client error. | 1500| 12800008 | input method manager service error. | 1501| 12800009 | input method client is detached. | 1502 1503**Example** 1504 1505```ts 1506import { BusinessError } from '@kit.BasicServicesKit'; 1507 1508try { 1509 let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; 1510 inputMethodController.updateAttribute(inputAttribute).then(() => { 1511 console.log('Succeeded in updating attribute.'); 1512 }).catch((err: BusinessError) => { 1513 console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); 1514 }) 1515} catch(err) { 1516 console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); 1517} 1518``` 1519 1520### stopInputSession<sup>9+</sup> 1521 1522stopInputSession(callback: AsyncCallback<boolean>): void 1523 1524Ends this input session. This API uses an asynchronous callback to return the result. 1525 1526> **NOTE** 1527> 1528> This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused. 1529 1530**System capability**: SystemCapability.MiscServices.InputMethodFramework 1531 1532**Parameters** 1533 1534| Name| Type| Mandatory| Description| 1535| -------- | -------- | -------- | -------- | 1536| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| 1537 1538**Error codes** 1539 1540For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1541 1542| ID| Error Message | 1543| -------- | -------------------------------------- | 1544| 12800003 | input method client error. | 1545| 12800008 | input method manager service error. | 1546 1547**Example** 1548 1549```ts 1550import { BusinessError } from '@kit.BasicServicesKit'; 1551 1552try { 1553 inputMethodController.stopInputSession((err: BusinessError, result: boolean) => { 1554 if (err) { 1555 console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); 1556 return; 1557 } 1558 if (result) { 1559 console.log('Succeeded in stopping inputSession.'); 1560 } else { 1561 console.error('Failed to stopInputSession.'); 1562 } 1563 }); 1564} catch(err) { 1565 console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); 1566} 1567``` 1568 1569### stopInputSession<sup>9+</sup> 1570 1571stopInputSession(): Promise<boolean> 1572 1573Ends this input session. This API uses a promise to return the result. 1574 1575> **NOTE** 1576> 1577> This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused. 1578 1579**System capability**: SystemCapability.MiscServices.InputMethodFramework 1580 1581**Return value** 1582 1583| Type| Description| 1584| -------- | -------- | 1585| Promise<boolean> | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.| 1586 1587**Error codes** 1588 1589For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1590 1591| ID| Error Message | 1592| -------- | -------------------------------------- | 1593| 12800003 | input method client error. | 1594| 12800008 | input method manager service error. | 1595 1596**Example** 1597 1598```ts 1599import { BusinessError } from '@kit.BasicServicesKit'; 1600 1601try { 1602 inputMethodController.stopInputSession().then((result: boolean) => { 1603 if (result) { 1604 console.log('Succeeded in stopping inputSession.'); 1605 } else { 1606 console.error('Failed to stopInputSession.'); 1607 } 1608 }).catch((err: BusinessError) => { 1609 console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); 1610 }) 1611} catch(err) { 1612 console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); 1613} 1614``` 1615 1616### showSoftKeyboard<sup>9+</sup> 1617 1618showSoftKeyboard(callback: AsyncCallback<void>): void 1619 1620Shows the soft keyboard. This API uses an asynchronous callback to return the result. 1621 1622> **NOTE** 1623> 1624> This API can be called only when the edit box is attached to the input method. That is, it can be called to show the soft keyboard only when the edit box is focused. 1625 1626**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) 1627 1628**System capability**: SystemCapability.MiscServices.InputMethodFramework 1629 1630**Parameters** 1631 1632| Name | Type | Mandatory| Description | 1633| -------- | ------------------------- | ---- | ---------- | 1634| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1635 1636**Error codes** 1637 1638For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1639 1640| ID| Error Message | 1641| -------- | -------------------------------------- | 1642| 201 | permissions check fails. | 1643| 12800003 | input method client error. | 1644| 12800008 | input method manager service error. | 1645 1646**Example** 1647 1648```ts 1649import { BusinessError } from '@kit.BasicServicesKit'; 1650 1651inputMethodController.showSoftKeyboard((err: BusinessError) => { 1652 if (!err) { 1653 console.log('Succeeded in showing softKeyboard.'); 1654 } else { 1655 console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); 1656 } 1657}) 1658``` 1659 1660### showSoftKeyboard<sup>9+</sup> 1661 1662showSoftKeyboard(): Promise<void> 1663 1664Shows the soft keyboard. This API uses a promise to return the result. 1665 1666> **NOTE** 1667> 1668> This API can be called only when the edit box is attached to the input method. That is, it can be called to show the soft keyboard only when the edit box is focused. 1669 1670**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) 1671 1672**System capability**: SystemCapability.MiscServices.InputMethodFramework 1673 1674**Return value** 1675 1676| Type | Description | 1677| ------------------- | ------------------------- | 1678| Promise<void> | Promise that returns no value.| 1679 1680**Error codes** 1681 1682For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1683 1684| ID| Error Message | 1685| -------- | -------------------------------------- | 1686| 201 | permissions check fails. | 1687| 12800003 | input method client error. | 1688| 12800008 | input method manager service error. | 1689 1690**Example** 1691 1692```ts 1693import { BusinessError } from '@kit.BasicServicesKit'; 1694 1695inputMethodController.showSoftKeyboard().then(() => { 1696 console.log('Succeeded in showing softKeyboard.'); 1697}).catch((err: BusinessError) => { 1698 console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); 1699}); 1700``` 1701 1702### hideSoftKeyboard<sup>9+</sup> 1703 1704hideSoftKeyboard(callback: AsyncCallback<void>): void 1705 1706Hides the soft keyboard. This API uses an asynchronous callback to return the result. 1707 1708> **NOTE** 1709> 1710> This API can be called only when the edit box is attached to the input method. That is, it can be called to hide the soft keyboard only when the edit box is focused. 1711 1712**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) 1713 1714**System capability**: SystemCapability.MiscServices.InputMethodFramework 1715 1716**Parameters** 1717 1718| Name | Type | Mandatory| Description | 1719| -------- | ------------------------- | ---- | ---------- | 1720| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1721 1722**Error codes** 1723 1724For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1725 1726| ID| Error Message | 1727| -------- | -------------------------------------- | 1728| 201 | permissions check fails. | 1729| 12800003 | input method client error. | 1730| 12800008 | input method manager service error. | 1731 1732**Example** 1733 1734```ts 1735import { BusinessError } from '@kit.BasicServicesKit'; 1736 1737inputMethodController.hideSoftKeyboard((err: BusinessError) => { 1738 if (!err) { 1739 console.log('Succeeded in hiding softKeyboard.'); 1740 } else { 1741 console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); 1742 } 1743}) 1744``` 1745 1746### hideSoftKeyboard<sup>9+</sup> 1747 1748hideSoftKeyboard(): Promise<void> 1749 1750Hides the soft keyboard. This API uses a promise to return the result. 1751 1752> **NOTE** 1753> 1754> This API can be called only when the edit box is attached to the input method. That is, it can be called to hide the soft keyboard only when the edit box is focused. 1755 1756**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) 1757 1758**System capability**: SystemCapability.MiscServices.InputMethodFramework 1759 1760**Return value** 1761 1762| Type | Description | 1763| ------------------- | ------------------------- | 1764| Promise<void> | Promise that returns no value.| 1765 1766**Error codes** 1767 1768For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1769 1770| ID| Error Message | 1771| -------- | -------------------------------------- | 1772| 201 | permissions check fails. | 1773| 12800003 | input method client error. | 1774| 12800008 | input method manager service error. | 1775 1776**Example** 1777 1778```ts 1779import { BusinessError } from '@kit.BasicServicesKit'; 1780 1781inputMethodController.hideSoftKeyboard().then(() => { 1782 console.log('Succeeded in hiding softKeyboard.'); 1783}).catch((err: BusinessError) => { 1784 console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); 1785}); 1786``` 1787 1788### stopInput<sup>(deprecated)</sup> 1789 1790stopInput(callback: AsyncCallback<boolean>): void 1791 1792Ends this input session. This API uses an asynchronous callback to return the result. 1793 1794> **NOTE** 1795> 1796> This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused. 1797> 1798> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9) instead. 1799 1800**System capability**: SystemCapability.MiscServices.InputMethodFramework 1801 1802**Parameters** 1803 1804| Name| Type| Mandatory| Description| 1805| -------- | -------- | -------- | -------- | 1806| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| 1807 1808**Example** 1809 1810```ts 1811import { BusinessError } from '@kit.BasicServicesKit'; 1812 1813inputMethodController.stopInput((err: BusinessError, result: boolean) => { 1814 if (err) { 1815 console.error(`Failed to stopInput: ${JSON.stringify(err)}`); 1816 return; 1817 } 1818 if (result) { 1819 console.log('Succeeded in stopping input.'); 1820 } else { 1821 console.error('Failed to stopInput.'); 1822 } 1823}); 1824``` 1825 1826### stopInput<sup>(deprecated)</sup> 1827 1828stopInput(): Promise<boolean> 1829 1830Ends this input session. This API uses a promise to return the result. 1831 1832> **NOTE** 1833> 1834> This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused. 1835> 1836> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9) instead. 1837 1838**System capability**: SystemCapability.MiscServices.InputMethodFramework 1839 1840**Return value** 1841 1842| Type| Description| 1843| -------- | -------- | 1844| Promise<boolean> | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.| 1845 1846**Example** 1847 1848```ts 1849import { BusinessError } from '@kit.BasicServicesKit'; 1850 1851inputMethodController.stopInput().then((result: boolean) => { 1852 if (result) { 1853 console.log('Succeeded in stopping input.'); 1854 } else { 1855 console.error('Failed to stopInput.'); 1856 } 1857}).catch((err: BusinessError) => { 1858 console.error(`Failed to stopInput: ${JSON.stringify(err)}`); 1859}) 1860``` 1861 1862### on('insertText')<sup>10+</sup> 1863 1864on(type: 'insertText', callback: (text: string) => void): void 1865 1866Enables listening for the text insertion event of the input method. This API uses an asynchronous callback to return the result. 1867 1868**System capability**: SystemCapability.MiscServices.InputMethodFramework 1869 1870**Parameters** 1871 1872| Name | Type | Mandatory| Description | 1873| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 1874| type | string | Yes | Listening type. The value is fixed at **'insertText'**.| 1875| callback | (text: string) => void | Yes | Callback used to return the text to be inserted.<br>The application needs to operate the content in the edit box based on the text content returned in the callback.| 1876 1877**Error codes** 1878 1879For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1880 1881| ID| Error Message | 1882| -------- | -------------------------------------- | 1883| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1884| 12800009 | input method client is detached. | 1885 1886**Example** 1887 1888```ts 1889function callback1(text: string) { 1890 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(text)); 1891} 1892 1893function callback2(text: string) { 1894 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(text)); 1895} 1896 1897try { 1898 inputMethodController.on('insertText', callback1); 1899 inputMethodController.on('insertText', callback2); 1900 // Cancel only callback1 of insertText. 1901 inputMethodController.off('insertText', callback1); 1902 // Cancel all callbacks of insertText. 1903 inputMethodController.off('insertText'); 1904} catch(err) { 1905 console.error(`Failed to subscribe insertText: ${JSON.stringify(err)}`); 1906} 1907``` 1908 1909### off('insertText')<sup>10+</sup> 1910 1911off(type: 'insertText', callback?: (text: string) => void): void 1912 1913Disables listening for the text insertion event of the input method. 1914 1915**System capability**: SystemCapability.MiscServices.InputMethodFramework 1916 1917**Parameters** 1918 1919| Name | Type | Mandatory| Description | 1920| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 1921| type | string | Yes | Listening type. The value is fixed at **'insertText'**.| 1922| callback | (text: string) => void | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 1923 1924**Example** 1925 1926```ts 1927let onInsertTextCallback = (text: string) => { 1928 console.log(`Succeeded in subscribing insertText: ${text}`); 1929}; 1930inputMethodController.off('insertText', onInsertTextCallback); 1931inputMethodController.off('insertText'); 1932``` 1933 1934### on('deleteLeft')<sup>10+</sup> 1935 1936on(type: 'deleteLeft', callback: (length: number) => void): void 1937 1938Enables listening for the leftward delete event. This API uses an asynchronous callback to return the result. 1939 1940**System capability**: SystemCapability.MiscServices.InputMethodFramework 1941 1942**Parameters** 1943 1944| Name | Type| Mandatory| Description| 1945| -------- | ----- | ---- | ----- | 1946| type | string | Yes | Listening type. The value is fixed at **'deleteLeft'**.| 1947| callback | (length: number) => void | Yes | Callback used to return the length of the text to be deleted leftward.<br>The application needs to operate the content in the edit box based on the length returned in the callback.| 1948 1949**Error codes** 1950 1951For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1952 1953| ID| Error Message | 1954| -------- | -------------------------------------- | 1955| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1956| 12800009 | input method client is detached. | 1957 1958**Example** 1959 1960```ts 1961try { 1962 inputMethodController.on('deleteLeft', (length: number) => { 1963 console.log(`Succeeded in subscribing deleteLeft, length: ${length}`); 1964 }); 1965} catch(err) { 1966 console.error(`Failed to subscribe deleteLeft: ${JSON.stringify(err)}`); 1967} 1968``` 1969 1970### off('deleteLeft')<sup>10+</sup> 1971 1972off(type: 'deleteLeft', callback?: (length: number) => void): void 1973 1974Disables listening for the leftward delete event. 1975 1976**System capability**: SystemCapability.MiscServices.InputMethodFramework 1977 1978**Parameters** 1979 1980| Name | Type | Mandatory| Description | 1981| -------- | ------------------------ | ---- | ------------------------------------------------------------ | 1982| type | string | Yes | Listening type. The value is fixed at **'deleteLeft'**.| 1983| callback | (length: number) => void | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 1984 1985**Example** 1986 1987```ts 1988let onDeleteLeftCallback = (length: number) => { 1989 console.log(`Succeeded in subscribing deleteLeft, length: ${length}`); 1990}; 1991inputMethodController.off('deleteLeft', onDeleteLeftCallback); 1992inputMethodController.off('deleteLeft'); 1993``` 1994 1995### on('deleteRight')<sup>10+</sup> 1996 1997on(type: 'deleteRight', callback: (length: number) => void): void 1998 1999Enables listening for the rightward delete event. This API uses an asynchronous callback to return the result. 2000 2001**System capability**: SystemCapability.MiscServices.InputMethodFramework 2002 2003**Parameters** 2004 2005| Name | Type| Mandatory| Description| 2006| -------- | ----- | ---- | ----- | 2007| type | string | Yes | Listening type. The value is fixed at **'deleteRight'**.| 2008| callback | (length: number) => void | Yes | Callback used to return the length of the text to be deleted rightward.<br>The application needs to operate the content in the edit box based on the length returned in the callback.| 2009 2010**Error codes** 2011 2012For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2013 2014| ID| Error Message | 2015| -------- | -------------------------------------- | 2016| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2017| 12800009 | input method client is detached. | 2018 2019**Example** 2020 2021```ts 2022try { 2023 inputMethodController.on('deleteRight', (length: number) => { 2024 console.log(`Succeeded in subscribing deleteRight, length: ${length}`); 2025 }); 2026} catch(err) { 2027 console.error(`Failed to subscribe deleteRight: ${JSON.stringify(err)}`); 2028} 2029``` 2030 2031### off('deleteRight')<sup>10+</sup> 2032 2033off(type: 'deleteRight', callback?: (length: number) => void): void 2034 2035Disables listening for the rightward delete event. 2036 2037**System capability**: SystemCapability.MiscServices.InputMethodFramework 2038 2039**Parameters** 2040 2041| Name | Type | Mandatory| Description | 2042| -------- | ------------------------ | ---- | ------------------------------------------------------------ | 2043| type | string | Yes | Listening type. The value is fixed at **'deleteRight'**.| 2044| callback | (length: number) => void | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 2045 2046**Example** 2047 2048```ts 2049let onDeleteRightCallback = (length: number) => { 2050 console.log(`Succeeded in subscribing deleteRight, length: ${length}`); 2051}; 2052inputMethodController.off('deleteRight', onDeleteRightCallback); 2053inputMethodController.off('deleteRight'); 2054``` 2055 2056### on('sendKeyboardStatus')<sup>10+</sup> 2057 2058on(type: 'sendKeyboardStatus', callback: (keyboardStatus: KeyboardStatus) => void): void 2059 2060Enables listening for the soft keyboard status event of the input method. This API uses an asynchronous callback to return the result. 2061 2062**System capability**: SystemCapability.MiscServices.InputMethodFramework 2063 2064**Parameters** 2065 2066| Name | Type | Mandatory| Description | 2067| -------- | ------ | ---- | ---- | 2068| type | string | Yes | Listening type. The value is fixed at **'sendKeyboardStatus'**.| 2069| callback | (keyboardStatus: [KeyboardStatus](#keyboardstatus10)) => void | Yes | Callback used to return the soft keyboard status.<br>The application needs to perform operations based on the soft keyboard state returned in the callback.| 2070 2071**Error codes** 2072 2073For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2074 2075| ID| Error Message | 2076| -------- | -------------------------------------- | 2077| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2078| 12800009 | input method client is detached. | 2079 2080**Example** 2081 2082```ts 2083try { 2084 inputMethodController.on('sendKeyboardStatus', (keyboardStatus: inputMethod.KeyboardStatus) => { 2085 console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`); 2086 }); 2087} catch(err) { 2088 console.error(`Failed to subscribe sendKeyboardStatus: ${JSON.stringify(err)}`); 2089} 2090``` 2091 2092### off('sendKeyboardStatus')<sup>10+</sup> 2093 2094off(type: 'sendKeyboardStatus', callback?: (keyboardStatus: KeyboardStatus) => void): void 2095 2096Disables listening for the soft keyboard status event of the input method. 2097 2098**System capability**: SystemCapability.MiscServices.InputMethodFramework 2099 2100**Parameters** 2101 2102| Name | Type | Mandatory| Description | 2103| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2104| type | string | Yes | Listening type. The value is fixed at **'sendKeyboardStatus'**.| 2105| callback | (keyboardStatus: [KeyboardStatus](#keyboardstatus10)) => void | No | Callback used for disable listening. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 2106 2107**Example** 2108 2109```ts 2110let onSendKeyboardStatus = (keyboardStatus: inputMethod.KeyboardStatus) => { 2111 console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`); 2112}; 2113inputMethodController.off('sendKeyboardStatus', onSendKeyboardStatus); 2114inputMethodController.off('sendKeyboardStatus'); 2115``` 2116 2117### on('sendFunctionKey')<sup>10+</sup> 2118 2119on(type: 'sendFunctionKey', callback: (functionKey: FunctionKey) => void): void 2120 2121Enables listening for the function key sending event of the input method. This API uses an asynchronous callback to return the result. 2122 2123**System capability**: SystemCapability.MiscServices.InputMethodFramework 2124 2125**Parameters** 2126 2127| Name | Type | Mandatory| Description | 2128| -------- | -------- | ---- | ----- | 2129| type | string | Yes | Listening type. The value is fixed at **'sendFunctionKey'**.| 2130| callback | (functionKey: [FunctionKey](#functionkey10)) => void | Yes | Callback used to return the function key information sent by the input method.<br>The application needs to perform operations based on the function key information returned in the callback.| 2131 2132**Error codes** 2133 2134For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2135 2136| ID| Error Message | 2137| -------- | -------------------------------------- | 2138| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2139| 12800009 | input method client is detached. | 2140 2141**Example** 2142 2143```ts 2144try { 2145 inputMethodController.on('sendFunctionKey', (functionKey: inputMethod.FunctionKey) => { 2146 console.log(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`); 2147 }); 2148} catch(err) { 2149 console.error(`Failed to subscribe sendFunctionKey: ${JSON.stringify(err)}`); 2150} 2151``` 2152 2153### off('sendFunctionKey')<sup>10+</sup> 2154 2155off(type: 'sendFunctionKey', callback?: (functionKey: FunctionKey) => void): void 2156 2157Disables listening for the function key sending event of the input method. 2158 2159**System capability**: SystemCapability.MiscServices.InputMethodFramework 2160 2161**Parameters** 2162 2163| Name | Type | Mandatory| Description | 2164| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 2165| type | string | Yes | Listening type. The value is fixed at **'sendFunctionKey'**.| 2166| callback | (functionKey: [FunctionKey](#functionkey10)) => void | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 2167 2168**Example** 2169 2170```ts 2171let onSendFunctionKey = (functionKey: inputMethod.FunctionKey) => { 2172 console.log(`Succeeded in subscribing sendFunctionKey, functionKey: ${functionKey.enterKeyType}`); 2173}; 2174inputMethodController.off('sendFunctionKey', onSendFunctionKey); 2175inputMethodController.off('sendFunctionKey'); 2176``` 2177 2178### on('moveCursor')<sup>10+</sup> 2179 2180on(type: 'moveCursor', callback: (direction: Direction) => void): void 2181 2182Enables listening for the cursor movement event of the input method. This API uses an asynchronous callback to return the result. 2183 2184**System capability**: SystemCapability.MiscServices.InputMethodFramework 2185 2186**Parameters** 2187 2188| Name | Type| Mandatory| Description | 2189| -------- | ------ | ---- | ------ | 2190| type | string | Yes | Listening type. The value is fixed at **'moveCursor'**.| 2191| callback | callback: (direction: [Direction<sup>10+</sup>](#direction10)) => void | Yes | Callback used to return the cursor movement direction.<br>The application needs to change the cursor position based on the cursor movement direction returned in the callback. | 2192 2193**Error codes** 2194 2195For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2196 2197| ID| Error Message | 2198| -------- | -------------------------------- | 2199| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2200| 12800009 | input method client is detached. | 2201 2202**Example** 2203 2204```ts 2205try { 2206 inputMethodController.on('moveCursor', (direction: inputMethod.Direction) => { 2207 console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`); 2208 }); 2209} catch(err) { 2210 console.error(`Failed to subscribe moveCursor: ${JSON.stringify(err)}`); 2211} 2212``` 2213 2214### off('moveCursor')<sup>10+</sup> 2215 2216off(type: 'moveCursor', callback?: (direction: Direction) => void): void 2217 2218Disables listening for the cursor movement event of the input method. 2219 2220**System capability**: SystemCapability.MiscServices.InputMethodFramework 2221 2222**Parameters** 2223 2224| Name | Type | Mandatory| Description | 2225| ------ | ------ | ---- | ---- | 2226| type | string | Yes | Listening type. The value is fixed at **'moveCursor'**.| 2227| callback | (direction: [Direction<sup>10+</sup>](#direction10)) => void | No| Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 2228 2229**Example** 2230 2231```ts 2232let onMoveCursorCallback = (direction: inputMethod.Direction) => { 2233 console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`); 2234}; 2235inputMethodController.off('moveCursor', onMoveCursorCallback); 2236inputMethodController.off('moveCursor'); 2237``` 2238 2239### on('handleExtendAction')<sup>10+</sup> 2240 2241on(type: 'handleExtendAction', callback: (action: ExtendAction) => void): void 2242 2243Enables listening for the extended action handling event of the input method. This API uses an asynchronous callback to return the result. 2244 2245**System capability**: SystemCapability.MiscServices.InputMethodFramework 2246 2247**Parameters** 2248 2249| Name | Type | Mandatory| Description | 2250| -------- | ------ | ---- | -------- | 2251| type | string | Yes | Listening type. The value is fixed at **'handleExtendAction'**.| 2252| callback | callback: (action: [ExtendAction](#extendaction10)) => void | Yes | Callback used to return the extended action type.<br>The application needs to perform operations based on the extended action type returned in the callback.| 2253 2254**Error codes** 2255 2256For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2257 2258| ID| Error Message | 2259| -------- | -------------------------------------- | 2260| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2261| 12800009 | input method client is detached. | 2262 2263**Example** 2264 2265```ts 2266try { 2267 inputMethodController.on('handleExtendAction', (action: inputMethod.ExtendAction) => { 2268 console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`); 2269 }); 2270} catch(err) { 2271 console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`); 2272} 2273``` 2274 2275### off('handleExtendAction')<sup>10+</sup> 2276 2277off(type: 'handleExtendAction', callback?: (action: ExtendAction) => void): void 2278 2279Disables listening for the extended action handling event of the input method. This API uses an asynchronous callback to return the result. 2280 2281**System capability**: SystemCapability.MiscServices.InputMethodFramework 2282 2283**Parameters** 2284 2285| Name| Type | Mandatory| Description | 2286| ------ | ------ | ---- | ------- | 2287| type | string | Yes | Listening type. The value is fixed at **'handleExtendAction'**.| 2288| callback | (action: [ExtendAction](#extendaction10)) => void | No| Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 2289 2290**Example** 2291 2292```ts 2293try { 2294 let onHandleExtendActionCallback = (action: inputMethod.ExtendAction) => { 2295 console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`); 2296 }; 2297 inputMethodController.off('handleExtendAction', onHandleExtendActionCallback); 2298 inputMethodController.off('handleExtendAction'); 2299} catch(err) { 2300 console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`); 2301} 2302``` 2303 2304### on('selectByRange')<sup>10+</sup> 2305 2306on(type: 'selectByRange', callback: Callback<Range>): void 2307 2308Enables listening for the select-by-range event. This API uses an asynchronous callback to return the result. 2309 2310**System capability**: SystemCapability.MiscServices.InputMethodFramework 2311 2312**Parameters** 2313 2314| Name | Type | Mandatory| Description | 2315| -------- | ---- | ---- | ------- | 2316| type | string | Yes | Listening type. The value is fixed at **'selectByRange'**.| 2317| callback | Callback<[Range](#range10)> | Yes | Callback used to return the range of the text to be selected.<br>The application needs to select the text based on the range returned in the callback.| 2318 2319**Error codes** 2320 2321For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2322 2323| ID| Error Message | 2324| -------- | ------------------------------------------------------- | 2325| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2326 2327**Example** 2328 2329```ts 2330try { 2331 inputMethodController.on('selectByRange', (range: inputMethod.Range) => { 2332 console.log(`Succeeded in subscribing selectByRange: start: ${range.start} , end: ${range.end}`); 2333 }); 2334} catch(err) { 2335 console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`); 2336} 2337``` 2338 2339### off('selectByRange')<sup>10+</sup> 2340 2341off(type: 'selectByRange', callback?: Callback<Range>): void 2342 2343Disables listening for the select-by-range event. This API uses an asynchronous callback to return the result. 2344 2345**System capability**: SystemCapability.MiscServices.InputMethodFramework 2346 2347**Parameters** 2348 2349| Name | Type | Mandatory| Description | 2350| -------- | --------------------------------- | ---- | ------------------------------------------------------------ | 2351| type | string | Yes | Listening type. The value is fixed at **'selectByRange'**.| 2352| callback | Callback<[Range](#range10)> | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 2353 2354**Example** 2355 2356```ts 2357try { 2358 let onSelectByRangeCallback = (range: inputMethod.Range) => { 2359 console.log(`Succeeded in subscribing selectByRange, range: ${JSON.stringify(range)}`); 2360 }; 2361 inputMethodController.off('selectByRange', onSelectByRangeCallback); 2362 inputMethodController.off('selectByRange'); 2363} catch(err) { 2364 console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`); 2365} 2366``` 2367 2368### on('selectByMovement')<sup>10+</sup> 2369 2370on(type: 'selectByMovement', callback: Callback<Movement>): void 2371 2372Enables listening for the select-by-cursor-movement event. This API uses an asynchronous callback to return the result. 2373 2374**System capability**: SystemCapability.MiscServices.InputMethodFramework 2375 2376**Parameters** 2377 2378| Name | Type | Mandatory| Description | 2379| -------- | ----- | ---- | ------ | 2380| type | string | Yes | Listening type. The value is fixed at **'selectByMovement'**.| 2381| callback | Callback<[Movement](#movement10)> | Yes | Callback used to return the direction in which the cursor moves.<br>The application needs to select the text based on the direction returned in the callback.| 2382 2383**Error codes** 2384 2385For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2386 2387| ID| Error Message | 2388| -------- | ------------------------------------------------------- | 2389| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2390 2391**Example** 2392 2393```ts 2394try { 2395 inputMethodController.on('selectByMovement', (movement: inputMethod.Movement) => { 2396 console.log('Succeeded in subscribing selectByMovement: direction: ' + movement.direction); 2397 }); 2398} catch(err) { 2399 console.error(`Failed to subscribe selectByMovement: ${JSON.stringify(err)}`); 2400} 2401``` 2402 2403### off('selectByMovement')<sup>10+</sup> 2404 2405off(type: 'selectByMovement', callback?: Callback<Movement>): void 2406 2407Disables listening for the select-by-cursor-movement event. This API uses an asynchronous callback to return the result. 2408 2409**System capability**: SystemCapability.MiscServices.InputMethodFramework 2410 2411**Parameters** 2412 2413| Name | Type | Mandatory| Description | 2414| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 2415| type | string | Yes | Listening type. The value is fixed at **'selectByMovement'**.| 2416| callback | Callback<[Movement](#movement10)> | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 2417 2418**Example** 2419 2420```ts 2421try { 2422 let onSelectByMovementCallback = (movement: inputMethod.Movement) => { 2423 console.log(`Succeeded in subscribing selectByMovement, movement.direction: ${movement.direction}`); 2424 }; 2425 inputMethodController.off('selectByMovement', onSelectByMovementCallback); 2426 inputMethodController.off('selectByMovement'); 2427} catch(err) { 2428 console.error(`Failed to unsubscribing selectByMovement: ${JSON.stringify(err)}`); 2429} 2430``` 2431 2432### on('getLeftTextOfCursor')<sup>10+</sup> 2433 2434on(type: 'getLeftTextOfCursor', callback: (length: number) => string): void 2435 2436Enables listening for the event of obtaining the length of text deleted leftward. This API uses an asynchronous callback to return the result. 2437 2438**System capability**: SystemCapability.MiscServices.InputMethodFramework 2439 2440**Parameters** 2441 2442| Name | Type | Mandatory| Description | 2443| -------- | ----- | ---- | ------ | 2444| type | string | Yes | Listening type. The value is fixed at **'getLeftTextOfCursor'**.| 2445| callback | (length: number) => string | Yes | Callback used to obtain the text of the specified length deleted leftward.| 2446 2447**Error codes** 2448 2449For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2450 2451| ID| Error Message | 2452| -------- | -------------------------------------- | 2453| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2454| 12800009 | input method client is detached. | 2455 2456**Example** 2457 2458```ts 2459try { 2460 inputMethodController.on('getLeftTextOfCursor', (length: number) => { 2461 console.info(`Succeeded in subscribing getLeftTextOfCursor, length: ${length}`); 2462 let text:string = ""; 2463 return text; 2464 }); 2465} catch(err) { 2466 console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`); 2467} 2468``` 2469 2470### off('getLeftTextOfCursor')<sup>10+</sup> 2471 2472off(type: 'getLeftTextOfCursor', callback?: (length: number) => string): void 2473 2474Disables listening for the event of obtaining the length of text deleted leftward. This API uses an asynchronous callback to return the result. 2475 2476**System capability**: SystemCapability.MiscServices.InputMethodFramework 2477 2478**Parameters** 2479 2480| Name| Type | Mandatory| Description | 2481| ------ | ------ | ---- | ------------------------------------------------------------ | 2482| type | string | Yes | Listening type. The value is fixed at **'getLeftTextOfCursor'**.| 2483| callback | (length: number) => string | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 2484 2485**Example** 2486 2487```ts 2488try { 2489 let getLeftTextOfCursorCallback = (length: number) => { 2490 console.info(`Succeeded in unsubscribing getLeftTextOfCursor, length: ${length}`); 2491 let text:string = ""; 2492 return text; 2493 }; 2494 inputMethodController.off('getLeftTextOfCursor', getLeftTextOfCursorCallback); 2495 inputMethodController.off('getLeftTextOfCursor'); 2496} catch(err) { 2497 console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`); 2498} 2499``` 2500 2501### on('getRightTextOfCursor')<sup>10+</sup> 2502 2503on(type: 'getRightTextOfCursor', callback: (length: number) => string): void 2504 2505Enables listening for the event of obtaining the length of text deleted rightward. This API uses an asynchronous callback to return the result. 2506 2507**System capability**: SystemCapability.MiscServices.InputMethodFramework 2508 2509**Parameters** 2510 2511| Name | Type | Mandatory| Description | 2512| -------- | ----- | ---- | ------ | 2513| type | string | Yes | Listening type. The value is fixed at **'getRightTextOfCursor'**.| 2514| callback | (length: number) => string | Yes | Callback used to obtain the text of the specified length deleted rightward.| 2515 2516**Error codes** 2517 2518For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2519 2520| ID| Error Message | 2521| -------- | -------------------------------------- | 2522| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2523| 12800009 | input method client is detached. | 2524 2525**Example** 2526 2527```ts 2528try { 2529 inputMethodController.on('getRightTextOfCursor', (length: number) => { 2530 console.info(`Succeeded in subscribing getRightTextOfCursor, length: ${length}`); 2531 let text:string = ""; 2532 return text; 2533 }); 2534} catch(err) { 2535 console.error(`Failed to subscribe getRightTextOfCursor. err: ${JSON.stringify(err)}`); 2536} 2537``` 2538 2539### off('getRightTextOfCursor')<sup>10+</sup> 2540 2541off(type: 'getRightTextOfCursor', callback?: (length: number) => string): void 2542 2543Disables listening for the event of obtaining the length of text deleted rightward. This API uses an asynchronous callback to return the result. 2544 2545**System capability**: SystemCapability.MiscServices.InputMethodFramework 2546 2547**Parameters** 2548 2549| Name| Type | Mandatory| Description | 2550| ------ | ------ | ---- | ------------------------------------------------------------ | 2551| type | string | Yes | Listening type. The value is fixed at **'getRightTextOfCursor'**.| 2552| callback | (length: number) => string | No |Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 2553 2554**Example** 2555 2556```ts 2557try { 2558 let getRightTextOfCursorCallback = (length: number) => { 2559 console.info(`Succeeded in unsubscribing getRightTextOfCursor, length: ${length}`); 2560 let text:string = ""; 2561 return text; 2562 }; 2563 inputMethodController.off('getRightTextOfCursor', getRightTextOfCursorCallback); 2564 inputMethodController.off('getRightTextOfCursor'); 2565} catch(err) { 2566 console.error(`Failed to unsubscribing getRightTextOfCursor. err: ${JSON.stringify(err)}`); 2567} 2568``` 2569 2570### on('getTextIndexAtCursor')<sup>10+</sup> 2571 2572on(type: 'getTextIndexAtCursor', callback: () => number): void 2573 2574Enables listening for the event of obtaining the index of text at the cursor. This API uses an asynchronous callback to return the result. 2575 2576**System capability**: SystemCapability.MiscServices.InputMethodFramework 2577 2578**Parameters** 2579 2580| Name | Type | Mandatory| Description | 2581| -------- | ----- | ---- | ------ | 2582| type | string | Yes | Listening type. The value is fixed at **'getTextIndexAtCursor'**.| 2583| callback | () => number | Yes | Callback used to obtain the index of text at the cursor.| 2584 2585**Error codes** 2586 2587For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2588 2589| ID| Error Message | 2590| -------- | -------------------------------------- | 2591| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2592| 12800009 | input method client is detached. | 2593 2594**Example** 2595 2596```ts 2597try { 2598 inputMethodController.on('getTextIndexAtCursor', () => { 2599 console.info(`Succeeded in subscribing getTextIndexAtCursor.`); 2600 let index:number = 0; 2601 return index; 2602 }); 2603} catch(err) { 2604 console.error(`Failed to subscribe getTextIndexAtCursor. err: ${JSON.stringify(err)}`); 2605} 2606``` 2607 2608### off('getTextIndexAtCursor')<sup>10+</sup> 2609 2610off(type: 'getTextIndexAtCursor', callback?: () => number): void 2611 2612Disables listening for the event of obtaining the index of text at the cursor. This API uses an asynchronous callback to return the result. 2613 2614**System capability**: SystemCapability.MiscServices.InputMethodFramework 2615 2616**Parameters** 2617 2618| Name| Type | Mandatory| Description | 2619| ------ | ------ | ---- | ------------------------------------------------------------ | 2620| type | string | Yes | Listening type. The value is fixed at **'getTextIndexAtCursor'**.| 2621| callback | () => number | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 2622 2623**Example** 2624 2625```ts 2626try { 2627 let getTextIndexAtCursorCallback = () => { 2628 console.info(`Succeeded in unsubscribing getTextIndexAtCursor.`); 2629 let index:number = 0; 2630 return index; 2631 }; 2632 inputMethodController.off('getTextIndexAtCursor', getTextIndexAtCursorCallback); 2633 inputMethodController.off('getTextIndexAtCursor'); 2634} catch(err) { 2635 console.error(`Failed to unsubscribing getTextIndexAtCursor. err: ${JSON.stringify(err)}`); 2636} 2637``` 2638 2639## InputMethodSetting<sup>8+</sup> 2640 2641In the following API examples, you must first use [getSetting](#inputmethodgetsetting9) to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance. 2642 2643### on('imeChange')<sup>9+</sup> 2644 2645on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void 2646 2647Enables listening for the input method and subtype change event. This API uses an asynchronous callback to return the result. 2648 2649**System capability**: SystemCapability.MiscServices.InputMethodFramework 2650 2651**Parameters** 2652 2653| Name | Type | Mandatory| Description | 2654| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | 2655| type | string | Yes | Listening type. The value is fixed at **'imeChange'**.| 2656| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void | Yes| Callback used to return the input method attributes and subtype.| 2657 2658**Example** 2659 2660```ts 2661import { InputMethodSubtype } from '@kit.IMEKit'; 2662try { 2663 inputMethodSetting.on('imeChange', (inputMethodProperty: inputMethod.InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => { 2664 console.log('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype)); 2665 }); 2666} catch(err) { 2667 console.error(`Failed to unsubscribing inputMethodProperty. err: ${JSON.stringify(err)}`); 2668} 2669``` 2670 2671### off('imeChange')<sup>9+</sup> 2672 2673off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void 2674 2675Disables listening for the input method and subtype change event. This API uses an asynchronous callback to return the result. 2676 2677**System capability**: SystemCapability.MiscServices.InputMethodFramework 2678 2679**Parameters** 2680 2681| Name | Type | Mandatory| Description | 2682| -------- | --------- | ---- | --------------- | 2683| type | string | Yes | Listening type. The value is fixed at **'imeChange'**.| 2684| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void | No| Callback used to return the input method attributes and subtype.| 2685 2686**Example** 2687 2688```ts 2689inputMethodSetting.off('imeChange'); 2690``` 2691 2692### listInputMethodSubtype<sup>9+</sup> 2693 2694listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback<Array<InputMethodSubtype>>): void 2695 2696Obtains all subtypes of a specified input method. This API uses an asynchronous callback to return the result. 2697 2698**System capability**: SystemCapability.MiscServices.InputMethodFramework 2699 2700**Parameters** 2701 2702| Name | Type | Mandatory| Description | 2703| -------- | -------------------------------------------------- | ---- | ---------------------- | 2704| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method.| 2705| callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Yes| Callback used to return all subtypes of the specified input method.| 2706 2707**Error codes** 2708 2709For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2710 2711| ID| Error Message | 2712| -------- | -------------------------------------- | 2713| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2714| 12800001 | package manager error. | 2715| 12800008 | input method manager service error. | 2716 2717**Example** 2718 2719```ts 2720import { InputMethodSubtype } from '@kit.IMEKit'; 2721import { BusinessError } from '@kit.BasicServicesKit'; 2722 2723let inputMethodProperty: inputMethod.InputMethodProperty = { 2724 name: 'com.example.kikakeyboard', 2725 id: 'propertyId', 2726} 2727let inputMethodSetting = inputMethod.getSetting(); 2728try { 2729 inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err: BusinessError, data: Array<InputMethodSubtype>) => { 2730 if (err) { 2731 console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); 2732 return; 2733 } 2734 console.log('Succeeded in listing inputMethodSubtype.'); 2735 }); 2736} catch (err) { 2737 console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); 2738} 2739``` 2740 2741### listInputMethodSubtype<sup>9+</sup> 2742 2743listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Array<InputMethodSubtype>> 2744 2745Obtains all subtypes of a specified input method. This API uses a promise to return the result. 2746 2747**System capability**: SystemCapability.MiscServices.InputMethodFramework 2748 2749**Parameters** 2750 2751| Name | Type | Mandatory| Description | 2752| -------- | -------------------------------------------------- | ---- | ---------------------- | 2753| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method.| 2754 2755**Return value** 2756 2757| Type | Description | 2758| ----------------------------------------------------------- | ---------------------- | 2759| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise used to return all subtypes of the specified input method.| 2760 2761**Error codes** 2762 2763For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2764 2765| ID| Error Message | 2766| -------- | -------------------------------------- | 2767| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2768| 12800001 | package manager error. | 2769| 12800008 | input method manager service error. | 2770 2771**Example** 2772 2773```ts 2774import { InputMethodSubtype } from '@kit.IMEKit'; 2775import { BusinessError } from '@kit.BasicServicesKit'; 2776 2777let inputMethodProperty: inputMethod.InputMethodProperty = { 2778 name: 'com.example.kikakeyboard', 2779 id: 'propertyId', 2780} 2781let inputMethodSetting = inputMethod.getSetting(); 2782try { 2783 inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data: Array<InputMethodSubtype>) => { 2784 console.log('Succeeded in listing inputMethodSubtype.'); 2785 }).catch((err: BusinessError) => { 2786 console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); 2787 }) 2788} catch(err) { 2789 console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); 2790} 2791``` 2792 2793### listCurrentInputMethodSubtype<sup>9+</sup> 2794 2795listCurrentInputMethodSubtype(callback: AsyncCallback<Array<InputMethodSubtype>>): void 2796 2797Obtains all subtypes of this input method. This API uses an asynchronous callback to return the result. 2798 2799**System capability**: SystemCapability.MiscServices.InputMethodFramework 2800 2801**Parameters** 2802 2803| Name | Type | Mandatory| Description | 2804| -------- | -------------------------------------------------- | ---- | ---------------------- | 2805| callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Yes | Callback used to return all subtypes of the current input method.| 2806 2807**Error codes** 2808 2809For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2810 2811| ID| Error Message | 2812| -------- | -------------------------------------- | 2813| 12800001 | package manager error. | 2814| 12800008 | input method manager service error. | 2815 2816**Example** 2817 2818```ts 2819import { InputMethodSubtype } from '@kit.IMEKit'; 2820import { BusinessError } from '@kit.BasicServicesKit'; 2821 2822let inputMethodSetting = inputMethod.getSetting(); 2823try { 2824 inputMethodSetting.listCurrentInputMethodSubtype((err: BusinessError, data: Array<InputMethodSubtype>) => { 2825 if (err) { 2826 console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 2827 return; 2828 } 2829 console.log('Succeeded in listing currentInputMethodSubtype.'); 2830 }); 2831} catch(err) { 2832 console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 2833} 2834``` 2835 2836### listCurrentInputMethodSubtype<sup>9+</sup> 2837 2838listCurrentInputMethodSubtype(): Promise<Array<InputMethodSubtype>> 2839 2840Obtains all subtypes of this input method. This API uses a promise to return the result. 2841 2842**System capability**: SystemCapability.MiscServices.InputMethodFramework 2843 2844**Return value** 2845 2846| Type | Description | 2847| ----------------------------------------------------------- | ---------------------- | 2848| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise used to return all subtypes of the current input method.| 2849 2850**Error codes** 2851 2852For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2853 2854| ID| Error Message | 2855| -------- | -------------------------------------- | 2856| 12800001 | package manager error. | 2857| 12800008 | input method manager service error. | 2858 2859**Example** 2860 2861```ts 2862import { InputMethodSubtype } from '@kit.IMEKit'; 2863import { BusinessError } from '@kit.BasicServicesKit'; 2864 2865let inputMethodSetting = inputMethod.getSetting(); 2866try { 2867 inputMethodSetting.listCurrentInputMethodSubtype().then((data: Array<InputMethodSubtype>) => { 2868 console.log('Succeeded in listing currentInputMethodSubtype.'); 2869 }).catch((err: BusinessError) => { 2870 console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 2871 }) 2872} catch(err) { 2873 console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 2874} 2875``` 2876 2877### getInputMethods<sup>9+</sup> 2878 2879getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void 2880 2881Obtains a list of activated or deactivated input methods. This API uses an asynchronous callback to return the result. 2882 2883> **NOTE** 2884> 2885> An activated input method refers to an input method that is enabled. The default input method is enabled by default. Other input methods can be enabled or disabled as needed. 2886> 2887> The list of activated input methods includes the default input method and enabled input methods. The list of deactivated input methods includes all installed input methods except the enabled ones. 2888 2889**System capability**: SystemCapability.MiscServices.InputMethodFramework 2890 2891**Parameters** 2892 2893| Name | Type | Mandatory| Description | 2894| -------- | --------------------------------------------------- | ---- | ----------------------------- | 2895| enable | boolean | Yes |Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.| 2896| callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | Yes | Callback used to return a list of activated or deactivated input methods.| 2897 2898**Error codes** 2899 2900For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2901 2902| ID| Error Message | 2903| -------- | ----------------------------------- | 2904| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2905| 12800001 | package manager error. | 2906| 12800008 | input method manager service error. | 2907 2908**Example** 2909 2910```ts 2911import { BusinessError } from '@kit.BasicServicesKit'; 2912 2913try { 2914 inputMethodSetting.getInputMethods(true, (err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => { 2915 if (err) { 2916 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 2917 return; 2918 } 2919 console.log('Succeeded in getting inputMethods.'); 2920 }); 2921} catch (err) { 2922 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 2923} 2924``` 2925 2926### getInputMethods<sup>9+</sup> 2927 2928getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>> 2929 2930Obtains a list of activated or deactivated input methods. This API uses a promise to return the result. 2931 2932> **NOTE** 2933> 2934> An activated input method refers to an input method that is enabled. The default input method is enabled by default. Other input methods can be enabled or disabled as needed. 2935> 2936> The list of activated input methods includes the default input method and enabled input methods. The list of deactivated input methods includes all installed input methods except the enabled ones. 2937 2938**System capability**: SystemCapability.MiscServices.InputMethodFramework 2939 2940**Parameters** 2941 2942| Name| Type | Mandatory| Description | 2943| ------ | ------- | ---- | ----------------------- | 2944| enable | boolean | Yes |Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.| 2945 2946**Return value** 2947 2948| Type | Description | 2949| ------------------------------------------------------------ | ------------------------------------------ | 2950| Promise\<Array\<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return a list of activated or deactivated input methods.| 2951 2952**Error codes** 2953 2954For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2955 2956| ID| Error Message | 2957| -------- | ----------------------------------- | 2958| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2959| 12800001 | package manager error. | 2960| 12800008 | input method manager service error. | 2961 2962**Example** 2963 2964```ts 2965import { BusinessError } from '@kit.BasicServicesKit'; 2966 2967try { 2968 inputMethodSetting.getInputMethods(true).then((data: Array<inputMethod.InputMethodProperty>) => { 2969 console.log('Succeeded in getting inputMethods.'); 2970 }).catch((err: BusinessError) => { 2971 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 2972 }) 2973} catch(err) { 2974 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 2975} 2976``` 2977 2978### getInputMethodsSync<sup>11+</sup> 2979 2980getInputMethodsSync(enable: boolean): Array<InputMethodProperty> 2981 2982Obtains a list of activated or deactivated input methods. This API returns the result synchronously. 2983 2984> **NOTE** 2985> 2986> An activated input method refers to an input method that is enabled. The default input method is enabled by default. Other input methods can be enabled or disabled as needed. 2987> 2988> The list of activated input methods includes the default input method and enabled input methods. The list of deactivated input methods includes all installed input methods except the enabled ones. 2989 2990**System capability**: SystemCapability.MiscServices.InputMethodFramework 2991 2992**Parameters** 2993 2994| Name| Type | Mandatory| Description | 2995| ------ | ------- | ---- | ----------------------- | 2996| enable | boolean | Yes |Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.| 2997 2998**Return value** 2999 3000| Type | Description | 3001| ---------------------------------------------------- | ----------------------------- | 3002| Array\<[InputMethodProperty](#inputmethodproperty8)> | List of activated or deactivated input methods.| 3003 3004**Error codes** 3005 3006For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3007 3008| ID| Error Message | 3009| -------- | -------------------------------------- | 3010| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3011| 12800001 | bundle manager error. | 3012| 12800008 |input method manager service error. | 3013 3014**Example** 3015 3016```ts 3017try { 3018 let imeProp = inputMethodSetting.getInputMethodsSync(true); 3019} catch(err) { 3020 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 3021} 3022``` 3023 3024### getAllInputMethods<sup>11+</sup> 3025 3026getAllInputMethods(callback: AsyncCallback<Array<InputMethodProperty>>): void 3027 3028Obtains a list of all input methods. This API uses an asynchronous callback to return the result. 3029 3030**System capability**: SystemCapability.MiscServices.InputMethodFramework 3031 3032**Parameters** 3033 3034| Name | Type | Mandatory| Description | 3035| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | 3036| callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | Yes | Callback used to return a list of all input methods.| 3037 3038**Error codes** 3039 3040For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3041 3042| ID| Error Message | 3043| -------- | ----------------------------------- | 3044| 12800001 | bundle manager error. | 3045| 12800008 | input method manager service error. | 3046 3047**Example** 3048 3049```ts 3050import { BusinessError } from '@kit.BasicServicesKit'; 3051 3052try { 3053 inputMethodSetting.getAllInputMethods((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => { 3054 if (err) { 3055 console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`); 3056 return; 3057 } 3058 console.log('Succeeded in getting all inputMethods.'); 3059 }); 3060} catch (err) { 3061 console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`); 3062} 3063``` 3064 3065### getAllInputMethods<sup>11+</sup> 3066 3067getAllInputMethods(): Promise<Array<InputMethodProperty>> 3068 3069Obtains a list of all input methods. This API uses a promise to return the result. 3070 3071**System capability**: SystemCapability.MiscServices.InputMethodFramework 3072 3073**Return value** 3074 3075| Type | Description | 3076| ------------------------------------------------------------ | --------------------------------- | 3077| Promise\<Array\<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return a list of all input methods.| 3078 3079**Error codes** 3080 3081For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3082 3083| ID| Error Message | 3084| -------- | ----------------------------------- | 3085| 12800001 | bundle manager error. | 3086| 12800008 | input method manager service error. | 3087 3088**Example** 3089 3090```ts 3091import { BusinessError } from '@kit.BasicServicesKit'; 3092 3093inputMethodSetting.getAllInputMethods().then((data: Array<inputMethod.InputMethodProperty>) => { 3094 console.log('Succeeded in getting all inputMethods.'); 3095}).catch((err: BusinessError) => { 3096 console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`); 3097}) 3098``` 3099 3100### getAllInputMethodsSync<sup>11+</sup> 3101 3102getAllInputMethodsSync(): Array<InputMethodProperty> 3103 3104Obtains a list of all input methods. This API returns the result synchronously. 3105 3106**System capability**: SystemCapability.MiscServices.InputMethodFramework 3107 3108**Return value** 3109 3110| Type | Description | 3111| ---------------------------------------------------- | ------------------ | 3112| Array\<[InputMethodProperty](#inputmethodproperty8)> | List of all input methods.| 3113 3114**Error codes** 3115 3116For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3117 3118| ID| Error Message | 3119| -------- | ----------------------------------- | 3120| 12800001 | bundle manager error. | 3121| 12800008 | input method manager service error. | 3122 3123**Example** 3124 3125```ts 3126try { 3127 let imeProp = inputMethodSetting.getAllInputMethodsSync(); 3128} catch(err) { 3129 console.error(`Failed to getAllInputMethodsSync: ${JSON.stringify(err)}`); 3130} 3131``` 3132 3133### showOptionalInputMethods<sup>9+</sup> 3134 3135showOptionalInputMethods(callback: AsyncCallback<boolean>): void 3136 3137Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. 3138 3139**System capability**: SystemCapability.MiscServices.InputMethodFramework 3140 3141**Parameters** 3142 3143| Name| Type| Mandatory| Description| 3144| -------- | -------- | -------- | -------- | 3145| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| 3146 3147**Error codes** 3148 3149For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3150 3151| ID| Error Message | 3152| -------- | -------------------------------------- | 3153| 12800008 | input method manager service error. | 3154 3155**Example** 3156 3157```ts 3158import { BusinessError } from '@kit.BasicServicesKit'; 3159 3160try { 3161 inputMethodSetting.showOptionalInputMethods((err: BusinessError, data: boolean) => { 3162 if (err) { 3163 console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); 3164 return; 3165 } 3166 console.log('Succeeded in showing optionalInputMethods.'); 3167 }); 3168} catch (err) { 3169 console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); 3170} 3171``` 3172 3173### showOptionalInputMethods<sup>9+</sup> 3174 3175showOptionalInputMethods(): Promise<boolean> 3176 3177Displays a dialog box for selecting an input method. This API uses a promise to return the result. 3178 3179**System capability**: SystemCapability.MiscServices.InputMethodFramework 3180 3181**Return value** 3182 3183| Type| Description| 3184| -------- | -------- | 3185| Promise<boolean> | Promise used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.| 3186 3187**Error codes** 3188 3189For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3190 3191| ID| Error Message | 3192| -------- | -------------------------------------- | 3193| 12800008 | input method manager service error. | 3194 3195**Example** 3196 3197```ts 3198import { BusinessError } from '@kit.BasicServicesKit'; 3199 3200inputMethodSetting.showOptionalInputMethods().then((data: boolean) => { 3201 console.log('Succeeded in showing optionalInputMethods.'); 3202}).catch((err: BusinessError) => { 3203 console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); 3204}) 3205``` 3206 3207### listInputMethod<sup>(deprecated)</sup> 3208 3209listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void 3210 3211Obtains a list of installed input methods. This API uses an asynchronous callback to return the result. 3212 3213> **NOTE** 3214> 3215> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9) instead. 3216 3217**System capability**: SystemCapability.MiscServices.InputMethodFramework 3218 3219**Parameters** 3220 3221| Name | Type | Mandatory| Description | 3222| -------- | -------------------------------------------------- | ---- | ---------------------- | 3223| callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | Yes | Callback used to return the list of installed input methods.| 3224 3225**Example** 3226 3227```ts 3228import { BusinessError } from '@kit.BasicServicesKit'; 3229 3230inputMethodSetting.listInputMethod((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => { 3231 if (err) { 3232 console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); 3233 return; 3234 } 3235 console.log('Succeeded in listing inputMethod.'); 3236 }); 3237``` 3238 3239### listInputMethod<sup>(deprecated)</sup> 3240 3241listInputMethod(): Promise<Array<InputMethodProperty>> 3242 3243Obtains a list of installed input methods. This API uses a promise to return the result. 3244 3245> **NOTE** 3246> 3247> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9-1) instead. 3248 3249**System capability**: SystemCapability.MiscServices.InputMethodFramework 3250 3251**Return value** 3252 3253| Type | Description | 3254| ----------------------------------------------------------- | ---------------------- | 3255| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return the list of installed input methods.| 3256 3257**Example** 3258 3259```ts 3260import { BusinessError } from '@kit.BasicServicesKit'; 3261 3262inputMethodSetting.listInputMethod().then((data: Array<inputMethod.InputMethodProperty>) => { 3263 console.log('Succeeded in listing inputMethod.'); 3264}).catch((err: BusinessError) => { 3265 console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); 3266}) 3267``` 3268 3269### displayOptionalInputMethod<sup>(deprecated)</sup> 3270 3271displayOptionalInputMethod(callback: AsyncCallback<void>): void 3272 3273Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. 3274 3275> **NOTE** 3276> 3277> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9) instead. 3278 3279**System capability**: SystemCapability.MiscServices.InputMethodFramework 3280 3281**Parameters** 3282 3283| Name| Type| Mandatory| Description| 3284| -------- | -------- | -------- | -------- | 3285| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 3286 3287**Example** 3288 3289```ts 3290import { BusinessError } from '@kit.BasicServicesKit'; 3291 3292inputMethodSetting.displayOptionalInputMethod((err: BusinessError) => { 3293 if (err) { 3294 console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); 3295 return; 3296 } 3297 console.log('Succeeded in displaying optionalInputMethod.'); 3298}); 3299``` 3300 3301### displayOptionalInputMethod<sup>(deprecated)</sup> 3302 3303displayOptionalInputMethod(): Promise<void> 3304 3305Displays a dialog box for selecting an input method. This API uses a promise to return the result. 3306 3307> **NOTE** 3308> 3309> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9-1) instead. 3310 3311**System capability**: SystemCapability.MiscServices.InputMethodFramework 3312 3313**Return value** 3314 3315| Type| Description| 3316| -------- | -------- | 3317| Promise<void> | Promise that returns no value.| 3318 3319**Example** 3320 3321```ts 3322import { BusinessError } from '@kit.BasicServicesKit'; 3323 3324inputMethodSetting.displayOptionalInputMethod().then(() => { 3325 console.log('Succeeded in displaying optionalInputMethod.'); 3326}).catch((err: BusinessError) => { 3327 console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); 3328}) 3329``` 3330