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