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## RequestKeyboardReason<sup>15+</sup> 796 797Describes the reason for keyboard request. 798 799**System capability**: SystemCapability.MiscServices.InputMethodFramework 800 801| Name| Value|Description| 802| -------- | -------- |-------- | 803| NONE | 0 |The keyboard request is triggered for no reason.| 804| MOUSE | 1 |The keyboard request is triggered by a mouse operation.| 805| TOUCH | 2 |The keyboard request is triggered by a touch operation.| 806| OTHER | 20 |The keyboard request is triggered by other reasons.| 807 808## MessageHandler<sup>15+</sup> 809 810Represents a custom communication object. 811 812> **NOTE** 813> 814> 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. 815> 816> 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. 817> 818> If this object is unregistered, its [onTerminated](#onterminated15) callback will be triggered. 819 820### onMessage<sup>15+</sup> 821 822onMessage(msgId: string, msgParam?: ArrayBuffer): void 823 824Receives custom data sent by the input method application. 825 826> **NOTE** 827> 828> This callback is triggered when the registered MeesageHandler receives custom communication data sent by the input method application. 829> 830> 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. 831 832**System capability**: SystemCapability.MiscServices.InputMethodFramework 833 834**Parameters** 835 836| Name | Type | Mandatory| Description | 837| -------- | ----------- | ---- | -------------------------------- | 838| msgId | string | Yes | Identifier of the received custom communication data.| 839| msgParam | ArrayBuffer | No | Message body of the received custom communication data.| 840 841**Example** 842 843```ts 844import { BusinessError } from '@kit.BasicServicesKit'; 845 846let inputMethodController = inputMethod.getController(); 847try { 848 let messageHandler: inputMethod.MessageHandler = { 849 onTerminated(): void { 850 console.log('OnTerminated.'); 851 }, 852 onMessage(msgId: string, msgParam?:ArrayBuffer): void { 853 console.log('recv message.'); 854 } 855 } 856 inputMethodController.recvMessage(messageHandler); 857} catch(err) { 858 console.error(`Failed to recvMessage: ${JSON.stringify(err)}`); 859} 860``` 861 862### onTerminated<sup>15+</sup> 863 864onTerminated(): void 865 866Listens for MessageHandler termination. 867 868> **NOTE** 869> 870> When an application registers a new MessageHandler object, the **OnTerminated** callback of the previous registered MessageHandler object is triggered. 871> 872> When an application unregisters a MessageHandler object, the **OnTerminated** callback of the current registered MessageHandler object is triggered. 873 874**System capability**: SystemCapability.MiscServices.InputMethodFramework 875 876**Example** 877 878```ts 879import { BusinessError } from '@kit.BasicServicesKit'; 880 881let inputMethodController = inputMethod.getController(); 882try { 883 let messageHandler: inputMethod.MessageHandler = { 884 onTerminated(): void { 885 console.log('OnTerminated.'); 886 }, 887 onMessage(msgId: string, msgParam?:ArrayBuffer): void { 888 console.log('recv message.'); 889 } 890 } 891 inputMethodController.recvMessage(messageHandler); 892} catch(err) { 893 console.error(`Failed to recvMessage: ${JSON.stringify(err)}`); 894} 895``` 896 897## InputMethodController 898 899In the following API examples, you must first use [getController](#inputmethodgetcontroller9) to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance. 900 901### attach<sup>10+</sup> 902 903attach(showKeyboard: boolean, textConfig: TextConfig, callback: AsyncCallback<void>): void 904 905Attaches a self-drawing component to the input method. This API uses an asynchronous callback to return the result. 906 907> **NOTE** 908> 909> 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. 910 911**System capability**: SystemCapability.MiscServices.InputMethodFramework 912 913**Parameters** 914 915| Name| Type| Mandatory| Description| 916| -------- | -------- | -------- | -------- | 917| showKeyboard | boolean | Yes| Whether to start the input method keyboard after the self-drawing component is attached to the input method.<br>- **true** means to start the input method keyboard.<br>- **false** means not to start the input method keyboard.| 918| textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the edit box.| 919| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 920 921**Error codes** 922 923For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 924 925| ID| Error Message | 926| -------- | -------------------------------------- | 927| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 928| 12800003 | input method client error. | 929| 12800008 | input method manager service error. | 930 931**Example** 932 933```ts 934import { BusinessError } from '@kit.BasicServicesKit'; 935 936try { 937 let textConfig: inputMethod.TextConfig = { 938 inputAttribute: { 939 textInputType: 0, 940 enterKeyType: 1 941 } 942 }; 943 inputMethodController.attach(true, textConfig, (err: BusinessError) => { 944 if (err) { 945 console.error(`Failed to attach: ${JSON.stringify(err)}`); 946 return; 947 } 948 console.log('Succeeded in attaching the inputMethod.'); 949 }); 950} catch(err) { 951 console.error(`Failed to attach: ${JSON.stringify(err)}`); 952} 953``` 954 955### attach<sup>10+</sup> 956 957attach(showKeyboard: boolean, textConfig: TextConfig): Promise<void> 958 959Attaches a self-drawing component to the input method. This API uses a promise to return the result. 960 961> **NOTE** 962> 963> 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. 964 965**System capability**: SystemCapability.MiscServices.InputMethodFramework 966 967**Parameters** 968 969| Name| Type| Mandatory| Description| 970| -------- | -------- | -------- | -------- | 971| showKeyboard | boolean | Yes| Whether to start the input method keyboard after the self-drawing component is attached to the input method.<br>- **true** means to start the input method keyboard.<br>- **false** means not to start the input method keyboard.| 972| textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the edit box.| 973 974**Return value** 975 976| Type| Description| 977| -------- | -------- | 978| Promise<void> | Promise that returns no value.| 979 980**Error codes** 981 982For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 983 984| ID| Error Message | 985| -------- | -------------------------------------- | 986| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 987| 12800003 | input method client error. | 988| 12800008 | input method manager service error. | 989 990**Example** 991 992```ts 993import { BusinessError } from '@kit.BasicServicesKit'; 994 995try { 996 let textConfig: inputMethod.TextConfig = { 997 inputAttribute: { 998 textInputType: 0, 999 enterKeyType: 1 1000 } 1001 }; 1002 inputMethodController.attach(true, textConfig).then(() => { 1003 console.log('Succeeded in attaching inputMethod.'); 1004 }).catch((err: BusinessError) => { 1005 console.error(`Failed to attach: ${JSON.stringify(err)}`); 1006 }) 1007} catch(err) { 1008 console.error(`Failed to attach: ${JSON.stringify(err)}`); 1009} 1010``` 1011 1012### attach<sup>15+</sup> 1013 1014attach(showKeyboard: boolean, textConfig: TextConfig, requestKeyboardReason: RequestKeyboardReason): Promise<void> 1015 1016Attaches a self-drawing component to the input method. This API uses a promise to return the result. 1017 1018> **NOTE** 1019> 1020> 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. 1021 1022**System capability**: SystemCapability.MiscServices.InputMethodFramework 1023 1024**Parameters** 1025 1026| Name| Type| Mandatory| Description| 1027| -------- | -------- | -------- | -------- | 1028| showKeyboard | boolean | Yes| Whether to start the input method keyboard after the self-drawing component is attached to the input method.<br>- **true** means to start the input method keyboard.<br>- **false** means not to start the input method keyboard.| 1029| textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the edit box.| 1030| requestKeyboardReason | [RequestKeyboardReason](#requestkeyboardreason15) | Yes| Reason for keyboard request.| 1031 1032**Return value** 1033 1034| Type| Description| 1035| -------- | -------- | 1036| Promise<void> | Promise that returns no value.| 1037 1038**Error codes** 1039 1040For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1041 1042| ID| Error Message | 1043| -------- | -------------------------------------- | 1044| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1045| 12800003 | input method client error. | 1046| 12800008 | input method manager service error. | 1047 1048**Example** 1049 1050```ts 1051import { BusinessError } from '@kit.BasicServicesKit'; 1052 1053try { 1054 let textConfig: inputMethod.TextConfig = { 1055 inputAttribute: { 1056 textInputType: 0, 1057 enterKeyType: 1 1058 } 1059 }; 1060 1061 let requestKeyboardReason: inputMethod.RequestKeyboardReason = inputMethod.RequestKeyboardReason.MOUSE; 1062 1063 inputMethodController.attach(true, textConfig, requestKeyboardReason).then(() => { 1064 console.log('Succeeded in attaching inputMethod.'); 1065 }).catch((err: BusinessError) => { 1066 console.error(`Failed to attach: ${JSON.stringify(err)}`); 1067 }) 1068} catch(err) { 1069 console.error(`Failed to attach: ${JSON.stringify(err)}`); 1070} 1071``` 1072 1073### showTextInput<sup>10+</sup> 1074 1075showTextInput(callback: AsyncCallback<void>): void 1076 1077Enters the text editing mode. This API uses an asynchronous callback to return the result. 1078 1079> **NOTE** 1080> 1081> 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. 1082 1083**System capability**: SystemCapability.MiscServices.InputMethodFramework 1084 1085**Parameters** 1086 1087| Name| Type| Mandatory| Description| 1088| -------- | -------- | -------- | -------- | 1089| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1090 1091**Error codes** 1092 1093For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1094 1095| ID| Error Message | 1096| -------- | -------------------------------------- | 1097| 12800003 | input method client error. | 1098| 12800008 | input method manager service error. | 1099| 12800009 | input method client detached. | 1100 1101**Example** 1102 1103```ts 1104import { BusinessError } from '@kit.BasicServicesKit'; 1105 1106inputMethodController.showTextInput((err: BusinessError) => { 1107 if (err) { 1108 console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); 1109 return; 1110 } 1111 console.log('Succeeded in showing the inputMethod.'); 1112}); 1113``` 1114 1115### showTextInput<sup>10+</sup> 1116 1117showTextInput(): Promise<void> 1118 1119Enters the text editing mode. This API uses a promise to return the result. 1120 1121> **NOTE** 1122> 1123> 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. 1124 1125**System capability**: SystemCapability.MiscServices.InputMethodFramework 1126 1127**Return value** 1128 1129| Type| Description| 1130| -------- | -------- | 1131| Promise<void> | Promise that returns no value.| 1132 1133**Error codes** 1134 1135For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1136 1137| ID| Error Message | 1138| -------- | -------------------------------------- | 1139| 12800003 | input method client error. | 1140| 12800008 | input method manager service error. | 1141| 12800009 | input method client detached. | 1142 1143**Example** 1144 1145```ts 1146import { BusinessError } from '@kit.BasicServicesKit'; 1147 1148inputMethodController.showTextInput().then(() => { 1149 console.log('Succeeded in showing text input.'); 1150}).catch((err: BusinessError) => { 1151 console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); 1152}); 1153``` 1154 1155### showTextInput<sup>15+</sup> 1156 1157showTextInput(requestKeyboardReason: RequestKeyboardReason): Promise<void> 1158 1159Enters the text editing mode. This API uses a promise to return the result. 1160 1161> **NOTE** 1162> 1163> 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. 1164 1165**System capability**: SystemCapability.MiscServices.InputMethodFramework 1166 1167**Parameters** 1168 1169| Name| Type| Mandatory| Description| 1170| -------- | -------- | -------- | -------- | 1171| requestKeyboardReason | [RequestKeyboardReason](#requestkeyboardreason15) | Yes| Reason for keyboard request.| 1172 1173**Return value** 1174 1175| Type| Description| 1176| -------- | -------- | 1177| Promise<void> | Promise that returns no value.| 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| 12800009 | input method client detached. | 1188 1189**Example** 1190 1191```ts 1192import { BusinessError } from '@kit.BasicServicesKit'; 1193 1194let requestKeyboardReason = inputMethod.RequestKeyboardReason.MOUSE; 1195 1196inputMethodController.showTextInput(requestKeyboardReason).then(() => { 1197 console.log('Succeeded in showing text input.'); 1198}).catch((err: BusinessError) => { 1199 console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); 1200}); 1201``` 1202 1203### hideTextInput<sup>10+</sup> 1204 1205hideTextInput(callback: AsyncCallback<void>): void 1206 1207Exits the text editing mode. This API uses an asynchronous callback to return the result. 1208 1209> **NOTE** 1210> 1211> If the soft keyboard is displayed when this API is called, it will be hidden. 1212> 1213> 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. 1214 1215**System capability**: SystemCapability.MiscServices.InputMethodFramework 1216 1217**Parameters** 1218 1219| Name| Type| Mandatory| Description| 1220| -------- | -------- | -------- | -------- | 1221| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1222 1223**Error codes** 1224 1225For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1226 1227| ID| Error Message | 1228| -------- | -------------------------------------- | 1229| 12800003 | input method client error. | 1230| 12800008 | input method manager service error. | 1231| 12800009 | input method client detached. | 1232 1233**Example** 1234 1235```ts 1236import { BusinessError } from '@kit.BasicServicesKit'; 1237 1238inputMethodController.hideTextInput((err: BusinessError) => { 1239 if (err) { 1240 console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); 1241 return; 1242 } 1243 console.log('Succeeded in hiding text input.'); 1244}); 1245``` 1246 1247### hideTextInput<sup>10+</sup> 1248 1249hideTextInput(): Promise<void> 1250 1251Exits the text editing mode. This API uses a promise to return the result. 1252 1253> **NOTE** 1254> 1255> If the soft keyboard is displayed when this API is called, it will be hidden. 1256> 1257> 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. 1258 1259**System capability**: SystemCapability.MiscServices.InputMethodFramework 1260 1261**Return value** 1262 1263| Type| Description| 1264| -------- | -------- | 1265| Promise<void> | Promise that returns no value.| 1266 1267**Error codes** 1268 1269For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1270 1271| ID| Error Message | 1272| -------- | -------------------------------------- | 1273| 12800003 | input method client error. | 1274| 12800008 | input method manager service error. | 1275| 12800009 | input method client detached. | 1276 1277**Example** 1278 1279```ts 1280import { BusinessError } from '@kit.BasicServicesKit'; 1281 1282inputMethodController.hideTextInput().then(() => { 1283 console.log('Succeeded in hiding inputMethod.'); 1284}).catch((err: BusinessError) => { 1285 console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); 1286}) 1287``` 1288 1289### detach<sup>10+</sup> 1290 1291detach(callback: AsyncCallback<void>): void 1292 1293Detaches the self-drawing component from the input method. This API uses an asynchronous callback to return the result. 1294 1295**System capability**: SystemCapability.MiscServices.InputMethodFramework 1296 1297**Parameters** 1298 1299| Name| Type| Mandatory| Description| 1300| -------- | -------- | -------- | -------- | 1301| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1302 1303**Error codes** 1304 1305For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1306 1307| ID| Error Message | 1308| -------- | -------------------------------------- | 1309| 12800003 | input method client error. | 1310| 12800008 | input method manager service error. | 1311 1312**Example** 1313 1314```ts 1315import { BusinessError } from '@kit.BasicServicesKit'; 1316 1317inputMethodController.detach((err: BusinessError) => { 1318 if (err) { 1319 console.error(`Failed to detach: ${JSON.stringify(err)}`); 1320 return; 1321 } 1322 console.log('Succeeded in detaching inputMethod.'); 1323}); 1324``` 1325 1326### detach<sup>10+</sup> 1327 1328detach(): Promise<void> 1329 1330Detaches the self-drawing component from the input method. This API uses a promise to return the result. 1331 1332**System capability**: SystemCapability.MiscServices.InputMethodFramework 1333 1334**Return value** 1335 1336| Type| Description| 1337| -------- | -------- | 1338| Promise<void> | Promise that returns no value.| 1339 1340**Error codes** 1341 1342For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1343 1344| ID| Error Message | 1345| -------- | -------------------------------------- | 1346| 12800003 | input method client error. | 1347| 12800008 | input method manager service error. | 1348 1349**Example** 1350 1351```ts 1352import { BusinessError } from '@kit.BasicServicesKit'; 1353 1354inputMethodController.detach().then(() => { 1355 console.log('Succeeded in detaching inputMethod.'); 1356}).catch((err: BusinessError) => { 1357 console.error(`Failed to detach: ${JSON.stringify(err)}`); 1358}); 1359``` 1360 1361### setCallingWindow<sup>10+</sup> 1362 1363setCallingWindow(windowId: number, callback: AsyncCallback<void>): void 1364 1365Sets the window to be avoided by the input method. This API uses an asynchronous callback to return the result. 1366 1367> **NOTE** 1368> 1369> 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. 1370 1371**System capability**: SystemCapability.MiscServices.InputMethodFramework 1372 1373**Parameters** 1374 1375| Name| Type| Mandatory| Description| 1376| -------- | -------- | -------- | -------- | 1377| windowId | number | Yes| Window ID of the application bound to the input method.| 1378| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1379 1380**Error codes** 1381 1382For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1383 1384| ID| Error Message | 1385| -------- | -------------------------------------- | 1386| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1387| 12800003 | input method client error. | 1388| 12800008 | input method manager service error. | 1389| 12800009 | input method client detached. | 1390 1391**Example** 1392 1393```ts 1394import { BusinessError } from '@kit.BasicServicesKit'; 1395 1396try { 1397 let windowId: number = 2000; 1398 inputMethodController.setCallingWindow(windowId, (err: BusinessError) => { 1399 if (err) { 1400 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 1401 return; 1402 } 1403 console.log('Succeeded in setting callingWindow.'); 1404 }); 1405} catch(err) { 1406 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 1407} 1408``` 1409 1410### setCallingWindow<sup>10+</sup> 1411 1412setCallingWindow(windowId: number): Promise<void> 1413 1414Sets the window to be avoided by the input method. This API uses a promise to return the result. 1415 1416> **NOTE** 1417> 1418> 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. 1419 1420**System capability**: SystemCapability.MiscServices.InputMethodFramework 1421 1422**Parameters** 1423 1424| Name| Type| Mandatory| Description| 1425| -------- | -------- | -------- | -------- | 1426| windowId | number | Yes| Window ID of the application bound to the input method.| 1427 1428**Return value** 1429 1430| Type| Description| 1431| -------- | -------- | 1432| Promise<void> | Promise that returns no value.| 1433 1434**Error codes** 1435 1436For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1437 1438| ID| Error Message | 1439| -------- | -------------------------------------- | 1440| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1441| 12800003 | input method client error. | 1442| 12800008 | input method manager service error. | 1443| 12800009 | input method client detached. | 1444 1445**Example** 1446 1447```ts 1448import { BusinessError } from '@kit.BasicServicesKit'; 1449 1450try { 1451 let windowId: number = 2000; 1452 inputMethodController.setCallingWindow(windowId).then(() => { 1453 console.log('Succeeded in setting callingWindow.'); 1454 }).catch((err: BusinessError) => { 1455 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 1456 }) 1457} catch(err) { 1458 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 1459} 1460``` 1461 1462### updateCursor<sup>10+</sup> 1463 1464updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback<void>): void 1465 1466Updates 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. 1467 1468**System capability**: SystemCapability.MiscServices.InputMethodFramework 1469 1470**Parameters** 1471 1472| Name| Type| Mandatory| Description| 1473| -------- | -------- | -------- | -------- | 1474| cursorInfo | [CursorInfo](#cursorinfo10) | Yes| Cursor information.| 1475| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1476 1477**Error codes** 1478 1479For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1480 1481| ID| Error Message | 1482| -------- | -------------------------------------- | 1483| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1484| 12800003 | input method client error. | 1485| 12800008 | input method manager service error. | 1486| 12800009 | input method client detached. | 1487 1488**Example** 1489 1490```ts 1491import { BusinessError } from '@kit.BasicServicesKit'; 1492 1493try { 1494 let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 }; 1495 inputMethodController.updateCursor(cursorInfo, (err: BusinessError) => { 1496 if (err) { 1497 console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); 1498 return; 1499 } 1500 console.log('Succeeded in updating cursorInfo.'); 1501 }); 1502} catch(err) { 1503 console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); 1504} 1505``` 1506 1507### updateCursor<sup>10+</sup> 1508 1509updateCursor(cursorInfo: CursorInfo): Promise<void> 1510 1511Updates 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. 1512 1513**System capability**: SystemCapability.MiscServices.InputMethodFramework 1514 1515**Parameters** 1516 1517| Name| Type| Mandatory| Description| 1518| -------- | -------- | -------- | -------- | 1519| cursorInfo | [CursorInfo](#cursorinfo10) | Yes| Cursor information.| 1520 1521**Return value** 1522 1523| Type| Description| 1524| -------- | -------- | 1525| Promise<void> | Promise that returns no value.| 1526 1527**Error codes** 1528 1529For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1530 1531| ID| Error Message | 1532| -------- | -------------------------------------- | 1533| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1534| 12800003 | input method client error. | 1535| 12800008 | input method manager service error. | 1536| 12800009 | input method client detached. | 1537 1538**Example** 1539 1540```ts 1541import { BusinessError } from '@kit.BasicServicesKit'; 1542 1543try { 1544 let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 }; 1545 inputMethodController.updateCursor(cursorInfo).then(() => { 1546 console.log('Succeeded in updating cursorInfo.'); 1547 }).catch((err: BusinessError) => { 1548 console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); 1549 }) 1550} catch(err) { 1551 console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); 1552} 1553``` 1554 1555### changeSelection<sup>10+</sup> 1556 1557changeSelection(text: string, start: number, end: number, callback: AsyncCallback<void>): void 1558 1559Updates 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. 1560 1561**System capability**: SystemCapability.MiscServices.InputMethodFramework 1562 1563**Parameters** 1564 1565| Name| Type| Mandatory| Description| 1566| -------- | -------- | -------- | -------- | 1567| text | string | Yes| All input text.| 1568| start | number | Yes| Start position of the selected text.| 1569| end | number | Yes| End position of the selected text.| 1570| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1571 1572**Error codes** 1573 1574For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1575 1576| ID| Error Message | 1577| -------- | -------------------------------------- | 1578| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1579| 12800003 | input method client error. | 1580| 12800008 | input method manager service error. | 1581| 12800009 | input method client detached. | 1582 1583**Example** 1584 1585```ts 1586import { BusinessError } from '@kit.BasicServicesKit'; 1587 1588try { 1589 inputMethodController.changeSelection('text', 0, 5, (err: BusinessError) => { 1590 if (err) { 1591 console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); 1592 return; 1593 } 1594 console.log('Succeeded in changing selection.'); 1595 }); 1596} catch(err) { 1597 console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); 1598} 1599``` 1600 1601### changeSelection<sup>10+</sup> 1602 1603changeSelection(text: string, start: number, end: number): Promise<void> 1604 1605Updates 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. 1606 1607**System capability**: SystemCapability.MiscServices.InputMethodFramework 1608 1609**Parameters** 1610 1611| Name| Type| Mandatory| Description| 1612| -------- | -------- | -------- | -------- | 1613| text | string | Yes| All input text.| 1614| start | number | Yes| Start position of the selected text.| 1615| end | number | Yes| End position of the selected text.| 1616 1617**Return value** 1618 1619| Type| Description| 1620| -------- | -------- | 1621| Promise<void> | Promise that returns no value.| 1622 1623**Error codes** 1624 1625For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1626 1627| ID| Error Message | 1628| -------- | -------------------------------------- | 1629| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1630| 12800003 | input method client error. | 1631| 12800008 | input method manager service error. | 1632| 12800009 | input method client detached. | 1633 1634**Example** 1635 1636```ts 1637import { BusinessError } from '@kit.BasicServicesKit'; 1638 1639try { 1640 inputMethodController.changeSelection('test', 0, 5).then(() => { 1641 console.log('Succeeded in changing selection.'); 1642 }).catch((err: BusinessError) => { 1643 console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); 1644 }) 1645} catch(err) { 1646 console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); 1647} 1648``` 1649 1650### updateAttribute<sup>10+</sup> 1651 1652updateAttribute(attribute: InputAttribute, callback: AsyncCallback<void>): void 1653 1654Updates the attribute information of this edit box. This API uses an asynchronous callback to return the result. 1655 1656**System capability**: SystemCapability.MiscServices.InputMethodFramework 1657 1658**Parameters** 1659 1660| Name| Type| Mandatory| Description| 1661| -------- | -------- | -------- | -------- | 1662| attribute | [InputAttribute](#inputattribute10) | Yes| Attribute information.| 1663| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1664 1665**Error codes** 1666 1667For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1668 1669| ID| Error Message | 1670| -------- | -------------------------------------- | 1671| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1672| 12800003 | input method client error. | 1673| 12800008 | input method manager service error. | 1674| 12800009 | input method client detached. | 1675 1676**Example** 1677 1678```ts 1679import { BusinessError } from '@kit.BasicServicesKit'; 1680 1681try { 1682 let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; 1683 inputMethodController.updateAttribute(inputAttribute, (err: BusinessError) => { 1684 if (err) { 1685 console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); 1686 return; 1687 } 1688 console.log('Succeeded in updating attribute.'); 1689 }); 1690} catch(err) { 1691 console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); 1692} 1693``` 1694 1695### updateAttribute<sup>10+</sup> 1696 1697updateAttribute(attribute: InputAttribute): Promise<void> 1698 1699Updates the attribute information of this edit box. This API uses a promise to return the result. 1700 1701**System capability**: SystemCapability.MiscServices.InputMethodFramework 1702 1703**Parameters** 1704 1705| Name| Type| Mandatory| Description| 1706| -------- | -------- | -------- | -------- | 1707| attribute | [InputAttribute](#inputattribute10) | Yes| Attribute information.| 1708 1709**Return value** 1710 1711| Type| Description| 1712| -------- | -------- | 1713| Promise<void> | Promise that returns no value.| 1714 1715**Error codes** 1716 1717For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1718 1719| ID| Error Message | 1720| -------- | -------------------------------------- | 1721| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1722| 12800003 | input method client error. | 1723| 12800008 | input method manager service error. | 1724| 12800009 | input method client detached. | 1725 1726**Example** 1727 1728```ts 1729import { BusinessError } from '@kit.BasicServicesKit'; 1730 1731try { 1732 let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; 1733 inputMethodController.updateAttribute(inputAttribute).then(() => { 1734 console.log('Succeeded in updating attribute.'); 1735 }).catch((err: BusinessError) => { 1736 console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); 1737 }) 1738} catch(err) { 1739 console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); 1740} 1741``` 1742 1743### stopInputSession<sup>9+</sup> 1744 1745stopInputSession(callback: AsyncCallback<boolean>): void 1746 1747Ends this input session. This API uses an asynchronous callback to return the result. 1748 1749> **NOTE** 1750> 1751> 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. 1752 1753**System capability**: SystemCapability.MiscServices.InputMethodFramework 1754 1755**Parameters** 1756 1757| Name| Type| Mandatory| Description| 1758| -------- | -------- | -------- | -------- | 1759| 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.| 1760 1761**Error codes** 1762 1763For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1764 1765| ID| Error Message | 1766| -------- | -------------------------------------- | 1767| 12800003 | input method client error. | 1768| 12800008 | input method manager service error. | 1769 1770**Example** 1771 1772```ts 1773import { BusinessError } from '@kit.BasicServicesKit'; 1774 1775try { 1776 inputMethodController.stopInputSession((err: BusinessError, result: boolean) => { 1777 if (err) { 1778 console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); 1779 return; 1780 } 1781 if (result) { 1782 console.log('Succeeded in stopping inputSession.'); 1783 } else { 1784 console.error('Failed to stopInputSession.'); 1785 } 1786 }); 1787} catch(err) { 1788 console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); 1789} 1790``` 1791 1792### stopInputSession<sup>9+</sup> 1793 1794stopInputSession(): Promise<boolean> 1795 1796Ends this input session. This API uses a promise to return the result. 1797 1798> **NOTE** 1799> 1800> 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. 1801 1802**System capability**: SystemCapability.MiscServices.InputMethodFramework 1803 1804**Return value** 1805 1806| Type| Description| 1807| -------- | -------- | 1808| Promise<boolean> | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.| 1809 1810**Error codes** 1811 1812For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1813 1814| ID| Error Message | 1815| -------- | -------------------------------------- | 1816| 12800003 | input method client error. | 1817| 12800008 | input method manager service error. | 1818 1819**Example** 1820 1821```ts 1822import { BusinessError } from '@kit.BasicServicesKit'; 1823 1824try { 1825 inputMethodController.stopInputSession().then((result: boolean) => { 1826 if (result) { 1827 console.log('Succeeded in stopping inputSession.'); 1828 } else { 1829 console.error('Failed to stopInputSession.'); 1830 } 1831 }).catch((err: BusinessError) => { 1832 console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); 1833 }) 1834} catch(err) { 1835 console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); 1836} 1837``` 1838 1839### showSoftKeyboard<sup>9+</sup> 1840 1841showSoftKeyboard(callback: AsyncCallback<void>): void 1842 1843Shows the soft keyboard. This API uses an asynchronous callback to return the result. 1844 1845> **NOTE** 1846> 1847> 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. 1848 1849**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) 1850 1851**System capability**: SystemCapability.MiscServices.InputMethodFramework 1852 1853**Parameters** 1854 1855| Name | Type | Mandatory| Description | 1856| -------- | ------------------------- | ---- | ---------- | 1857| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1858 1859**Error codes** 1860 1861For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1862 1863| ID| Error Message | 1864| -------- | -------------------------------------- | 1865| 201 | permissions check fails. | 1866| 12800003 | input method client error. | 1867| 12800008 | input method manager service error. | 1868 1869**Example** 1870 1871```ts 1872import { BusinessError } from '@kit.BasicServicesKit'; 1873 1874inputMethodController.showSoftKeyboard((err: BusinessError) => { 1875 if (!err) { 1876 console.log('Succeeded in showing softKeyboard.'); 1877 } else { 1878 console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); 1879 } 1880}) 1881``` 1882 1883### showSoftKeyboard<sup>9+</sup> 1884 1885showSoftKeyboard(): Promise<void> 1886 1887Shows the soft keyboard. This API uses a promise to return the result. 1888 1889> **NOTE** 1890> 1891> 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. 1892 1893**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) 1894 1895**System capability**: SystemCapability.MiscServices.InputMethodFramework 1896 1897**Return value** 1898 1899| Type | Description | 1900| ------------------- | ------------------------- | 1901| Promise<void> | Promise that returns no value.| 1902 1903**Error codes** 1904 1905For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1906 1907| ID| Error Message | 1908| -------- | -------------------------------------- | 1909| 201 | permissions check fails. | 1910| 12800003 | input method client error. | 1911| 12800008 | input method manager service error. | 1912 1913**Example** 1914 1915```ts 1916import { BusinessError } from '@kit.BasicServicesKit'; 1917 1918inputMethodController.showSoftKeyboard().then(() => { 1919 console.log('Succeeded in showing softKeyboard.'); 1920}).catch((err: BusinessError) => { 1921 console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); 1922}); 1923``` 1924 1925### hideSoftKeyboard<sup>9+</sup> 1926 1927hideSoftKeyboard(callback: AsyncCallback<void>): void 1928 1929Hides the soft keyboard. This API uses an asynchronous callback to return the result. 1930 1931> **NOTE** 1932> 1933> 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. 1934 1935**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) 1936 1937**System capability**: SystemCapability.MiscServices.InputMethodFramework 1938 1939**Parameters** 1940 1941| Name | Type | Mandatory| Description | 1942| -------- | ------------------------- | ---- | ---------- | 1943| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1944 1945**Error codes** 1946 1947For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1948 1949| ID| Error Message | 1950| -------- | -------------------------------------- | 1951| 201 | permissions check fails. | 1952| 12800003 | input method client error. | 1953| 12800008 | input method manager service error. | 1954 1955**Example** 1956 1957```ts 1958import { BusinessError } from '@kit.BasicServicesKit'; 1959 1960inputMethodController.hideSoftKeyboard((err: BusinessError) => { 1961 if (!err) { 1962 console.log('Succeeded in hiding softKeyboard.'); 1963 } else { 1964 console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); 1965 } 1966}) 1967``` 1968 1969### hideSoftKeyboard<sup>9+</sup> 1970 1971hideSoftKeyboard(): Promise<void> 1972 1973Hides the soft keyboard. This API uses a promise to return the result. 1974 1975> **NOTE** 1976> 1977> 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. 1978 1979**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only) 1980 1981**System capability**: SystemCapability.MiscServices.InputMethodFramework 1982 1983**Return value** 1984 1985| Type | Description | 1986| ------------------- | ------------------------- | 1987| Promise<void> | Promise that returns no value.| 1988 1989**Error codes** 1990 1991For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 1992 1993| ID| Error Message | 1994| -------- | -------------------------------------- | 1995| 201 | permissions check fails. | 1996| 12800003 | input method client error. | 1997| 12800008 | input method manager service error. | 1998 1999**Example** 2000 2001```ts 2002import { BusinessError } from '@kit.BasicServicesKit'; 2003 2004inputMethodController.hideSoftKeyboard().then(() => { 2005 console.log('Succeeded in hiding softKeyboard.'); 2006}).catch((err: BusinessError) => { 2007 console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); 2008}); 2009``` 2010 2011### sendMessage<sup>15+</sup> 2012 2013sendMessage(msgId: string, msgParam?: ArrayBuffer): Promise<void> 2014 2015Sends the custom communication to the input method application. This API uses a promise to return the result. 2016 2017> **NOTE** 2018> 2019> 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. 2020> 2021> The maximum length of **msgId** is 256 B, and the maximum length of **msgParam** is 128 KB. 2022 2023**System capability**: SystemCapability.MiscServices.InputMethodFramework 2024 2025**Parameters** 2026 2027| Name | Type | Mandatory| Description | 2028| -------- | ----------- | ---- | ------------------------------------------ | 2029| msgId | string | Yes | Identifier of the custom data to be sent to the input method application.| 2030| msgParam | ArrayBuffer | No | Message body of the custom data to be sent to the input method application.| 2031 2032**Return value** 2033 2034| Type | Description | 2035| ------------------- | ------------------------- | 2036| Promise<void> | Promise that returns no value.| 2037 2038**Error codes** 2039 2040For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2041 2042| ID| Error Message | 2043| -------- | ------------------------------------------- | 2044| 401 | parameter error. Possible causes: 1. Incorrect parameter types. 2. Incorrect parameter length. | 2045| 12800003 | input method client error. | 2046| 12800009 | input method client detached. | 2047| 12800014 | the input method is in basic mode. | 2048| 12800015 | the other side does not accept the request. | 2049| 12800016 | input method client is not editable. | 2050 2051**Example** 2052 2053```ts 2054import { BusinessError } from '@kit.BasicServicesKit'; 2055 2056let msgId: string = "testMsgId"; 2057let msgParam: ArrayBuffer = new ArrayBuffer(128); 2058inputMethodController.sendMessage(msgId, msgParam).then(() => { 2059 console.log('Succeeded send message.'); 2060}).catch((err: BusinessError) => { 2061 console.error(`Failed to send message: ${JSON.stringify(err)}`); 2062}); 2063``` 2064 2065### recvMessage<sup>15+</sup> 2066 2067recvMessage(msgHandler?: MessageHandler): void 2068 2069Registers or unregisters MessageHandler. 2070 2071> **NOTE** 2072> 2073> 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. 2074> 2075> If no parameter is set, unregister [MessageHandler](#messagehandler15). Its [onTerminated](#onterminated15) callback will be triggered. 2076 2077**System capability**: SystemCapability.MiscServices.InputMethodFramework 2078 2079**Parameters** 2080 2081| Name | Type | Mandatory| Description | 2082| ---------- | ----------------------------------- | ---- | ------------------------------------------------------------ | 2083| 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).<br>If no parameter is set, unregister [MessageHandler](#messagehandler15). Its [onTerminated](#onterminated15) callback will be triggered.| 2084 2085**Return value** 2086 2087| Type| Description | 2088| ---- | ------------ | 2089| void | No value is returned.| 2090 2091**Error codes** 2092 2093For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2094 2095| ID| Error Message | 2096| -------- | ---------------- | 2097| 401 | parameter error. Possible causes: 1. Incorrect parameter types. | 2098 2099**Example** 2100 2101```ts 2102import { BusinessError } from '@kit.BasicServicesKit'; 2103 2104try { 2105 let messageHandler: inputMethod.MessageHandler = { 2106 onTerminated(): void { 2107 console.log('OnTerminated.'); 2108 }, 2109 onMessage(msgId: string, msgParam?:ArrayBuffer): void { 2110 console.log('recv message.'); 2111 } 2112 } 2113inputMethodController.recvMessage(messageHandler); 2114inputMethodController.recvMessage(); 2115} catch(err) { 2116 console.error(`Failed to recvMessage: ${JSON.stringify(err)}`); 2117} 2118``` 2119 2120### stopInput<sup>(deprecated)</sup> 2121 2122stopInput(callback: AsyncCallback<boolean>): void 2123 2124Ends this input session. This API uses an asynchronous callback to return the result. 2125 2126> **NOTE** 2127> 2128> 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. 2129> 2130> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9) instead. 2131 2132**System capability**: SystemCapability.MiscServices.InputMethodFramework 2133 2134**Parameters** 2135 2136| Name| Type| Mandatory| Description| 2137| -------- | -------- | -------- | -------- | 2138| 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.| 2139 2140**Example** 2141 2142```ts 2143import { BusinessError } from '@kit.BasicServicesKit'; 2144 2145inputMethodController.stopInput((err: BusinessError, result: boolean) => { 2146 if (err) { 2147 console.error(`Failed to stopInput: ${JSON.stringify(err)}`); 2148 return; 2149 } 2150 if (result) { 2151 console.log('Succeeded in stopping input.'); 2152 } else { 2153 console.error('Failed to stopInput.'); 2154 } 2155}); 2156``` 2157 2158### stopInput<sup>(deprecated)</sup> 2159 2160stopInput(): Promise<boolean> 2161 2162Ends this input session. This API uses a promise to return the result. 2163 2164> **NOTE** 2165> 2166> 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. 2167> 2168> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9) instead. 2169 2170**System capability**: SystemCapability.MiscServices.InputMethodFramework 2171 2172**Return value** 2173 2174| Type| Description| 2175| -------- | -------- | 2176| Promise<boolean> | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.| 2177 2178**Example** 2179 2180```ts 2181import { BusinessError } from '@kit.BasicServicesKit'; 2182 2183inputMethodController.stopInput().then((result: boolean) => { 2184 if (result) { 2185 console.log('Succeeded in stopping input.'); 2186 } else { 2187 console.error('Failed to stopInput.'); 2188 } 2189}).catch((err: BusinessError) => { 2190 console.error(`Failed to stopInput: ${JSON.stringify(err)}`); 2191}) 2192``` 2193 2194### on('insertText')<sup>10+</sup> 2195 2196on(type: 'insertText', callback: (text: string) => void): void 2197 2198Enables listening for the text insertion event of the input method. This API uses an asynchronous callback to return the result. 2199 2200**System capability**: SystemCapability.MiscServices.InputMethodFramework 2201 2202**Parameters** 2203 2204| Name | Type | Mandatory| Description | 2205| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2206| type | string | Yes | Listening type. The value is fixed at **'insertText'**.| 2207| 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.| 2208 2209**Error codes** 2210 2211For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2212 2213| ID| Error Message | 2214| -------- | -------------------------------------- | 2215| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2216| 12800009 | input method client detached. | 2217 2218**Example** 2219 2220```ts 2221function callback1(text: string) { 2222 console.info('Succeeded in getting callback1 data: ' + JSON.stringify(text)); 2223} 2224 2225function callback2(text: string) { 2226 console.info('Succeeded in getting callback2 data: ' + JSON.stringify(text)); 2227} 2228 2229try { 2230 inputMethodController.on('insertText', callback1); 2231 inputMethodController.on('insertText', callback2); 2232 // Cancel only callback1 of insertText. 2233 inputMethodController.off('insertText', callback1); 2234 // Cancel all callbacks of insertText. 2235 inputMethodController.off('insertText'); 2236} catch(err) { 2237 console.error(`Failed to subscribe insertText: ${JSON.stringify(err)}`); 2238} 2239``` 2240 2241### off('insertText')<sup>10+</sup> 2242 2243off(type: 'insertText', callback?: (text: string) => void): void 2244 2245Disables listening for the text insertion event of the input method. 2246 2247**System capability**: SystemCapability.MiscServices.InputMethodFramework 2248 2249**Parameters** 2250 2251| Name | Type | Mandatory| Description | 2252| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 2253| type | string | Yes | Listening type. The value is fixed at **'insertText'**.| 2254| 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.| 2255 2256**Example** 2257 2258```ts 2259let onInsertTextCallback = (text: string) => { 2260 console.log(`Succeeded in subscribing insertText: ${text}`); 2261}; 2262inputMethodController.off('insertText', onInsertTextCallback); 2263inputMethodController.off('insertText'); 2264``` 2265 2266### on('deleteLeft')<sup>10+</sup> 2267 2268on(type: 'deleteLeft', callback: (length: number) => void): void 2269 2270Enables listening for the leftward delete event. This API uses an asynchronous callback to return the result. 2271 2272**System capability**: SystemCapability.MiscServices.InputMethodFramework 2273 2274**Parameters** 2275 2276| Name | Type| Mandatory| Description| 2277| -------- | ----- | ---- | ----- | 2278| type | string | Yes | Listening type. The value is fixed at **'deleteLeft'**.| 2279| 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.| 2280 2281**Error codes** 2282 2283For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2284 2285| ID| Error Message | 2286| -------- | -------------------------------------- | 2287| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2288| 12800009 | input method client detached. | 2289 2290**Example** 2291 2292```ts 2293try { 2294 inputMethodController.on('deleteLeft', (length: number) => { 2295 console.log(`Succeeded in subscribing deleteLeft, length: ${length}`); 2296 }); 2297} catch(err) { 2298 console.error(`Failed to subscribe deleteLeft: ${JSON.stringify(err)}`); 2299} 2300``` 2301 2302### off('deleteLeft')<sup>10+</sup> 2303 2304off(type: 'deleteLeft', callback?: (length: number) => void): void 2305 2306Disables listening for the leftward delete event. 2307 2308**System capability**: SystemCapability.MiscServices.InputMethodFramework 2309 2310**Parameters** 2311 2312| Name | Type | Mandatory| Description | 2313| -------- | ------------------------ | ---- | ------------------------------------------------------------ | 2314| type | string | Yes | Listening type. The value is fixed at **'deleteLeft'**.| 2315| 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.| 2316 2317**Example** 2318 2319```ts 2320let onDeleteLeftCallback = (length: number) => { 2321 console.log(`Succeeded in subscribing deleteLeft, length: ${length}`); 2322}; 2323inputMethodController.off('deleteLeft', onDeleteLeftCallback); 2324inputMethodController.off('deleteLeft'); 2325``` 2326 2327### on('deleteRight')<sup>10+</sup> 2328 2329on(type: 'deleteRight', callback: (length: number) => void): void 2330 2331Enables listening for the rightward delete event. This API uses an asynchronous callback to return the result. 2332 2333**System capability**: SystemCapability.MiscServices.InputMethodFramework 2334 2335**Parameters** 2336 2337| Name | Type| Mandatory| Description| 2338| -------- | ----- | ---- | ----- | 2339| type | string | Yes | Listening type. The value is fixed at **'deleteRight'**.| 2340| 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.| 2341 2342**Error codes** 2343 2344For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2345 2346| ID| Error Message | 2347| -------- | -------------------------------------- | 2348| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2349| 12800009 | input method client detached. | 2350 2351**Example** 2352 2353```ts 2354try { 2355 inputMethodController.on('deleteRight', (length: number) => { 2356 console.log(`Succeeded in subscribing deleteRight, length: ${length}`); 2357 }); 2358} catch(err) { 2359 console.error(`Failed to subscribe deleteRight: ${JSON.stringify(err)}`); 2360} 2361``` 2362 2363### off('deleteRight')<sup>10+</sup> 2364 2365off(type: 'deleteRight', callback?: (length: number) => void): void 2366 2367Disables listening for the rightward delete event. 2368 2369**System capability**: SystemCapability.MiscServices.InputMethodFramework 2370 2371**Parameters** 2372 2373| Name | Type | Mandatory| Description | 2374| -------- | ------------------------ | ---- | ------------------------------------------------------------ | 2375| type | string | Yes | Listening type. The value is fixed at `deleteRight`.| 2376| 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.| 2377 2378**Example** 2379 2380```ts 2381let onDeleteRightCallback = (length: number) => { 2382 console.log(`Succeeded in subscribing deleteRight, length: ${length}`); 2383}; 2384inputMethodController.off('deleteRight', onDeleteRightCallback); 2385inputMethodController.off('deleteRight'); 2386``` 2387 2388### on('sendKeyboardStatus')<sup>10+</sup> 2389 2390on(type: 'sendKeyboardStatus', callback: (keyboardStatus: KeyboardStatus) => void): void 2391 2392Enables listening for the soft keyboard status event of the input method. This API uses an asynchronous callback to return the result. 2393 2394**System capability**: SystemCapability.MiscServices.InputMethodFramework 2395 2396**Parameters** 2397 2398| Name | Type | Mandatory| Description | 2399| -------- | ------ | ---- | ---- | 2400| type | string | Yes | Listening type. The value is fixed at **'sendKeyboardStatus'**.| 2401| 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.| 2402 2403**Error codes** 2404 2405For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2406 2407| ID| Error Message | 2408| -------- | -------------------------------------- | 2409| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2410| 12800009 | input method client detached. | 2411 2412**Example** 2413 2414```ts 2415try { 2416 inputMethodController.on('sendKeyboardStatus', (keyboardStatus: inputMethod.KeyboardStatus) => { 2417 console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`); 2418 }); 2419} catch(err) { 2420 console.error(`Failed to subscribe sendKeyboardStatus: ${JSON.stringify(err)}`); 2421} 2422``` 2423 2424### off('sendKeyboardStatus')<sup>10+</sup> 2425 2426off(type: 'sendKeyboardStatus', callback?: (keyboardStatus: KeyboardStatus) => void): void 2427 2428Disables listening for the soft keyboard status event of the input method. 2429 2430**System capability**: SystemCapability.MiscServices.InputMethodFramework 2431 2432**Parameters** 2433 2434| Name | Type | Mandatory| Description | 2435| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2436| type | string | Yes | Listening type. The value is fixed at **'sendKeyboardStatus'**.| 2437| 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.| 2438 2439**Example** 2440 2441```ts 2442let onSendKeyboardStatus = (keyboardStatus: inputMethod.KeyboardStatus) => { 2443 console.log(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`); 2444}; 2445inputMethodController.off('sendKeyboardStatus', onSendKeyboardStatus); 2446inputMethodController.off('sendKeyboardStatus'); 2447``` 2448 2449### on('sendFunctionKey')<sup>10+</sup> 2450 2451on(type: 'sendFunctionKey', callback: (functionKey: FunctionKey) => void): void 2452 2453Enables listening for the function key sending event of the input method. This API uses an asynchronous callback to return the result. 2454 2455**System capability**: SystemCapability.MiscServices.InputMethodFramework 2456 2457**Parameters** 2458 2459| Name | Type | Mandatory| Description | 2460| -------- | -------- | ---- | ----- | 2461| type | string | Yes | Listening type. The value is fixed at **'sendFunctionKey'**.| 2462| 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.| 2463 2464**Error codes** 2465 2466For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2467 2468| ID| Error Message | 2469| -------- | -------------------------------------- | 2470| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2471| 12800009 | input method client detached. | 2472 2473**Example** 2474 2475```ts 2476try { 2477 inputMethodController.on('sendFunctionKey', (functionKey: inputMethod.FunctionKey) => { 2478 console.log(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`); 2479 }); 2480} catch(err) { 2481 console.error(`Failed to subscribe sendFunctionKey: ${JSON.stringify(err)}`); 2482} 2483``` 2484 2485### off('sendFunctionKey')<sup>10+</sup> 2486 2487off(type: 'sendFunctionKey', callback?: (functionKey: FunctionKey) => void): void 2488 2489Disables listening for the function key sending event of the input method. 2490 2491**System capability**: SystemCapability.MiscServices.InputMethodFramework 2492 2493**Parameters** 2494 2495| Name | Type | Mandatory| Description | 2496| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | 2497| type | string | Yes | Listening type. The value is fixed at **'sendFunctionKey'**.| 2498| 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.| 2499 2500**Example** 2501 2502```ts 2503let onSendFunctionKey = (functionKey: inputMethod.FunctionKey) => { 2504 console.log(`Succeeded in subscribing sendFunctionKey, functionKey: ${functionKey.enterKeyType}`); 2505}; 2506inputMethodController.off('sendFunctionKey', onSendFunctionKey); 2507inputMethodController.off('sendFunctionKey'); 2508``` 2509 2510### on('moveCursor')<sup>10+</sup> 2511 2512on(type: 'moveCursor', callback: (direction: Direction) => void): void 2513 2514Enables listening for the cursor movement event of the input method. This API uses an asynchronous callback to return the result. 2515 2516**System capability**: SystemCapability.MiscServices.InputMethodFramework 2517 2518**Parameters** 2519 2520| Name | Type| Mandatory| Description | 2521| -------- | ------ | ---- | ------ | 2522| type | string | Yes | Listening type. The value is fixed at **'moveCursor'**.| 2523| 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. | 2524 2525**Error codes** 2526 2527For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2528 2529| ID| Error Message | 2530| -------- | -------------------------------- | 2531| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2532| 12800009 | input method client detached. | 2533 2534**Example** 2535 2536```ts 2537try { 2538 inputMethodController.on('moveCursor', (direction: inputMethod.Direction) => { 2539 console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`); 2540 }); 2541} catch(err) { 2542 console.error(`Failed to subscribe moveCursor: ${JSON.stringify(err)}`); 2543} 2544``` 2545 2546### off('moveCursor')<sup>10+</sup> 2547 2548off(type: 'moveCursor', callback?: (direction: Direction) => void): void 2549 2550Disables listening for the cursor movement event of the input method. 2551 2552**System capability**: SystemCapability.MiscServices.InputMethodFramework 2553 2554**Parameters** 2555 2556| Name | Type | Mandatory| Description | 2557| ------ | ------ | ---- | ---- | 2558| type | string | Yes | Listening type. The value is fixed at **'moveCursor'**.| 2559| 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.| 2560 2561**Example** 2562 2563```ts 2564let onMoveCursorCallback = (direction: inputMethod.Direction) => { 2565 console.log(`Succeeded in subscribing moveCursor, direction: ${direction}`); 2566}; 2567inputMethodController.off('moveCursor', onMoveCursorCallback); 2568inputMethodController.off('moveCursor'); 2569``` 2570 2571### on('handleExtendAction')<sup>10+</sup> 2572 2573on(type: 'handleExtendAction', callback: (action: ExtendAction) => void): void 2574 2575Enables listening for the extended action handling event of the input method. 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 **'handleExtendAction'**.| 2584| 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.| 2585 2586**Error codes** 2587 2588For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [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| 12800009 | input method client detached. | 2594 2595**Example** 2596 2597```ts 2598try { 2599 inputMethodController.on('handleExtendAction', (action: inputMethod.ExtendAction) => { 2600 console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`); 2601 }); 2602} catch(err) { 2603 console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`); 2604} 2605``` 2606 2607### off('handleExtendAction')<sup>10+</sup> 2608 2609off(type: 'handleExtendAction', callback?: (action: ExtendAction) => void): void 2610 2611Disables listening for the extended action handling event of the input method. This API uses an asynchronous callback to return the result. 2612 2613**System capability**: SystemCapability.MiscServices.InputMethodFramework 2614 2615**Parameters** 2616 2617| Name| Type | Mandatory| Description | 2618| ------ | ------ | ---- | ------- | 2619| type | string | Yes | Listening type. The value is fixed at **'handleExtendAction'**.| 2620| 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.| 2621 2622**Example** 2623 2624```ts 2625try { 2626 let onHandleExtendActionCallback = (action: inputMethod.ExtendAction) => { 2627 console.log(`Succeeded in subscribing handleExtendAction, action: ${action}`); 2628 }; 2629 inputMethodController.off('handleExtendAction', onHandleExtendActionCallback); 2630 inputMethodController.off('handleExtendAction'); 2631} catch(err) { 2632 console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`); 2633} 2634``` 2635 2636### on('selectByRange')<sup>10+</sup> 2637 2638on(type: 'selectByRange', callback: Callback<Range>): void 2639 2640Enables listening for the select-by-range event. This API uses an asynchronous callback to return the result. 2641 2642**System capability**: SystemCapability.MiscServices.InputMethodFramework 2643 2644**Parameters** 2645 2646| Name | Type | Mandatory| Description | 2647| -------- | ---- | ---- | ------- | 2648| type | string | Yes | Listening type. The value is fixed at **'selectByRange'**.| 2649| 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.| 2650 2651**Error codes** 2652 2653For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2654 2655| ID| Error Message | 2656| -------- | ------------------------------------------------------- | 2657| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2658 2659**Example** 2660 2661```ts 2662try { 2663 inputMethodController.on('selectByRange', (range: inputMethod.Range) => { 2664 console.log(`Succeeded in subscribing selectByRange: start: ${range.start} , end: ${range.end}`); 2665 }); 2666} catch(err) { 2667 console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`); 2668} 2669``` 2670 2671### off('selectByRange')<sup>10+</sup> 2672 2673off(type: 'selectByRange', callback?: Callback<Range>): void 2674 2675Disables listening for the select-by-range event. This API uses an asynchronous callback to return the result. 2676 2677**System capability**: SystemCapability.MiscServices.InputMethodFramework 2678 2679**Parameters** 2680 2681| Name | Type | Mandatory| Description | 2682| -------- | --------------------------------- | ---- | ------------------------------------------------------------ | 2683| type | string | Yes | Listening type. The value is fixed at **'selectByRange'**.| 2684| 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.| 2685 2686**Example** 2687 2688```ts 2689try { 2690 let onSelectByRangeCallback = (range: inputMethod.Range) => { 2691 console.log(`Succeeded in subscribing selectByRange, start: ${range.start} , end: ${range.end}`); 2692 }; 2693 inputMethodController.off('selectByRange', onSelectByRangeCallback); 2694 inputMethodController.off('selectByRange'); 2695} catch(err) { 2696 console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`); 2697} 2698``` 2699 2700### on('selectByMovement')<sup>10+</sup> 2701 2702on(type: 'selectByMovement', callback: Callback<Movement>): void 2703 2704Enables listening for the select-by-cursor-movement event. This API uses an asynchronous callback to return the result. 2705 2706**System capability**: SystemCapability.MiscServices.InputMethodFramework 2707 2708**Parameters** 2709 2710| Name | Type | Mandatory| Description | 2711| -------- | ----- | ---- | ------ | 2712| type | string | Yes | Listening type. The value is fixed at **'selectByMovement'**.| 2713| 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.| 2714 2715**Error codes** 2716 2717For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2718 2719| ID| Error Message | 2720| -------- | ------------------------------------------------------- | 2721| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2722 2723**Example** 2724 2725```ts 2726try { 2727 inputMethodController.on('selectByMovement', (movement: inputMethod.Movement) => { 2728 console.log('Succeeded in subscribing selectByMovement: direction: ' + movement.direction); 2729 }); 2730} catch(err) { 2731 console.error(`Failed to subscribe selectByMovement: ${JSON.stringify(err)}`); 2732} 2733``` 2734 2735### off('selectByMovement')<sup>10+</sup> 2736 2737off(type: 'selectByMovement', callback?: Callback<Movement>): void 2738 2739Disables listening for the select-by-cursor-movement event. This API uses an asynchronous callback to return the result. 2740 2741**System capability**: SystemCapability.MiscServices.InputMethodFramework 2742 2743**Parameters** 2744 2745| Name | Type | Mandatory| Description | 2746| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ | 2747| type | string | Yes | Listening type. The value is fixed at **'selectByMovement'**.| 2748| 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.| 2749 2750**Example** 2751 2752```ts 2753try { 2754 let onSelectByMovementCallback = (movement: inputMethod.Movement) => { 2755 console.log(`Succeeded in subscribing selectByMovement, movement.direction: ${movement.direction}`); 2756 }; 2757 inputMethodController.off('selectByMovement', onSelectByMovementCallback); 2758 inputMethodController.off('selectByMovement'); 2759} catch(err) { 2760 console.error(`Failed to unsubscribing selectByMovement: ${JSON.stringify(err)}`); 2761} 2762``` 2763 2764### on('getLeftTextOfCursor')<sup>10+</sup> 2765 2766on(type: 'getLeftTextOfCursor', callback: (length: number) => string): void 2767 2768Enables listening for the event of obtaining the length of text deleted leftward. This API uses an asynchronous callback to return the result. 2769 2770**System capability**: SystemCapability.MiscServices.InputMethodFramework 2771 2772**Parameters** 2773 2774| Name | Type | Mandatory| Description | 2775| -------- | ----- | ---- | ------ | 2776| type | string | Yes | Listening type. The value is fixed at **'getLeftTextOfCursor'**.| 2777| callback | (length: number) => string | Yes | Callback used to obtain the text of the specified length deleted leftward.| 2778 2779**Error codes** 2780 2781For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2782 2783| ID| Error Message | 2784| -------- | -------------------------------------- | 2785| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2786| 12800009 | input method client detached. | 2787 2788**Example** 2789 2790```ts 2791try { 2792 inputMethodController.on('getLeftTextOfCursor', (length: number) => { 2793 console.info(`Succeeded in subscribing getLeftTextOfCursor, length: ${length}`); 2794 let text:string = ""; 2795 return text; 2796 }); 2797} catch(err) { 2798 console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`); 2799} 2800``` 2801 2802### off('getLeftTextOfCursor')<sup>10+</sup> 2803 2804off(type: 'getLeftTextOfCursor', callback?: (length: number) => string): void 2805 2806Disables listening for the event of obtaining the length of text deleted leftward. This API uses an asynchronous callback to return the result. 2807 2808**System capability**: SystemCapability.MiscServices.InputMethodFramework 2809 2810**Parameters** 2811 2812| Name| Type | Mandatory| Description | 2813| ------ | ------ | ---- | ------------------------------------------------------------ | 2814| type | string | Yes | Listening type. The value is fixed at **'getLeftTextOfCursor'**.| 2815| 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.| 2816 2817**Example** 2818 2819```ts 2820try { 2821 let getLeftTextOfCursorCallback = (length: number) => { 2822 console.info(`Succeeded in unsubscribing getLeftTextOfCursor, length: ${length}`); 2823 let text:string = ""; 2824 return text; 2825 }; 2826 inputMethodController.off('getLeftTextOfCursor', getLeftTextOfCursorCallback); 2827 inputMethodController.off('getLeftTextOfCursor'); 2828} catch(err) { 2829 console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`); 2830} 2831``` 2832 2833### on('getRightTextOfCursor')<sup>10+</sup> 2834 2835on(type: 'getRightTextOfCursor', callback: (length: number) => string): void 2836 2837Enables listening for the event of obtaining the length of text deleted rightward. This API uses an asynchronous callback to return the result. 2838 2839**System capability**: SystemCapability.MiscServices.InputMethodFramework 2840 2841**Parameters** 2842 2843| Name | Type | Mandatory| Description | 2844| -------- | ----- | ---- | ------ | 2845| type | string | Yes | Listening type. The value is fixed at **'getRightTextOfCursor'**.| 2846| callback | (length: number) => string | Yes | Callback used to obtain the text of the specified length deleted rightward.| 2847 2848**Error codes** 2849 2850For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2851 2852| ID| Error Message | 2853| -------- | -------------------------------------- | 2854| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2855| 12800009 | input method client detached. | 2856 2857**Example** 2858 2859```ts 2860try { 2861 inputMethodController.on('getRightTextOfCursor', (length: number) => { 2862 console.info(`Succeeded in subscribing getRightTextOfCursor, length: ${length}`); 2863 let text:string = ""; 2864 return text; 2865 }); 2866} catch(err) { 2867 console.error(`Failed to subscribe getRightTextOfCursor. err: ${JSON.stringify(err)}`); 2868} 2869``` 2870 2871### off('getRightTextOfCursor')<sup>10+</sup> 2872 2873off(type: 'getRightTextOfCursor', callback?: (length: number) => string): void 2874 2875Disables listening for the event of obtaining the length of text deleted rightward. This API uses an asynchronous callback to return the result. 2876 2877**System capability**: SystemCapability.MiscServices.InputMethodFramework 2878 2879**Parameters** 2880 2881| Name| Type | Mandatory| Description | 2882| ------ | ------ | ---- | ------------------------------------------------------------ | 2883| type | string | Yes | Listening type. The value is fixed at **'getRightTextOfCursor'**.| 2884| 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.| 2885 2886**Example** 2887 2888```ts 2889try { 2890 let getRightTextOfCursorCallback = (length: number) => { 2891 console.info(`Succeeded in unsubscribing getRightTextOfCursor, length: ${length}`); 2892 let text:string = ""; 2893 return text; 2894 }; 2895 inputMethodController.off('getRightTextOfCursor', getRightTextOfCursorCallback); 2896 inputMethodController.off('getRightTextOfCursor'); 2897} catch(err) { 2898 console.error(`Failed to unsubscribing getRightTextOfCursor. err: ${JSON.stringify(err)}`); 2899} 2900``` 2901 2902### on('getTextIndexAtCursor')<sup>10+</sup> 2903 2904on(type: 'getTextIndexAtCursor', callback: () => number): void 2905 2906Enables listening for the event of obtaining the index of text at the cursor. This API uses an asynchronous callback to return the result. 2907 2908**System capability**: SystemCapability.MiscServices.InputMethodFramework 2909 2910**Parameters** 2911 2912| Name | Type | Mandatory| Description | 2913| -------- | ----- | ---- | ------ | 2914| type | string | Yes | Listening type. The value is fixed at **'getTextIndexAtCursor'**.| 2915| callback | () => number | Yes | Callback used to obtain the index of text at the cursor.| 2916 2917**Error codes** 2918 2919For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2920 2921| ID| Error Message | 2922| -------- | -------------------------------------- | 2923| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2924| 12800009 | input method client detached. | 2925 2926**Example** 2927 2928```ts 2929try { 2930 inputMethodController.on('getTextIndexAtCursor', () => { 2931 console.info(`Succeeded in subscribing getTextIndexAtCursor.`); 2932 let index:number = 0; 2933 return index; 2934 }); 2935} catch(err) { 2936 console.error(`Failed to subscribe getTextIndexAtCursor. err: ${JSON.stringify(err)}`); 2937} 2938``` 2939 2940### off('getTextIndexAtCursor')<sup>10+</sup> 2941 2942off(type: 'getTextIndexAtCursor', callback?: () => number): void 2943 2944Disables listening for the event of obtaining the index of text at the cursor. This API uses an asynchronous callback to return the result. 2945 2946**System capability**: SystemCapability.MiscServices.InputMethodFramework 2947 2948**Parameters** 2949 2950| Name| Type | Mandatory| Description | 2951| ------ | ------ | ---- | ------------------------------------------------------------ | 2952| type | string | Yes | Listening type. The value is fixed at **'getTextIndexAtCursor'**.| 2953| 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.| 2954 2955**Example** 2956 2957```ts 2958try { 2959 let getTextIndexAtCursorCallback = () => { 2960 console.info(`Succeeded in unsubscribing getTextIndexAtCursor.`); 2961 let index:number = 0; 2962 return index; 2963 }; 2964 inputMethodController.off('getTextIndexAtCursor', getTextIndexAtCursorCallback); 2965 inputMethodController.off('getTextIndexAtCursor'); 2966} catch(err) { 2967 console.error(`Failed to unsubscribing getTextIndexAtCursor. err: ${JSON.stringify(err)}`); 2968} 2969``` 2970 2971## InputMethodSetting<sup>8+</sup> 2972 2973In the following API examples, you must first use [getSetting](#inputmethodgetsetting9) to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance. 2974 2975### on('imeChange')<sup>9+</sup> 2976 2977on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void 2978 2979Enables listening for the input method and subtype change event. This API uses an asynchronous callback to return the result. 2980 2981**System capability**: SystemCapability.MiscServices.InputMethodFramework 2982 2983**Parameters** 2984 2985| Name | Type | Mandatory| Description | 2986| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | 2987| type | string | Yes | Listening type. The value is fixed at **'imeChange'**.| 2988| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void | Yes| Callback used to return the input method attributes and subtype.| 2989 2990**Example** 2991 2992```ts 2993import { InputMethodSubtype } from '@kit.IMEKit'; 2994try { 2995 inputMethodSetting.on('imeChange', (inputMethodProperty: inputMethod.InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => { 2996 console.log('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype)); 2997 }); 2998} catch(err) { 2999 console.error(`Failed to unsubscribing inputMethodProperty. err: ${JSON.stringify(err)}`); 3000} 3001``` 3002 3003### off('imeChange')<sup>9+</sup> 3004 3005off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void 3006 3007Disables listening for the input method and subtype change event. This API uses an asynchronous callback to return the result. 3008 3009**System capability**: SystemCapability.MiscServices.InputMethodFramework 3010 3011**Parameters** 3012 3013| Name | Type | Mandatory| Description | 3014| -------- | --------- | ---- | --------------- | 3015| type | string | Yes | Listening type. The value is fixed at **'imeChange'**.| 3016| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void | No| Callback used to return the input method attributes and subtype.| 3017 3018**Example** 3019 3020```ts 3021inputMethodSetting.off('imeChange'); 3022``` 3023 3024### listInputMethodSubtype<sup>9+</sup> 3025 3026listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback<Array<InputMethodSubtype>>): void 3027 3028Obtains all subtypes of a specified input method. This API uses an asynchronous callback to return the result. 3029 3030**System capability**: SystemCapability.MiscServices.InputMethodFramework 3031 3032**Parameters** 3033 3034| Name | Type | Mandatory| Description | 3035| -------- | -------------------------------------------------- | ---- | ---------------------- | 3036| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method.| 3037| callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Yes| Callback used to return all subtypes of the specified input method.| 3038 3039**Error codes** 3040 3041For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3042 3043| ID| Error Message | 3044| -------- | -------------------------------------- | 3045| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3046| 12800001 | bundle manager error. | 3047| 12800008 | input method manager service error. | 3048 3049**Example** 3050 3051```ts 3052import { InputMethodSubtype } from '@kit.IMEKit'; 3053import { BusinessError } from '@kit.BasicServicesKit'; 3054 3055let inputMethodProperty: inputMethod.InputMethodProperty = { 3056 name: 'com.example.kikakeyboard', 3057 id: 'propertyId', 3058 packageName: 'com.example.kikakeyboard', 3059 methodId: 'propertyId', 3060} 3061let inputMethodSetting = inputMethod.getSetting(); 3062try { 3063 inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err: BusinessError, data: Array<InputMethodSubtype>) => { 3064 if (err) { 3065 console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); 3066 return; 3067 } 3068 console.log('Succeeded in listing inputMethodSubtype.'); 3069 }); 3070} catch (err) { 3071 console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); 3072} 3073``` 3074 3075### listInputMethodSubtype<sup>9+</sup> 3076 3077listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise<Array<InputMethodSubtype>> 3078 3079Obtains all subtypes of a specified input method. This API uses a promise to return the result. 3080 3081**System capability**: SystemCapability.MiscServices.InputMethodFramework 3082 3083**Parameters** 3084 3085| Name | Type | Mandatory| Description | 3086| -------- | -------------------------------------------------- | ---- | ---------------------- | 3087| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method.| 3088 3089**Return value** 3090 3091| Type | Description | 3092| ----------------------------------------------------------- | ---------------------- | 3093| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise used to return all subtypes of the specified input method.| 3094 3095**Error codes** 3096 3097For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3098 3099| ID| Error Message | 3100| -------- | -------------------------------------- | 3101| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3102| 12800001 | bundle manager error. | 3103| 12800008 | input method manager service error. | 3104 3105**Example** 3106 3107```ts 3108import { InputMethodSubtype } from '@kit.IMEKit'; 3109import { BusinessError } from '@kit.BasicServicesKit'; 3110 3111let inputMethodProperty: inputMethod.InputMethodProperty = { 3112 name: 'com.example.kikakeyboard', 3113 id: 'propertyId', 3114 packageName: 'com.example.kikakeyboard', 3115 methodId: 'propertyId', 3116} 3117let inputMethodSetting = inputMethod.getSetting(); 3118try { 3119 inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data: Array<InputMethodSubtype>) => { 3120 console.log('Succeeded in listing inputMethodSubtype.'); 3121 }).catch((err: BusinessError) => { 3122 console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); 3123 }) 3124} catch(err) { 3125 console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); 3126} 3127``` 3128 3129### listCurrentInputMethodSubtype<sup>9+</sup> 3130 3131listCurrentInputMethodSubtype(callback: AsyncCallback<Array<InputMethodSubtype>>): void 3132 3133Obtains all subtypes of this input method. This API uses an asynchronous callback to return the result. 3134 3135**System capability**: SystemCapability.MiscServices.InputMethodFramework 3136 3137**Parameters** 3138 3139| Name | Type | Mandatory| Description | 3140| -------- | -------------------------------------------------- | ---- | ---------------------- | 3141| callback | AsyncCallback<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Yes | Callback used to return all subtypes of the current input method.| 3142 3143**Error codes** 3144 3145For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3146 3147| ID| Error Message | 3148| -------- | -------------------------------------- | 3149| 12800001 | bundle manager error. | 3150| 12800008 | input method manager service error. | 3151 3152**Example** 3153 3154```ts 3155import { InputMethodSubtype } from '@kit.IMEKit'; 3156import { BusinessError } from '@kit.BasicServicesKit'; 3157 3158let inputMethodSetting = inputMethod.getSetting(); 3159try { 3160 inputMethodSetting.listCurrentInputMethodSubtype((err: BusinessError, data: Array<InputMethodSubtype>) => { 3161 if (err) { 3162 console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 3163 return; 3164 } 3165 console.log('Succeeded in listing currentInputMethodSubtype.'); 3166 }); 3167} catch(err) { 3168 console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 3169} 3170``` 3171 3172### listCurrentInputMethodSubtype<sup>9+</sup> 3173 3174listCurrentInputMethodSubtype(): Promise<Array<InputMethodSubtype>> 3175 3176Obtains all subtypes of this input method. This API uses a promise to return the result. 3177 3178**System capability**: SystemCapability.MiscServices.InputMethodFramework 3179 3180**Return value** 3181 3182| Type | Description | 3183| ----------------------------------------------------------- | ---------------------- | 3184| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise used to return all subtypes of the current input method.| 3185 3186**Error codes** 3187 3188For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3189 3190| ID| Error Message | 3191| -------- | -------------------------------------- | 3192| 12800001 | bundle manager error. | 3193| 12800008 | input method manager service error. | 3194 3195**Example** 3196 3197```ts 3198import { InputMethodSubtype } from '@kit.IMEKit'; 3199import { BusinessError } from '@kit.BasicServicesKit'; 3200 3201let inputMethodSetting = inputMethod.getSetting(); 3202try { 3203 inputMethodSetting.listCurrentInputMethodSubtype().then((data: Array<InputMethodSubtype>) => { 3204 console.log('Succeeded in listing currentInputMethodSubtype.'); 3205 }).catch((err: BusinessError) => { 3206 console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 3207 }) 3208} catch(err) { 3209 console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); 3210} 3211``` 3212 3213### getInputMethods<sup>9+</sup> 3214 3215getInputMethods(enable: boolean, callback: AsyncCallback<Array<InputMethodProperty>>): void 3216 3217Obtains a list of activated or deactivated input methods. This API uses an asynchronous callback to return the result. 3218 3219> **NOTE** 3220> 3221> 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. 3222> 3223> 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. 3224 3225**System capability**: SystemCapability.MiscServices.InputMethodFramework 3226 3227**Parameters** 3228 3229| Name | Type | Mandatory| Description | 3230| -------- | --------------------------------------------------- | ---- | ----------------------------- | 3231| 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.| 3232| callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | Yes | Callback used to return a list of activated or deactivated input methods.| 3233 3234**Error codes** 3235 3236For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3237 3238| ID| Error Message | 3239| -------- | ----------------------------------- | 3240| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3241| 12800001 | bundle manager error. | 3242| 12800008 | input method manager service error. | 3243 3244**Example** 3245 3246```ts 3247import { BusinessError } from '@kit.BasicServicesKit'; 3248 3249try { 3250 inputMethodSetting.getInputMethods(true, (err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => { 3251 if (err) { 3252 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 3253 return; 3254 } 3255 console.log('Succeeded in getting inputMethods.'); 3256 }); 3257} catch (err) { 3258 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 3259} 3260``` 3261 3262### getInputMethods<sup>9+</sup> 3263 3264getInputMethods(enable: boolean): Promise<Array<InputMethodProperty>> 3265 3266Obtains a list of activated or deactivated input methods. This API uses a promise to return the result. 3267 3268> **NOTE** 3269> 3270> 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. 3271> 3272> 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. 3273 3274**System capability**: SystemCapability.MiscServices.InputMethodFramework 3275 3276**Parameters** 3277 3278| Name| Type | Mandatory| Description | 3279| ------ | ------- | ---- | ----------------------- | 3280| 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.| 3281 3282**Return value** 3283 3284| Type | Description | 3285| ------------------------------------------------------------ | ------------------------------------------ | 3286| Promise\<Array\<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return a list of activated or deactivated input methods.| 3287 3288**Error codes** 3289 3290For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3291 3292| ID| Error Message | 3293| -------- | ----------------------------------- | 3294| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3295| 12800001 | bundle manager error. | 3296| 12800008 | input method manager service error. | 3297 3298**Example** 3299 3300```ts 3301import { BusinessError } from '@kit.BasicServicesKit'; 3302 3303try { 3304 inputMethodSetting.getInputMethods(true).then((data: Array<inputMethod.InputMethodProperty>) => { 3305 console.log('Succeeded in getting inputMethods.'); 3306 }).catch((err: BusinessError) => { 3307 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 3308 }) 3309} catch(err) { 3310 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 3311} 3312``` 3313 3314### getInputMethodsSync<sup>11+</sup> 3315 3316getInputMethodsSync(enable: boolean): Array<InputMethodProperty> 3317 3318Obtains a list of activated or deactivated input methods. This API returns the result synchronously. 3319 3320> **NOTE** 3321> 3322> 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. 3323> 3324> 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. 3325 3326**System capability**: SystemCapability.MiscServices.InputMethodFramework 3327 3328**Parameters** 3329 3330| Name| Type | Mandatory| Description | 3331| ------ | ------- | ---- | ----------------------- | 3332| 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.| 3333 3334**Return value** 3335 3336| Type | Description | 3337| ---------------------------------------------------- | ----------------------------- | 3338| Array\<[InputMethodProperty](#inputmethodproperty8)> | List of activated or deactivated input methods.| 3339 3340**Error codes** 3341 3342For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3343 3344| ID| Error Message | 3345| -------- | -------------------------------------- | 3346| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3347| 12800001 | bundle manager error. | 3348| 12800008 |input method manager service error. | 3349 3350**Example** 3351 3352```ts 3353try { 3354 let imeProp = inputMethodSetting.getInputMethodsSync(true); 3355} catch(err) { 3356 console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); 3357} 3358``` 3359 3360### getAllInputMethods<sup>11+</sup> 3361 3362getAllInputMethods(callback: AsyncCallback<Array<InputMethodProperty>>): void 3363 3364Obtains a list of all input methods. This API uses an asynchronous callback to return the result. 3365 3366**System capability**: SystemCapability.MiscServices.InputMethodFramework 3367 3368**Parameters** 3369 3370| Name | Type | Mandatory| Description | 3371| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | 3372| callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | Yes | Callback used to return a list of all input methods.| 3373 3374**Error codes** 3375 3376For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3377 3378| ID| Error Message | 3379| -------- | ----------------------------------- | 3380| 12800001 | bundle manager error. | 3381| 12800008 | input method manager service error. | 3382 3383**Example** 3384 3385```ts 3386import { BusinessError } from '@kit.BasicServicesKit'; 3387 3388try { 3389 inputMethodSetting.getAllInputMethods((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => { 3390 if (err) { 3391 console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`); 3392 return; 3393 } 3394 console.log('Succeeded in getting all inputMethods.'); 3395 }); 3396} catch (err) { 3397 console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`); 3398} 3399``` 3400 3401### getAllInputMethods<sup>11+</sup> 3402 3403getAllInputMethods(): Promise<Array<InputMethodProperty>> 3404 3405Obtains a list of all input methods. This API uses a promise to return the result. 3406 3407**System capability**: SystemCapability.MiscServices.InputMethodFramework 3408 3409**Return value** 3410 3411| Type | Description | 3412| ------------------------------------------------------------ | --------------------------------- | 3413| Promise\<Array\<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return a list of all input methods.| 3414 3415**Error codes** 3416 3417For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3418 3419| ID| Error Message | 3420| -------- | ----------------------------------- | 3421| 12800001 | bundle manager error. | 3422| 12800008 | input method manager service error. | 3423 3424**Example** 3425 3426```ts 3427import { BusinessError } from '@kit.BasicServicesKit'; 3428 3429inputMethodSetting.getAllInputMethods().then((data: Array<inputMethod.InputMethodProperty>) => { 3430 console.log('Succeeded in getting all inputMethods.'); 3431}).catch((err: BusinessError) => { 3432 console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`); 3433}) 3434``` 3435 3436### getAllInputMethodsSync<sup>11+</sup> 3437 3438getAllInputMethodsSync(): Array<InputMethodProperty> 3439 3440Obtains a list of all input methods. This API returns the result synchronously. 3441 3442**System capability**: SystemCapability.MiscServices.InputMethodFramework 3443 3444**Return value** 3445 3446| Type | Description | 3447| ---------------------------------------------------- | ------------------ | 3448| Array\<[InputMethodProperty](#inputmethodproperty8)> | List of all input methods.| 3449 3450**Error codes** 3451 3452For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3453 3454| ID| Error Message | 3455| -------- | ----------------------------------- | 3456| 12800001 | bundle manager error. | 3457| 12800008 | input method manager service error. | 3458 3459**Example** 3460 3461```ts 3462try { 3463 let imeProp = inputMethodSetting.getAllInputMethodsSync(); 3464} catch(err) { 3465 console.error(`Failed to getAllInputMethodsSync: ${JSON.stringify(err)}`); 3466} 3467``` 3468 3469### showOptionalInputMethods<sup>9+</sup> 3470 3471showOptionalInputMethods(callback: AsyncCallback<boolean>): void 3472 3473Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. 3474 3475**System capability**: SystemCapability.MiscServices.InputMethodFramework 3476 3477**Parameters** 3478 3479| Name| Type| Mandatory| Description| 3480| -------- | -------- | -------- | -------- | 3481| 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.| 3482 3483**Error codes** 3484 3485For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3486 3487| ID| Error Message | 3488| -------- | -------------------------------------- | 3489| 12800008 | input method manager service error. | 3490 3491**Example** 3492 3493```ts 3494import { BusinessError } from '@kit.BasicServicesKit'; 3495 3496try { 3497 inputMethodSetting.showOptionalInputMethods((err: BusinessError, data: boolean) => { 3498 if (err) { 3499 console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); 3500 return; 3501 } 3502 console.log('Succeeded in showing optionalInputMethods.'); 3503 }); 3504} catch (err) { 3505 console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); 3506} 3507``` 3508 3509### showOptionalInputMethods<sup>9+</sup> 3510 3511showOptionalInputMethods(): Promise<boolean> 3512 3513Displays a dialog box for selecting an input method. This API uses a promise to return the result. 3514 3515**System capability**: SystemCapability.MiscServices.InputMethodFramework 3516 3517**Return value** 3518 3519| Type| Description| 3520| -------- | -------- | 3521| 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.| 3522 3523**Error codes** 3524 3525For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3526 3527| ID| Error Message | 3528| -------- | -------------------------------------- | 3529| 12800008 | input method manager service error. | 3530 3531**Example** 3532 3533```ts 3534import { BusinessError } from '@kit.BasicServicesKit'; 3535 3536inputMethodSetting.showOptionalInputMethods().then((data: boolean) => { 3537 console.log('Succeeded in showing optionalInputMethods.'); 3538}).catch((err: BusinessError) => { 3539 console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); 3540}) 3541``` 3542 3543### listInputMethod<sup>(deprecated)</sup> 3544 3545listInputMethod(callback: AsyncCallback<Array<InputMethodProperty>>): void 3546 3547Obtains a list of installed input methods. This API uses an asynchronous callback to return the result. 3548 3549> **NOTE** 3550> 3551> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9) instead. 3552 3553**System capability**: SystemCapability.MiscServices.InputMethodFramework 3554 3555**Parameters** 3556 3557| Name | Type | Mandatory| Description | 3558| -------- | -------------------------------------------------- | ---- | ---------------------- | 3559| callback | AsyncCallback<Array<[InputMethodProperty](#inputmethodproperty8)>> | Yes | Callback used to return the list of installed input methods.| 3560 3561**Example** 3562 3563```ts 3564import { BusinessError } from '@kit.BasicServicesKit'; 3565 3566inputMethodSetting.listInputMethod((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => { 3567 if (err) { 3568 console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); 3569 return; 3570 } 3571 console.log('Succeeded in listing inputMethod.'); 3572 }); 3573``` 3574 3575### listInputMethod<sup>(deprecated)</sup> 3576 3577listInputMethod(): Promise<Array<InputMethodProperty>> 3578 3579Obtains a list of installed input methods. This API uses a promise to return the result. 3580 3581> **NOTE** 3582> 3583> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9-1) instead. 3584 3585**System capability**: SystemCapability.MiscServices.InputMethodFramework 3586 3587**Return value** 3588 3589| Type | Description | 3590| ----------------------------------------------------------- | ---------------------- | 3591| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return the list of installed input methods.| 3592 3593**Example** 3594 3595```ts 3596import { BusinessError } from '@kit.BasicServicesKit'; 3597 3598inputMethodSetting.listInputMethod().then((data: Array<inputMethod.InputMethodProperty>) => { 3599 console.log('Succeeded in listing inputMethod.'); 3600}).catch((err: BusinessError) => { 3601 console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); 3602}) 3603``` 3604 3605### displayOptionalInputMethod<sup>(deprecated)</sup> 3606 3607displayOptionalInputMethod(callback: AsyncCallback<void>): void 3608 3609Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result. 3610 3611> **NOTE** 3612> 3613> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9) instead. 3614 3615**System capability**: SystemCapability.MiscServices.InputMethodFramework 3616 3617**Parameters** 3618 3619| Name| Type| Mandatory| Description| 3620| -------- | -------- | -------- | -------- | 3621| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 3622 3623**Example** 3624 3625```ts 3626import { BusinessError } from '@kit.BasicServicesKit'; 3627 3628inputMethodSetting.displayOptionalInputMethod((err: BusinessError) => { 3629 if (err) { 3630 console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); 3631 return; 3632 } 3633 console.log('Succeeded in displaying optionalInputMethod.'); 3634}); 3635``` 3636 3637### displayOptionalInputMethod<sup>(deprecated)</sup> 3638 3639displayOptionalInputMethod(): Promise<void> 3640 3641Displays a dialog box for selecting an input method. This API uses a promise to return the result. 3642 3643> **NOTE** 3644> 3645> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [showOptionalInputMethods()](#showoptionalinputmethods9-1) instead. 3646 3647**System capability**: SystemCapability.MiscServices.InputMethodFramework 3648 3649**Return value** 3650 3651| Type| Description| 3652| -------- | -------- | 3653| Promise<void> | Promise that returns no value.| 3654 3655**Example** 3656 3657```ts 3658import { BusinessError } from '@kit.BasicServicesKit'; 3659 3660inputMethodSetting.displayOptionalInputMethod().then(() => { 3661 console.log('Succeeded in displaying optionalInputMethod.'); 3662}).catch((err: BusinessError) => { 3663 console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); 3664}) 3665``` 3666 3667### getInputMethodState<sup>15+</sup> 3668 3669getInputMethodState(): Promise<EnabledState> 3670 3671Obtains the input method state. This API uses a promise to return the result. 3672 3673**System capability**: SystemCapability.MiscServices.InputMethodFramework 3674 3675**Return value** 3676 3677| Type | Description | 3678| --------------------------------------- | ------------------------------------------------------------ | 3679| 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.| 3680 3681**Error codes** 3682 3683For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3684 3685| ID| Error Message | 3686| -------- | ----------------------------------- | 3687| 12800004 | not an input method application. | 3688| 12800008 | input method manager service error. | 3689 3690**Example** 3691 3692```ts 3693import { BusinessError } from '@kit.BasicServicesKit'; 3694 3695inputMethodSetting.getInputMethodState().then((status: inputMethod.EnabledState) => { 3696 console.log(`Succeeded in getInputMethodState, status: ${status}`); 3697}).catch((err: BusinessError) => { 3698 console.error(`Failed to getInputMethodState: ${JSON.stringify(err)}`); 3699}) 3700``` 3701