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