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