1# @ohos.inputMethodEngine (Input Method Service) 2 3The **inputMethodEngine** module is oriented to input method applications (including system and third-party input method applications). With the APIs of this module, input method applications are able to create soft keyboard windows, insert or delete characters, select text, and listen for physical keyboard events. 4 5> **NOTE** 6> 7>The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import inputMethodEngine from '@ohos.inputMethodEngine'; 13``` 14 15## Constants 16 17Provides the constant values of function keys, edit boxes, and the cursor. 18 19**System capability**: SystemCapability.MiscServices.InputMethodFramework 20 21| Name| Type| Value| Description| 22| -------- | -------- | -------- | -------- | 23| ENTER_KEY_TYPE_UNSPECIFIED | number | 0 | No function is specified for the Enter key.| 24| ENTER_KEY_TYPE_GO | number | 2 | The Enter key takes the user to the target.| 25| ENTER_KEY_TYPE_SEARCH | number | 3 | The Enter key takes the user to the results of their searching.| 26| ENTER_KEY_TYPE_SEND | number | 4 | The Enter key sends the text to its target.| 27| ENTER_KEY_TYPE_NEXT | number | 5 | The Enter key takes the user to the next field.| 28| ENTER_KEY_TYPE_DONE | number | 6 | The Enter key takes the user to the next line.| 29| ENTER_KEY_TYPE_PREVIOUS | number | 7 | The Enter key takes the user to the previous field.| 30| PATTERN_NULL | number | -1 | Any type of edit box.| 31| PATTERN_TEXT | number | 0 | Text edit box.| 32| PATTERN_NUMBER | number | 2 | Number edit box.| 33| PATTERN_PHONE | number | 3 | Phone number edit box.| 34| PATTERN_DATETIME | number | 4 | Date edit box.| 35| PATTERN_EMAIL | number | 5 | Email edit box.| 36| PATTERN_URI | number | 6 | URI edit box.| 37| PATTERN_PASSWORD | number | 7 | Password edit box.| 38| PATTERN_PASSWORD_NUMBER<sup>11+</sup> | number | 8 | Numeric password edit box.| 39| PATTERN_PASSWORD_SCREEN_LOCK<sup>11+</sup> | number | 9 | Screen lock password edit box.| 40| OPTION_ASCII | number | 20 | ASCII values are allowed.| 41| OPTION_NONE | number | 0 | No input attribute is specified.| 42| OPTION_AUTO_CAP_CHARACTERS | number | 2 | Characters are allowed.| 43| OPTION_AUTO_CAP_SENTENCES | number | 8 | Sentences are allowed.| 44| OPTION_AUTO_WORDS | number | 4 | Words are allowed.| 45| OPTION_MULTI_LINE | number | 1 | Multiple lines are allowed.| 46| OPTION_NO_FULLSCREEN | number | 10 | Half-screen style.| 47| FLAG_SELECTING | number | 2 | The edit box is being selected.| 48| FLAG_SINGLE_LINE | number | 1 | The edit box allows only single-line input.| 49| DISPLAY_MODE_PART | number | 0 | The edit box is displayed in half-screen mode.| 50| DISPLAY_MODE_FULL | number | 1 | The edit box is displayed in full screen.| 51| CURSOR_UP<sup>9+</sup> | number | 1 | The caret moves upward.| 52| CURSOR_DOWN<sup>9+</sup> | number | 2 | The caret moves downward.| 53| CURSOR_LEFT<sup>9+</sup> | number | 3 | The caret moves leftward.| 54| CURSOR_RIGHT<sup>9+</sup> | number | 4 | The caret moves rightward.| 55| WINDOW_TYPE_INPUT_METHOD_FLOAT<sup>9+</sup> | number | 2105 | The input method is displayed in a floating window.| 56 57## inputMethodEngine.getInputMethodAbility<sup>9+</sup> 58 59getInputMethodAbility(): InputMethodAbility 60 61Obtains an [InputMethodAbility](#inputmethodability) instance for the input method. This API can be called only by an input method. 62 63The input method can use the obtained instance to subscribe to a soft keyboard display/hide request event, create/destroy an input method panel, and the like. 64 65**System capability**: SystemCapability.MiscServices.InputMethodFramework 66 67**Return value** 68 69| Type | Description | 70| ----------------------------------------- | ------------------ | 71| [InputMethodAbility](#inputmethodability) | **InputMethodAbility** instance.| 72 73**Example** 74 75```ts 76let InputMethodAbility = inputMethodEngine.getInputMethodAbility(); 77``` 78 79## inputMethodEngine.getKeyboardDelegate<sup>9+</sup> 80 81getKeyboardDelegate(): KeyboardDelegate 82 83Obtains a [KeyboardDelegate](#keyboarddelegate) instance for the input method. 84 85The input method can use the obtained instance to subscribe to a physical keyboard event, text selection change event, and more. 86 87**System capability**: SystemCapability.MiscServices.InputMethodFramework 88 89**Return value** 90 91| Type | Description | 92| ------------------------------------- | ------------------------ | 93| [KeyboardDelegate](#keyboarddelegate) | **KeyboardDelegate** instance.| 94 95**Example** 96 97```ts 98let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate(); 99``` 100 101## inputMethodEngine.getInputMethodEngine<sup>(deprecated)</sup> 102 103getInputMethodEngine(): InputMethodEngine 104 105Obtains an [InputMethodEngine](#inputmethodengine) instance for the input method. 106 107The input method can use the obtained instance to subscribe to a soft keyboard display/hide request event. 108 109> **NOTE** 110> 111> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethodAbility()](#inputmethodenginegetinputmethodability9) instead. 112 113**System capability**: SystemCapability.MiscServices.InputMethodFramework 114 115**Return value** 116 117| Type | Description | 118| ----------------------------------------- | ------------------ | 119| [InputMethodEngine](#inputmethodengine) | **InputMethodAbility** instance.| 120 121**Example** 122 123```ts 124let InputMethodEngine = inputMethodEngine.getInputMethodEngine(); 125``` 126 127## inputMethodEngine.createKeyboardDelegate<sup>(deprecated)</sup> 128 129createKeyboardDelegate(): KeyboardDelegate 130 131Obtains a [KeyboardDelegate](#keyboarddelegate) instance for the input method. 132 133The input method can use the obtained instance to subscribe to a physical keyboard event, text selection change event, and more. 134 135> **NOTE** 136> 137>This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getKeyboardDelegate()](#inputmethodenginegetkeyboarddelegate9) instead. 138 139**System capability**: SystemCapability.MiscServices.InputMethodFramework 140 141**Return value** 142 143| Type | Description | 144| ------------------------------------- | ------------------------ | 145| [KeyboardDelegate](#keyboarddelegate) | **KeyboardDelegate** instance.| 146 147**Example** 148 149```ts 150let keyboardDelegate = inputMethodEngine.createKeyboardDelegate(); 151``` 152 153## InputMethodEngine 154 155In the following API examples, you must first use [getInputMethodEngine](#inputmethodenginegetinputmethodenginedeprecated) to obtain an **InputMethodEngine** instance, and then call the APIs using the obtained instance. 156 157### on('inputStart') 158 159on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void 160 161Enables listening for the input method binding event. This API uses an asynchronous callback to return the result. 162 163**System capability**: SystemCapability.MiscServices.InputMethodFramework 164 165**Parameters** 166 167| Name | Type | Mandatory| Description | 168| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | 169| type | string | Yes | Listening type. The value is fixed at **'inputStart'**.| 170| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclientdeprecated)) => void | Yes| Callback used to return the **KeyboardController** and **TextInputClient** instances.| 171 172**Example** 173 174```ts 175try { 176 inputMethodEngine.getInputMethodEngine() 177 .on('inputStart', (kbController: inputMethodEngine.KeyboardController, textClient: inputMethodEngine.TextInputClient) => { 178 let keyboardController = kbController; 179 let textInputClient = textClient; 180 }); 181} catch(err) { 182 console.error(`Failed to inputStart: ${JSON.stringify(err)}`); 183} 184``` 185 186### off('inputStart') 187 188off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void 189 190Disables listening for the input method binding event. 191 192**System capability**: SystemCapability.MiscServices.InputMethodFramework 193 194**Parameters** 195 196| Name | Type | Mandatory| Description | 197| -------- | -------------------- | ---- | ------------------------ | 198| type | string | Yes | Listening type. The value is fixed at **'inputStart'**.| 199| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclientdeprecated)) => void | No| Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 200 201**Example** 202 203```ts 204try { 205 inputMethodEngine.getInputMethodEngine() 206 .off('inputStart', (kbController: inputMethodEngine.KeyboardController, textClient: inputMethodEngine.TextInputClient) => { 207 console.log('delete inputStart notification.'); 208 }); 209} catch(err) { 210 console.error(`Failed to inputStart: ${JSON.stringify(err)}`); 211} 212``` 213 214### on('keyboardShow'|'keyboardHide') 215 216on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void 217 218Enables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result. 219 220**System capability**: SystemCapability.MiscServices.InputMethodFramework 221 222**Parameters** 223 224| Name | Type | Mandatory| Description | 225| -------- | ------ | ---- | ------------------------------------------------------------ | 226| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.| 227| callback | () => void | Yes | Callback used to return the result. | 228 229**Example** 230 231```ts 232try { 233 inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => { 234 console.log('inputMethodEngine keyboardShow.'); 235 }); 236 inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => { 237 console.log('inputMethodEngine keyboardHide.'); 238 }); 239} catch(err) { 240 console.error(`Failed to InputMethodEngine: ${JSON.stringify(err)}`); 241} 242``` 243 244### off('keyboardShow'|'keyboardHide') 245 246off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void 247 248Disables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result. 249 250**System capability**: SystemCapability.MiscServices.InputMethodFramework 251 252**Parameters** 253 254| Name | Type | Mandatory| Description | 255| -------- | ------ | ---- | ------------------------------------------------------------ | 256| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.| 257| callback | () => void | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 258 259**Example** 260 261```ts 262inputMethodEngine.getInputMethodEngine().off('keyboardShow'); 263inputMethodEngine.getInputMethodEngine().off('keyboardHide'); 264``` 265 266## InputMethodAbility 267 268In the following API examples, you must first use [getInputMethodAbility](#inputmethodenginegetinputmethodability9) to obtain an **InputMethodAbility** instance, and then call the APIs using the obtained instance. 269 270### on('inputStart')<sup>9+</sup> 271 272on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: InputClient) => void): void 273 274Enables listening for the input method binding event. This API uses an asynchronous callback to return the result. 275 276**System capability**: SystemCapability.MiscServices.InputMethodFramework 277 278**Parameters** 279 280| Name | Type | Mandatory| Description | 281| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | 282| type | string | Yes | Listening type. The value is fixed at **'inputStart'**.| 283| callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | Yes| Callback used to return the result.| 284 285**Example** 286 287```ts 288try { 289 inputMethodEngine.getInputMethodAbility() 290 .on('inputStart', (kbController: inputMethodEngine.KeyboardController, client: inputMethodEngine.InputClient) => { 291 let keyboardController = kbController; 292 let inputClient = client; 293 }); 294} catch(err) { 295 console.error(`Failed to InputMethodAbility: ${JSON.stringify(err)}`); 296} 297``` 298 299### off('inputStart')<sup>9+</sup> 300 301off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClient: InputClient) => void): void 302 303Disables listening for the input method binding event. This API uses an asynchronous callback to return the result. 304 305**System capability**: SystemCapability.MiscServices.InputMethodFramework 306 307**Parameters** 308 309| Name | Type | Mandatory| Description | 310| -------- | -------------------- | ---- | ------------------------ | 311| type | string | Yes | Listening type. The value is fixed at **'inputStart'**.| 312| callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | No| Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 313 314**Example** 315 316```ts 317inputMethodEngine.getInputMethodAbility().off('inputStart'); 318``` 319 320### on('inputStop')<sup>9+</sup> 321 322on(type: 'inputStop', callback: () => void): void 323 324Enables listening for the input method unbinding event. This API uses an asynchronous callback to return the result. 325 326**System capability**: SystemCapability.MiscServices.InputMethodFramework 327 328**Parameters** 329 330| Name | Type | Mandatory| Description | 331| -------- | ------ | ---- | ------------------------------------------------------------ | 332| type | string | Yes | Listening type. The value is fixed at **'inputStop'**.| 333| callback | () => void | Yes | Callback used to return the result. | 334 335**Example** 336 337```ts 338try { 339 inputMethodEngine.getInputMethodAbility().on('inputStop', () => { 340 console.log('inputMethodAbility inputStop'); 341 }); 342} catch(err) { 343 console.error(`Failed to inputStop: ${JSON.stringify(err)}`); 344} 345``` 346 347### off('inputStop')<sup>9+</sup> 348 349off(type: 'inputStop', callback: () => void): void 350 351Disables listening for the input method stop event. This API uses an asynchronous callback to return the result. 352 353**System capability**: SystemCapability.MiscServices.InputMethodFramework 354 355**Parameters** 356 357| Name | Type | Mandatory| Description | 358| -------- | ------ | ---- | ------------------------------------------------------------ | 359| type | string | Yes | Listening type. The value is fixed at **'inputStop'**.| 360| callback | () => void | Yes | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type. | 361 362**Example** 363 364```ts 365try { 366 inputMethodEngine.getInputMethodAbility().off('inputStop', () => { 367 console.log('inputMethodAbility delete inputStop notification.'); 368 }); 369} catch(err) { 370 console.error(`Failed to inputStop: ${JSON.stringify(err)}`); 371} 372``` 373 374### on('setCallingWindow')<sup>9+</sup> 375 376on(type: 'setCallingWindow', callback: (wid: number) => void): void 377 378Enables listening for the window invocation setting event. This API uses an asynchronous callback to return the result. 379 380**System capability**: SystemCapability.MiscServices.InputMethodFramework 381 382**Parameters** 383 384| Name | Type | Mandatory| Description | 385| -------- | ------ | ---- | ------------------------------------------------------------ | 386| type | string | Yes | Listening type. The value is fixed at **'setCallingWindow'**.| 387| callback | (wid: number) => void | Yes | Callback used to return the window ID of the caller. | 388 389**Example** 390 391```ts 392try { 393 inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid: number) => { 394 console.log('inputMethodAbility setCallingWindow'); 395 }); 396} catch(err) { 397 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 398} 399``` 400 401### off('setCallingWindow')<sup>9+</sup> 402 403off(type: 'setCallingWindow', callback: (wid:number) => void): void 404 405Disables listening for the window invocation setting event. This API uses an asynchronous callback to return the result. 406 407**System capability**: SystemCapability.MiscServices.InputMethodFramework 408 409**Parameters** 410 411| Name | Type | Mandatory| Description | 412| -------- | ------ | ---- | ------------------------------------------------------------ | 413| type | string | Yes | Listening type. The value is fixed at **'setCallingWindow'**.| 414| callback | (wid:number) => void | Yes | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 415 416**Example** 417 418```ts 419try { 420 inputMethodEngine.getInputMethodAbility().off('setCallingWindow', (wid: number) => { 421 console.log('inputMethodAbility delete setCallingWindow notification.'); 422 }); 423} catch(err) { 424 console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); 425} 426``` 427 428### on('keyboardShow'|'keyboardHide')<sup>9+</sup> 429 430on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void 431 432Enables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result. 433 434**System capability**: SystemCapability.MiscServices.InputMethodFramework 435 436**Parameters** 437 438| Name | Type | Mandatory| Description | 439| -------- | ------ | ---- | ------------------------------------------------------------ | 440| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.| 441| callback | () => void | Yes | Callback used to return the result. | 442 443**Example** 444 445```ts 446try { 447 inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => { 448 console.log('InputMethodAbility keyboardShow.'); 449 }); 450 inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => { 451 console.log('InputMethodAbility keyboardHide.'); 452 }); 453} catch(err) { 454 console.error(`Failed to keyboard: ${JSON.stringify(err)}`); 455} 456``` 457 458### off('keyboardShow'|'keyboardHide')<sup>9+</sup> 459 460off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void 461 462Disables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result. 463 464**System capability**: SystemCapability.MiscServices.InputMethodFramework 465 466**Parameters** 467 468| Name | Type | Mandatory| Description | 469| -------- | ------ | ---- | ------------------------------------------------------------ | 470| type | string | Yes | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.| 471| callback | () => void | No | Callback used to return the result.| 472 473**Example** 474 475```ts 476try { 477 inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => { 478 console.log('InputMethodAbility delete keyboardShow notification.'); 479 }); 480 inputMethodEngine.getInputMethodAbility().off('keyboardHide', () => { 481 console.log('InputMethodAbility delete keyboardHide notification.'); 482 }); 483} catch(err) { 484 console.error(`Failed to keyboard: ${JSON.stringify(err)}`); 485} 486``` 487 488### on('setSubtype')<sup>9+</sup> 489 490on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => void): void 491 492Enables listening for the input method subtype setting event. This API uses an asynchronous callback to return the result. 493 494**System capability**: SystemCapability.MiscServices.InputMethodFramework 495 496**Parameters** 497 498| Name | Type| Mandatory | Description| 499| -------- | --- | ---- | --- | 500| type | string | Yes | Listening type. The value is fixed at **'setSubtype'**.| 501| callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | Yes | Callback used to return the input method subtype. | 502 503**Example** 504 505```ts 506import InputMethodSubtype from '@ohos.InputMethodSubtype'; 507 508try { 509 inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype: InputMethodSubtype) => { 510 console.log('InputMethodAbility setSubtype.'); 511 }); 512} catch(err) { 513 console.error(`Failed to setSubtype: ${JSON.stringify(err)}`); 514} 515``` 516 517### off('setSubtype')<sup>9+</sup> 518 519off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void 520 521Disables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result. 522 523**System capability**: SystemCapability.MiscServices.InputMethodFramework 524 525**Parameters** 526 527| Name | Type | Mandatory| Description | 528| ------- | ----- | ---- | ---- | 529| type | string | Yes | Listening type. The value is fixed at **'setSubtype'**.| 530| callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type. | 531 532**Example** 533 534```ts 535try { 536 inputMethodEngine.getInputMethodAbility().off('setSubtype', () => { 537 console.log('InputMethodAbility delete setSubtype notification.'); 538 }); 539} catch(err) { 540 console.error(`Failed to setSubtype: ${JSON.stringify(err)}`); 541} 542``` 543 544### on('securityModeChange')<sup>11+</sup> 545 546on(type: 'securityModeChange', callback: Callback< SecurityMode>): void 547 548Enables listening for security mode changes of the input method. This API uses an asynchronous callback to return the result. 549 550**System capability**: SystemCapability.MiscServices.InputMethodFramework 551 552**Parameters** 553 554| Name | Type | Mandatory| Description | 555| -------- | ------------------------------------------- | ---- | ---------------------------------------------- | 556| type | string | Yes | Listening type. The value is fixed at **'securityModeChange'**.| 557| callback | Callback\<[SecurityMode](#securitymode11))> | Yes | Callback used to return the current security mode. | 558 559**Example** 560 561```ts 562try { 563 inputMethodEngine.getInputMethodAbility().on('securityModeChange', (securityMode: inputMethodEngine.SecurityMode) => { 564 console.log(`InputMethodAbility securityModeChange, security is ${securityMode}`); 565 }); 566} catch(err) { 567 console.error(`Failed to on securityModeChange: ${JSON.stringify(err)}`); 568} 569``` 570 571### off('securityModeChange')<sup>11+</sup> 572 573off(type: 'securityModeChange', callback?: Callback< SecurityMode>): void 574 575Disables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result. 576 577**System capability**: SystemCapability.MiscServices.InputMethodFramework 578 579**Parameters** 580 581| Name | Type | Mandatory| Description | 582| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 583| type | string | Yes | Listening type. The value is fixed at **'securityModeChange'**. | 584| callback | Callback\<[SecurityMode](#securitymode11))> | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 585 586**Example** 587 588```ts 589let securityChangeCallback = (securityMode: inputMethodEngine.SecurityMode) => { 590 console.log(`InputMethodAbility securityModeChange, security is ${securityMode}`); 591}; 592let inputMethodAbility = inputMethodEngine.getInputMethodAbility(); 593inputMethodAbility.on('securityModeChange', securityChangeCallback); 594try { 595 inputMethodAbility.off('securityModeChange', securityChangeCallback); 596} catch(err) { 597 console.error(`Failed to off securityModeChange: ${JSON.stringify(err)}`); 598} 599``` 600 601### getSecurityMode<sup>11+</sup> 602 603getSecurityMode(): SecurityMode 604 605Obtains the current security mode of the input method. 606 607**System capability**: SystemCapability.MiscServices.InputMethodFramework 608 609**Return value** 610 611| Type | Description | 612| ------------------------------- | ---------- | 613| [SecurityMode](#securitymode11) | Security mode.| 614 615**Error codes** 616 617| ID| Error Message | 618| -------- | ------------------------------ | 619| 12800004 | not an input method extension. | 620 621**Example** 622 623```ts 624try { 625 let security = inputMethodEngine.getInputMethodAbility().getSecurityMode(); 626 console.error(`getSecurityMode, securityMode is : ${security}`); 627} catch (err) { 628 console.error(`Failed to getSecurityMode: ${JSON.stringify(err)}`); 629} 630``` 631 632### createPanel<sup>10+</sup> 633 634createPanel(ctx: BaseContext, info: PanelInfo, callback: AsyncCallback\<Panel>): void 635 636Creates an input method panel. This API uses an asynchronous callback to return the result.<br>Only one [SOFT_KEYBOARD](#paneltype10) panel and one [STATUS_BAR](#paneltype10) panel can be created for a single input method. 637 638**System capability**: SystemCapability.MiscServices.InputMethodFramework 639 640**Parameters** 641 642| Name | Type | Mandatory| Description | 643| ------- | ----------- | ---- | ------------------------ | 644| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | Yes | Current context of the input method.| 645| info | [PanelInfo](#panelinfo10) | Yes | Information about the input method panel.| 646| callback | AsyncCallback\<[Panel](#panel10)> | Yes | Callback used to return the result. If the operation is successful, the created input method panel is returned. | 647 648**Error codes** 649 650| ID | Error Message | 651| ---------- | ----------------------------- | 652| 12800004 | not an input method extension. | 653 654**Example** 655 656```ts 657import { BusinessError } from '@ohos.base'; 658 659let panelInfo: inputMethodEngine.PanelInfo = { 660 type: inputMethodEngine.PanelType.SOFT_KEYBOARD, 661 flag: inputMethodEngine.PanelFlag.FLG_FIXED 662} 663try { 664 inputMethodEngine.getInputMethodAbility() 665 .createPanel(this.context, panelInfo, (err: BusinessError, panel: inputMethodEngine.Panel) => { 666 if (err) { 667 console.error(`Failed to createPanel: ${JSON.stringify(err)}`); 668 return; 669 } 670 console.log('Succeed in creating panel.'); 671 }) 672} catch (err) { 673 console.error(`Failed to createPanel: ${JSON.stringify(err)}`); 674} 675``` 676 677### createPanel<sup>10+</sup> 678 679createPanel(ctx: BaseContext, info: PanelInfo): Promise\<Panel> 680 681Creates an input method panel. This API uses a promise to return the result.<br>Only one [SOFT_KEYBOARD](#paneltype10) panel and one [STATUS_BAR](#paneltype10) panel can be created for a single input method. 682 683**System capability**: SystemCapability.MiscServices.InputMethodFramework 684 685**Parameters** 686 687| Name | Type | Mandatory| Description | 688| ------- | ----------- | ---- | ------------------------ | 689| ctx | [BaseContext](js-apis-inner-application-baseContext.md) | Yes | Current context of the input method.| 690| info | [PanelInfo](#panelinfo10) | Yes | Information about the input method panel.| 691 692**Return value** 693| Type | Description | 694| ------- | ------------------------------------------------------------------ | 695| Promise\<[Panel](#panel10)> | Callback used to return the result. If the operation is successful, the created input method panel is returned. | 696 697**Error codes** 698 699| ID | Error Message | 700| ---------- | ----------------------------- | 701| 12800004 | not an input method extension. | 702 703**Example** 704 705```ts 706import { BusinessError } from '@ohos.base'; 707 708let panelInfo: inputMethodEngine.PanelInfo = { 709 type: inputMethodEngine.PanelType.SOFT_KEYBOARD, 710 flag: inputMethodEngine.PanelFlag.FLG_FIXED 711} 712inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo) 713 .then((panel: inputMethodEngine.Panel) => { 714 console.log('Succeed in creating panel.'); 715 }).catch((err: BusinessError) => { 716 console.error(`Failed to create panel: ${JSON.stringify(err)}`); 717 }) 718``` 719 720### destroyPanel<sup>10+</sup> 721 722destroyPanel(panel: Panel, callback: AsyncCallback\<void>): void 723 724Destroys the specified input method panel. This API uses an asynchronous callback to return the result. 725 726**System capability**: SystemCapability.MiscServices.InputMethodFramework 727 728**Parameters** 729 730| Name | Type | Mandatory| Description | 731| ------- | ----------- | ---- | ------------------------ | 732| panel | [Panel](#panel10) | Yes | Input method panel to destroy.| 733| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 734 735**Example** 736 737```ts 738import { BusinessError } from '@ohos.base'; 739 740let panelInfo: inputMethodEngine.PanelInfo = { 741 type: inputMethodEngine.PanelType.SOFT_KEYBOARD, 742 flag: inputMethodEngine.PanelFlag.FLG_FIXED 743} 744let inputPanel: inputMethodEngine.Panel | undefined = undefined; 745try { 746 inputMethodEngine.getInputMethodAbility() 747 .createPanel(this.context, panelInfo, (err: BusinessError, panel: inputMethodEngine.Panel) => { 748 if (err) { 749 console.error(`Failed to create panel: ${JSON.stringify(err)}`); 750 return; 751 } 752 inputPanel = panel; 753 console.log('Succeed in creating panel.'); 754 }) 755} catch (err) { 756 console.error(`Failed to create panel: ${JSON.stringify(err)}`); 757} 758try { 759 if (inputPanel) { 760 inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel, (err: BusinessError) => { 761 if (err !== undefined) { 762 console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); 763 return; 764 } 765 console.log('Succeed in destroying panel.'); 766 }) 767 } 768} catch (err) { 769 console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); 770} 771``` 772 773### destroyPanel<sup>10+</sup> 774 775destroyPanel(panel: Panel): Promise\<void> 776 777Destroys the specified input method panel. This API uses a promise to return the result. 778 779**System capability**: SystemCapability.MiscServices.InputMethodFramework 780 781**Parameters** 782 783| Name | Type | Mandatory| Description | 784| ---------| ----------- | ---- | ------------------------ | 785| panel | [Panel](#panel10) | Yes | Input method panel to destroy. | 786 787**Return value** 788| Type | Description | 789| ------- | -------------------------------------------------------------------- | 790| Promise\<void> | Promise that returns no value.| 791 792**Example** 793 794```ts 795import { BusinessError } from '@ohos.base'; 796 797let panelInfo: inputMethodEngine.PanelInfo = { 798 type: inputMethodEngine.PanelType.SOFT_KEYBOARD, 799 flag: inputMethodEngine.PanelFlag.FLG_FIXED 800} 801let inputPanel: inputMethodEngine.Panel | undefined = undefined; 802try { 803 inputMethodEngine.getInputMethodAbility() 804 .createPanel(this.context, panelInfo, (err: BusinessError, panel: inputMethodEngine.Panel) => { 805 if (err) { 806 console.error(`Failed to create panel: ${JSON.stringify(err)}`); 807 return; 808 } 809 inputPanel = panel; 810 console.log('Succeed in creating panel.'); 811 }) 812} catch (err) { 813 console.error(`Failed to create panel: ${JSON.stringify(err)}`); 814} 815 816try { 817 if (inputPanel) { 818 inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel).then(() => { 819 console.log('Succeed in destroying panel.'); 820 }).catch((err: BusinessError) => { 821 console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); 822 }); 823 } 824} catch (err) { 825 console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); 826} 827``` 828 829## KeyboardDelegate 830 831In the following API examples, you must first use [getKeyboardDelegate](#inputmethodenginegetkeyboarddelegate9) to obtain a **KeyboardDelegate** instance, and then call the APIs using the obtained instance. 832 833### on('keyDown'|'keyUp') 834 835on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void 836 837Enables listening for a physical keyboard event. This API uses an asynchronous callback to return the result. 838 839**System capability**: SystemCapability.MiscServices.InputMethodFramework 840 841**Parameters** 842 843| Name | Type | Mandatory| Description | 844| -------- | ------------------------------- | ---- |-----------------------------------------------------| 845| type | string | Yes | Listening type.<br>- The value **'keyDown'** indicates the keydown event.<br>- The value **'keyUp'** indicates the keyup event.| 846| callback | (event: [KeyEvent](#keyevent)) => boolean | Yes| Callback used to return the key information. If the event is consumed by the event subscriber, **true** is returned. Otherwise, **false** is returned. | 847 848**Example** 849 850```ts 851try { 852 inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent: inputMethodEngine.KeyEvent) => { 853 console.log('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode)); 854 console.log('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction)); 855 return true; 856 }); 857 inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent: inputMethodEngine.KeyEvent) => { 858 console.log('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode)); 859 console.log('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction)); 860 return true; 861 }); 862} catch(err) { 863 console.error(`Failed to KeyboardDelegate: ${JSON.stringify(err)}`); 864} 865``` 866 867### off('keyDown'|'keyUp') 868 869off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void 870 871Disables listening for a physical keyboard event. This API uses an asynchronous callback to return the result. 872 873**System capability**: SystemCapability.MiscServices.InputMethodFramework 874 875**Parameters** 876 877| Name | Type | Mandatory | Description | 878| -------- | ------- | ---- | ----- | 879| type | string | Yes | Listening type.<br>- The value **'keyDown'** indicates the keydown event.<br>- The value **'keyUp'** indicates the keyup event.| 880| callback | (event: [KeyEvent](#keyevent)) => boolean | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type. | 881 882**Example** 883 884```ts 885try { 886 inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent: inputMethodEngine.KeyEvent) => { 887 console.log('delete keyUp notification.'); 888 return true; 889 }); 890 inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent: inputMethodEngine.KeyEvent) => { 891 console.log('delete keyDown notification.'); 892 return true; 893 }); 894} catch(err) { 895 console.error(`Failed to keyevent: ${JSON.stringify(err)}`); 896} 897``` 898 899### on('keyEvent')<sup>10+</sup> 900 901on(type: 'keyEvent', callback: (event: InputKeyEvent) => boolean): void 902 903Enables listening for a keyboard event. This API uses an asynchronous callback to return the result. 904 905**System capability**: SystemCapability.MiscServices.InputMethodFramework 906 907**Parameters** 908 909| Name | Type | Mandatory| Description | 910| -------- | -------- | ---- | ------------------------------------------------------------ | 911| type | string | Yes | Listening type. The value is fixed at **'keyEvent'**.| 912| callback | function | Yes | Callback used to return the result.<br>- The input parameter is of the [InputKeyEvent](js-apis-keyevent.md#KeyEvent) type and indicates the key event information.<br>- If the event is consumed by the event subscriber, **true** is returned. Otherwise, **false** is returned.| 913 914**Example** 915 916```ts 917import type { KeyEvent } from '@ohos.multimodalInput.keyEvent'; 918 919try { 920 inputMethodEngine.getKeyboardDelegate().on('keyEvent', (keyEvent: KeyEvent) => { 921 console.log('inputMethodEngine keyEvent.action:' + JSON.stringify(keyEvent.action)); 922 console.log('inputMethodEngine keyEvent.key.code:' + JSON.stringify(keyEvent.key.code)); 923 console.log('inputMethodEngine keyEvent.ctrlKey:' + JSON.stringify(keyEvent.ctrlKey)); 924 return true; 925 }); 926} catch(err) { 927 console.error(`Failed to inputMethodEngine: ${JSON.stringify(err)}`); 928} 929``` 930 931### off('keyEvent')<sup>10+</sup> 932 933off(type: 'keyEvent', callback?: (event: InputKeyEvent) => boolean): void 934 935Disables listening for a keyboard event. This API uses an asynchronous callback to return the result. 936 937**System capability**: SystemCapability.MiscServices.InputMethodFramework 938 939**Parameters** 940 941| Name | Type | Mandatory| Description | 942| -------- | -------- | ---- | ------------------------------------------------------------ | 943| type | string | Yes | Listening type. The value is fixed at **'keyEvent'**.| 944| callback | function | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 945 946**Example** 947 948```ts 949import type { KeyEvent } from '@ohos.multimodalInput.keyEvent'; 950 951try { 952 inputMethodEngine.getKeyboardDelegate().off('keyEvent', (keyEvent: KeyEvent) => { 953 console.log('This is a callback function which will be deregistered.'); 954 return true; 955 }); 956 inputMethodEngine.getKeyboardDelegate().off('keyEvent'); 957} catch(err) { 958 console.error(`Failed to keyEvent: ${JSON.stringify(err)}`); 959} 960``` 961 962### on('cursorContextChange') 963 964on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void 965 966Enables listening for the cursor change event. This API uses an asynchronous callback to return the result. 967 968**System capability**: SystemCapability.MiscServices.InputMethodFramework 969 970**Parameters** 971 972| Name | Type | Mandatory | Description | 973| -------- | ---- | ---- | ----- | 974| type | string | Yes | Listening type. The value is fixed at **'cursorContextChange'**.| 975| callback | (x: number, y: number, height: number) => void | Yes | Callback used to return the cursor movement direction.<br>- **x**: x coordinate of the top of the cursor.<br>- **y**: y coordinate of the bottom of the cursor.<br>- **height**: height of the cursor.| 976 977**Example** 978 979```ts 980try { 981 inputMethodEngine.getKeyboardDelegate().on('cursorContextChange', (x: number, y: number, height: number) => { 982 console.log('inputMethodEngine cursorContextChange x:' + x); 983 console.log('inputMethodEngine cursorContextChange y:' + y); 984 console.log('inputMethodEngine cursorContextChange height:' + height); 985 }); 986} catch(err) { 987 console.error(`Failed to cursorContextChange: ${JSON.stringify(err)}`); 988} 989``` 990 991### off('cursorContextChange') 992 993off(type: 'cursorContextChange', callback?: (x: number, y: number, height: number) => void): void 994 995Disables listening for cursor context changes. This API uses an asynchronous callback to return the result. 996 997**System capability**: SystemCapability.MiscServices.InputMethodFramework 998 999 **Parameters** 1000 1001| Name | Type | Mandatory | Description | 1002| -------- | ---- | ---- | ------ | 1003| type | string | Yes | Listening type. The value is fixed at **'cursorContextChange'**.| 1004| callback | (x: number, y:number, height:number) => void | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 1005 1006 1007 **Example** 1008 1009```ts 1010try { 1011 inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x: number, y: number, height: number) => { 1012 console.log('delete cursorContextChange notification.'); 1013 }); 1014} catch(err) { 1015 console.error(`Failed to cursorContextChange: ${JSON.stringify(err)}`); 1016} 1017``` 1018### on('selectionChange') 1019 1020on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void 1021 1022Enables listening for the text selection change event. This API uses an asynchronous callback to return the result. 1023 1024**System capability**: SystemCapability.MiscServices.InputMethodFramework 1025 1026**Parameters** 1027 1028| Name | Type | Mandatory| Description | 1029| -------- | ----- | ---- | ---- | 1030| type | string | Yes | Listening type. The value is fixed at **'selectionChange'**.| 1031| callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | Yes | Callback used to return the text selection information.<br>- **oldBegin**: start of the selected text before the change.<br>- **oldEnd**: end of the selected text before the change.<br>- **newBegin**: start of the selected text after the change.<br>- **newEnd**: end of the selected text after the change.| 1032 1033**Example** 1034 1035```ts 1036try { 1037 inputMethodEngine.getKeyboardDelegate() 1038 .on('selectionChange', (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => { 1039 console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin); 1040 console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd); 1041 console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin); 1042 console.log('inputMethodEngine beforeEach selectionChange newEnd:' + newEnd); 1043 }); 1044} catch(err) { 1045 console.error(`Failed to selectionChange: ${JSON.stringify(err)}`); 1046} 1047``` 1048 1049### off('selectionChange') 1050 1051off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void 1052 1053Disables listening for the text selection change event. This API uses an asynchronous callback to return the result. 1054 1055**System capability**: SystemCapability.MiscServices.InputMethodFramework 1056 1057**Parameters** 1058 1059| Name | Type | Mandatory| Description | 1060| -------- | ------- | ---- | ------- | 1061| type | string | Yes | Listening type. The value is fixed at **'selectionChange'**.| 1062| callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 1063 1064**Example** 1065 1066```ts 1067try { 1068 inputMethodEngine.getKeyboardDelegate() 1069 .off('selectionChange', (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => { 1070 console.log('delete selectionChange notification.'); 1071 }); 1072} catch(err) { 1073 console.error(`Failed to selectionChange: ${JSON.stringify(err)}`); 1074} 1075``` 1076 1077 1078### on('textChange') 1079 1080on(type: 'textChange', callback: (text: string) => void): void 1081 1082Enables listening for the text change event. This API uses an asynchronous callback to return the result. 1083 1084**System capability**: SystemCapability.MiscServices.InputMethodFramework 1085 1086**Parameters** 1087 1088| Name | Type | Mandatory| Description | 1089| -------- | ------ | ---- | ------------------------------------------------------------ | 1090| type | string | Yes | Listening type. The value is fixed at **'textChange'**.| 1091| callback | (text: string) => void | Yes | Callback used to return the text content.| 1092 1093**Example** 1094 1095```ts 1096try { 1097 inputMethodEngine.getKeyboardDelegate().on('textChange', (text: string) => { 1098 console.log('inputMethodEngine textChange. text:' + text); 1099 }); 1100} catch(err) { 1101 console.error(`Failed to textChange: ${JSON.stringify(err)}`); 1102} 1103``` 1104 1105### off('textChange') 1106 1107off(type: 'textChange', callback?: (text: string) => void): void 1108 1109Disables listening for the text change event. This API uses an asynchronous callback to return the result. 1110 1111**System capability**: SystemCapability.MiscServices.InputMethodFramework 1112 1113**Parameters** 1114 1115| Name | Type | Mandatory| Description | 1116| -------- | ------ | ---- | ------------------------------------------------------------ | 1117| type | string | Yes | Listening type. The value is fixed at **'textChange'**.| 1118| callback | (text: string) => void | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 1119 1120**Example** 1121 1122```ts 1123try { 1124 inputMethodEngine.getKeyboardDelegate().off('textChange', (text: string) => { 1125 console.log('delete textChange notification. text:' + text); 1126 }); 1127} catch(err) { 1128 console.error(`Failed to textChange: ${JSON.stringify(err)}`); 1129} 1130``` 1131 1132### on('editorAttributeChanged')<sup>10+</sup> 1133 1134on(type: 'editorAttributeChanged', callback: (attr: EditorAttribute) => void): void 1135 1136Enables listening for the edit box attribute change event. This API uses an asynchronous callback to return the result. 1137 1138**System capability**: SystemCapability.MiscServices.InputMethodFramework 1139 1140**Parameters** 1141 1142| Name | Type | Mandatory| Description | 1143| -------- | ------ | ---- | ------------------------------------------------------------ | 1144| type | string | Yes | Listening type. The value is fixed at **'editorAttributeChanged'**.| 1145| callback | (attr: EditorAttribute) => void | Yes | Callback used to return the changed edit box attribute.| 1146 1147**Example** 1148 1149```ts 1150try { 1151 inputMethodEngine.getKeyboardDelegate().on('editorAttributeChanged', (attr: inputMethodEngine.EditorAttribute) => { 1152 console.log(`Succeeded in receiving attribute of editor, inputPattern = ${attr.inputPattern}, enterKeyType = ${attr.enterKeyType}`); 1153 }); 1154} catch(err) { 1155 console.error(`Failed to textChange: ${JSON.stringify(err)}`); 1156} 1157``` 1158 1159### off('editorAttributeChanged')<sup>10+</sup> 1160 1161off(type: 'editorAttributeChanged', callback?: (attr: EditorAttribute) => void): void 1162 1163Disables listening for the edit box attribute change event. This API uses an asynchronous callback to return the result. 1164 1165**System capability**: SystemCapability.MiscServices.InputMethodFramework 1166 1167**Parameters** 1168 1169| Name | Type | Mandatory| Description | 1170| -------- | ------ | ---- | ------------------------------------------------------------ | 1171| type | string | Yes | Listening type. The value is fixed at **'editorAttributeChanged'**.| 1172| callback | (attr: EditorAttribute) => void | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 1173 1174**Example** 1175 1176```ts 1177inputMethodEngine.getKeyboardDelegate().off('editorAttributeChanged'); 1178``` 1179 1180## Panel<sup>10+</sup> 1181 1182In the following API examples, you must first use [createPanel](#createpanel10) to obtain a **Panel** instance, and then call the APIs using the obtained instance. 1183 1184### setUiContent<sup>10+</sup> 1185 1186setUiContent(path: string, callback: AsyncCallback\<void>): void 1187 1188Loads content from a page to this input method panel. This API uses an asynchronous callback to return the result. 1189 1190**System capability**: SystemCapability.MiscServices.InputMethodFramework 1191 1192**Parameters** 1193 1194| Name | Type | Mandatory| Description | 1195| -------- | ---------------------- | ---- | -------- | 1196| path | string | Yes | Path of the page from which the content will be loaded.| 1197| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1198 1199**Example** 1200 1201```ts 1202import { BusinessError } from '@ohos.base'; 1203 1204try { 1205 panel.setUiContent('pages/page2/page2', (err: BusinessError) => { 1206 if (err) { 1207 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1208 return; 1209 } 1210 console.log('Succeeded in setting the content.'); 1211 }); 1212} catch (err) { 1213 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1214} 1215``` 1216 1217### setUiContent<sup>10+</sup> 1218 1219setUiContent(path: string): Promise\<void> 1220 1221Loads content from a page to this input method panel. This API uses a promise to return the result. 1222 1223**System capability**: SystemCapability.MiscServices.InputMethodFramework 1224 1225**Parameters** 1226 1227| Name | Type | Mandatory| Description | 1228| -------- | ---------------------- | ---- | -------- | 1229| path | string | Yes | Path of the page from which the content will be loaded.| 1230 1231**Return value** 1232 1233| Type | Description | 1234| ------- | ------------------------------ | 1235| Promise\<void> | Promise that returns no value. | 1236 1237**Example** 1238 1239```ts 1240import { BusinessError } from '@ohos.base'; 1241 1242try { 1243 panel.setUiContent('pages/page2/page2').then(() => { 1244 console.log('Succeeded in setting the content.'); 1245 }).catch((err: BusinessError) => { 1246 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1247 }); 1248} catch (err) { 1249 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1250} 1251``` 1252 1253### setUiContent<sup>10+</sup> 1254 1255setUiContent(path: string, storage: LocalStorage, callback: AsyncCallback\<void>): void 1256 1257Loads content from a page linked to LocalStorage to this input method panel. This API uses an asynchronous callback to return the result. 1258 1259**System capability**: SystemCapability.MiscServices.InputMethodFramework 1260 1261**Parameters** 1262 1263| Name | Type | Mandatory| Description | 1264| -------- | ---------------------- | ---- | -------- | 1265| path | string | Yes | Path of the page linked to LocalStorage.| 1266| storage | [LocalStorage](../arkui-ts/ts-state-management.md#localstorage9) | Yes | Storage unit that provides storage for mutable and immutable state variables in the application.| 1267| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1268 1269**Example** 1270 1271```ts 1272import { BusinessError } from '@ohos.base'; 1273 1274let storage = new LocalStorage(); 1275storage.setOrCreate('storageSimpleProp',121); 1276try { 1277 panel.setUiContent('pages/page2/page2', storage, (err: BusinessError) => { 1278 if (err) { 1279 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1280 return; 1281 } 1282 console.log('Succeeded in setting the content.'); 1283 }); 1284} catch (err) { 1285 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1286} 1287``` 1288 1289### setUiContent<sup>10+</sup> 1290 1291setUiContent(path: string, storage: LocalStorage): Promise\<void> 1292 1293Loads content from a page linked to LocalStorage to this panel. This API uses a promise to return the result. 1294 1295**System capability**: SystemCapability.MiscServices.InputMethodFramework 1296 1297**Parameters** 1298 1299| Name | Type | Mandatory| Description | 1300| -------- | ---------------------- | ---- | -------- | 1301| path | string | Yes | Path of the page from which the content will be loaded.| 1302| storage | [LocalStorage](../arkui-ts/ts-state-management.md#localstorage9) | Yes | Storage unit that provides storage for mutable and immutable state variables in the application.| 1303 1304**Return value** 1305 1306| Type | Description | 1307| ------- | ------------------------------ | 1308| Promise\<void> | Promise that returns no value. | 1309 1310**Example** 1311 1312```ts 1313import { BusinessError } from '@ohos.base'; 1314 1315let storage = new LocalStorage(); 1316storage.setOrCreate('storageSimpleProp',121); 1317try { 1318 panel.setUiContent('pages/page2/page2')then(() => { 1319 console.log('Succeeded in setting the content.'); 1320 }).catch((err: BusinessError) => { 1321 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1322 }); 1323} catch (err) { 1324 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1325} 1326``` 1327 1328### resize<sup>10+</sup> 1329 1330resize(width: number, height: number, callback: AsyncCallback\<void>): void 1331 1332Resizes this input method panel. This API uses an asynchronous callback to return the result. 1333 1334> **NOTE** 1335> 1336> The panel width cannot exceed the screen width, and the panel height cannot be 0.6 times higher than the screen height. 1337 1338**System capability**: SystemCapability.MiscServices.InputMethodFramework 1339 1340**Parameters** 1341 1342| Name | Type | Mandatory| Description | 1343| -------- | ---------------------- | ---- | -------- | 1344| width | number | Yes | Target width of the panel, in px.| 1345| height | number | Yes | Target height of the panel, in px.| 1346| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1347 1348**Example** 1349 1350```ts 1351import { BusinessError } from '@ohos.base'; 1352 1353try { 1354 panel.resize(500, 1000, (err: BusinessError) => { 1355 if (err) { 1356 console.error(`Failed to resize panel: ${JSON.stringify(err)}`); 1357 return; 1358 } 1359 console.log('Succeeded in changing the panel size.'); 1360 }); 1361} catch (err) { 1362 console.error(`Failed to resize panel: ${JSON.stringify(err)}`); 1363} 1364``` 1365 1366### resize<sup>10+</sup> 1367 1368resize(width: number, height: number): Promise\<void> 1369 1370Resizes this input method panel. This API uses a promise to return the result. 1371 1372> **NOTE** 1373> 1374> The panel width cannot exceed the screen width, and the panel height cannot be 0.6 times higher than the screen height. 1375 1376**System capability**: SystemCapability.MiscServices.InputMethodFramework 1377 1378**Parameters** 1379 1380| Name | Type | Mandatory| Description | 1381| -------- | ---------------------- | ---- | -------- | 1382| width | number | Yes | Target width of the panel, in px.| 1383| height | number | Yes | Target height of the panel, in px.| 1384 1385**Return value** 1386 1387| Type | Description | 1388| ------- | ------------------------------ | 1389| Promise\<void> | Promise that returns no value. | 1390 1391**Example** 1392 1393```ts 1394import { BusinessError } from '@ohos.base'; 1395 1396try { 1397 panel.resize(500, 1000).then(() => { 1398 console.log('Succeeded in changing the panel size.'); 1399 }).catch((err: BusinessError) => { 1400 console.error(`Failed to resize panel: ${JSON.stringify(err)}`); 1401 }); 1402} catch (err) { 1403 console.error(`Failed to resize panel: ${JSON.stringify(err)}`); 1404} 1405``` 1406 1407### moveTo<sup>10+</sup> 1408 1409moveTo(x: number, y: number, callback: AsyncCallback\<void>): void 1410 1411Moves this input method panel to the specified position. This API uses an asynchronous callback to return the result. This API does not work on panels in the [FLG_FIXED](#panelflag10) state. 1412 1413**System capability**: SystemCapability.MiscServices.InputMethodFramework 1414 1415**Parameters** 1416 1417| Name | Type | Mandatory| Description | 1418| -------- | ---------------------- | ---- | -------- | 1419| x | number | Yes | Distance to move along the x-axis, in px. A positive value indicates moving rightwards.| 1420| y | number | Yes | Distance to move along the y-axis, in px. A positive value indicates moving downwards.| 1421| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1422 1423**Example** 1424 1425```ts 1426import { BusinessError } from '@ohos.base'; 1427 1428try { 1429 panel.moveTo(300, 300, (err: BusinessError) =>{ 1430 if (err) { 1431 console.error(`Failed to move panel: ${JSON.stringify(err)}`); 1432 return; 1433 } 1434 console.log('Succeeded in moving the panel.'); 1435 }); 1436} catch (err) { 1437 console.error(`Failed to move panel: ${JSON.stringify(err)}`); 1438} 1439``` 1440 1441### moveTo<sup>10+</sup> 1442 1443moveTo(x: number, y: number): Promise\<void> 1444 1445Moves this input method panel to the specified position. This API uses a promise to return the result. This API does not work on panels in the [FLG_FIXED](#panelflag10) state. 1446 1447**System capability**: SystemCapability.MiscServices.InputMethodFramework 1448 1449**Parameters** 1450 1451| Name | Type | Mandatory| Description | 1452| -------- | ---------------------- | ---- | -------- | 1453| x | number | Yes |Distance to move along the x-axis, in px. A positive value indicates moving rightwards.| 1454| y | number | Yes |Distance to move along the y-axis, in px. A positive value indicates moving downwards.| 1455 1456**Return value** 1457 1458| Type | Description | 1459| ------- | ------------------------------ | 1460| Promise\<void> | Promise that returns no value. | 1461 1462**Example** 1463 1464```ts 1465import { BusinessError } from '@ohos.base'; 1466 1467try { 1468 panel.moveTo(300, 300).then(() => { 1469 console.log('Succeeded in moving the panel.'); 1470 }).catch((err: BusinessError) => { 1471 console.error(`Failed to move panel: ${JSON.stringify(err)}`); 1472 }); 1473} catch (err) { 1474 console.error(`Failed to move panel: ${JSON.stringify(err)}`); 1475} 1476``` 1477 1478### show<sup>10+</sup> 1479 1480show(callback: AsyncCallback\<void>): void 1481 1482Shows this input method panel. This API uses an asynchronous callback to return the result. It can be called when the input method is bound to the edit box. 1483 1484**System capability**: SystemCapability.MiscServices.InputMethodFramework 1485 1486**Parameters** 1487 1488| Name | Type | Mandatory| Description | 1489| -------- | ---------------------- | ---- | -------- | 1490| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1491 1492**Example** 1493 1494```ts 1495import { BusinessError } from '@ohos.base'; 1496 1497panel.show((err: BusinessError) => { 1498 if (err) { 1499 console.error(`Failed to show panel: ${JSON.stringify(err)}`); 1500 return; 1501 } 1502 console.log('Succeeded in showing the panel.'); 1503}); 1504``` 1505 1506### show<sup>10+</sup> 1507 1508show(): Promise\<void> 1509 1510Shows this input method panel. This API uses a promise to return the result. It can be called when the input method is bound to the edit box. 1511 1512**System capability**: SystemCapability.MiscServices.InputMethodFramework 1513 1514**Return value** 1515 1516| Type | Description | 1517| ------- | ------------------------------ | 1518| Promise\<void> | Promise that returns no value. | 1519 1520**Example** 1521 1522```ts 1523import { BusinessError } from '@ohos.base'; 1524 1525panel.show().then(() => { 1526 console.log('Succeeded in showing the panel.'); 1527}).catch((err: BusinessError) => { 1528 console.error(`Failed to show panel: ${JSON.stringify(err)}`); 1529}); 1530``` 1531 1532### hide<sup>10+</sup> 1533 1534hide(callback: AsyncCallback\<void>): void 1535 1536Hides this panel. This API uses an asynchronous callback to return the result. 1537 1538**System capability**: SystemCapability.MiscServices.InputMethodFramework 1539 1540**Parameters** 1541 1542| Name | Type | Mandatory| Description | 1543| -------- | ---------------------- | ---- | -------- | 1544| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1545 1546**Example** 1547 1548```ts 1549import { BusinessError } from '@ohos.base'; 1550 1551panel.hide((err: BusinessError) => { 1552 if (err) { 1553 console.error(`Failed to hide panel: ${JSON.stringify(err)}`); 1554 return; 1555 } 1556 console.log('Succeeded in hiding the panel.'); 1557}); 1558``` 1559 1560### hide<sup>10+</sup> 1561 1562hide(): Promise\<void> 1563 1564Hides this panel. This API uses a promise to return the result. 1565 1566**System capability**: SystemCapability.MiscServices.InputMethodFramework 1567 1568**Return value** 1569 1570| Type | Description | 1571| ------- | ------------------------------ | 1572| Promise\<void> | Promise that returns no value. | 1573 1574**Example** 1575 1576```ts 1577import { BusinessError } from '@ohos.base'; 1578 1579panel.hide().then(() => { 1580 console.log('Succeeded in hiding the panel.'); 1581}).catch((err: BusinessError) => { 1582 console.error(`Failed to hide panel: ${JSON.stringify(err)}`); 1583}); 1584``` 1585 1586### on('show')<sup>10+</sup> 1587 1588on(type: 'show', callback: () => void): void 1589 1590Enables listening for the show event of this panel. This API uses an asynchronous callback to return the result. 1591 1592**System capability**: SystemCapability.MiscServices.InputMethodFramework 1593 1594**Parameters** 1595 1596| Name | Type | Mandatory| Description | 1597| -------- | ---------------------- | ---- | -------- | 1598| type | string | Yes| Listening type. The value is fixed at **'show'**.| 1599| callback | () => void | Yes | Callback used to return the result.| 1600 1601**Example** 1602 1603```ts 1604try { 1605 panel.on('show', () => { 1606 console.log('Panel is showing.'); 1607 }); 1608} catch(err) { 1609 console.error(`Failed to show: ${JSON.stringify(err)}`); 1610} 1611``` 1612 1613### on('hide')<sup>10+</sup> 1614 1615on(type: 'hide', callback: () => void): void 1616 1617Enables listening for the hide event of this panel. This API uses an asynchronous callback to return the result. 1618 1619**System capability**: SystemCapability.MiscServices.InputMethodFramework 1620 1621**Parameters** 1622 1623| Name | Type | Mandatory| Description | 1624| -------- | ---------------------- | ---- | -------- | 1625| type | string | Yes| Listening type. The value is fixed at **'hide'**.| 1626| callback | () => void | Yes | Callback used to return the result.| 1627 1628**Example** 1629 1630```ts 1631try { 1632 panel.on('hide', () => { 1633 console.log('Panel is hiding.'); 1634 }); 1635} catch(err) { 1636 console.error(`Failed to hide: ${JSON.stringify(err)}`); 1637} 1638``` 1639 1640### off('show')<sup>10+</sup> 1641 1642off(type: 'show', callback?: () => void): void 1643 1644Disables listening for the show event of this panel. This API uses an asynchronous callback to return the result. 1645 1646**System capability**: SystemCapability.MiscServices.InputMethodFramework 1647 1648**Parameters** 1649 1650| Name | Type | Mandatory| Description | 1651| -------- | ---------------------- | ---- | -------- | 1652| type | string | Yes| Listening type. The value is fixed at **'show'**.| 1653| callback | () => void | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 1654 1655**Example** 1656 1657```ts 1658try { 1659 panel.off('show'); 1660} catch(err) { 1661 console.error(`Failed to show: ${JSON.stringify(err)}`); 1662} 1663``` 1664 1665### off('hide')<sup>10+</sup> 1666 1667off(type: 'hide', callback?: () => void): void 1668 1669Disables listening for the hide event of this panel. This API uses an asynchronous callback to return the result. 1670 1671**System capability**: SystemCapability.MiscServices.InputMethodFramework 1672 1673**Parameters** 1674 1675| Name | Type | Mandatory| Description | 1676| -------- | ---------------------- | ---- | -------- | 1677| type | string | Yes| Listening type. The value is fixed at **'hide'**.| 1678| callback | () => void | No | Callback for which listening is disabled. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 1679 1680**Example** 1681 1682```ts 1683try { 1684 panel.off('hide'); 1685} catch(err) { 1686 console.error(`Failed to hide: ${JSON.stringify(err)}`); 1687} 1688``` 1689 1690### changeFlag<sup>10+</sup> 1691 1692changeFlag(flag: PanelFlag): void 1693 1694Changes the state type of this input method panel. This API only works for [SOFT_KEYBOARD](#paneltype10) panels. 1695 1696**System capability**: SystemCapability.MiscServices.InputMethodFramework 1697 1698**Parameters** 1699 1700| Name | Type | Mandatory| Description | 1701| -------- | ---------------------- | ---- | -------- | 1702| flag | [PanelFlag](#panelflag10) | Yes| Target state type of the panel.| 1703 1704**Example** 1705 1706```ts 1707try { 1708 let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED; 1709 panel.changeFlag(panelFlag); 1710} catch(err) { 1711 console.error(`Failed to panelFlag: ${JSON.stringify(err)}`); 1712} 1713``` 1714 1715### setPrivacyMode<sup>11+</sup> 1716 1717setPrivacyMode(isPrivacyMode: boolean): void 1718 1719Sets the input method panel to privacy mode. In privacy mode, screenshot and screen recording are blocked. 1720 1721**Required permissions**: ohos.permission.PRIVACY_WINDOW 1722 1723**System capability**: SystemCapability.MiscServices.InputMethodFramework 1724 1725**Parameters** 1726 1727| Name | Type | Mandatory| Description | 1728| ------------- | ------- | ---- | ------------------ | 1729| isPrivacyMode | boolean | Yes | Whether to set the input method panel to privacy mode.| 1730 1731**Example** 1732 1733```ts 1734try { 1735 boolean isPrivacyMode = true; 1736 panel.setPrivacyMode(isPrivacyMode); 1737} catch(err) { 1738 console.error(`Failed to set privacy mode: ${JSON.stringify(err)}`); 1739} 1740``` 1741 1742## KeyboardController 1743 1744In the following API examples, you must first use [on('inputStart')](#oninputstart9) to obtain a **KeyboardController** instance, and then call the APIs using the obtained instance. 1745 1746### hide<sup>9+</sup> 1747 1748hide(callback: AsyncCallback<void>): void 1749 1750Hides the keyboard. This API uses an asynchronous callback to return the result. 1751 1752**System capability**: SystemCapability.MiscServices.InputMethodFramework 1753 1754**Parameters** 1755 1756| Name | Type | Mandatory| Description | 1757| -------- | ---------------------- | ---- | -------- | 1758| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1759 1760**Error codes** 1761 1762For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 1763 1764| ID| Error Message | 1765| -------- | -------------------------- | 1766| 12800003 | input method client error. | 1767 1768**Example** 1769 1770```ts 1771import { BusinessError } from '@ohos.base'; 1772 1773keyboardController.hide((err: BusinessError) => { 1774 if (err) { 1775 console.error(`Failed to hide: ${JSON.stringify(err)}`); 1776 return; 1777 } 1778 console.log('Succeeded in hiding keyboard.'); 1779}); 1780``` 1781 1782### hide<sup>9+</sup> 1783 1784hide(): Promise<void> 1785 1786Hides the keyboard. This API uses a promise to return the result. 1787 1788**System capability**: SystemCapability.MiscServices.InputMethodFramework 1789 1790**Return value** 1791 1792| Type | Description | 1793| ---------------- | ------------------------- | 1794| Promise<void> | Promise that returns no value.| 1795 1796**Error codes** 1797 1798For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 1799 1800| ID| Error Message | 1801| -------- | -------------------------- | 1802| 12800003 | input method client error. | 1803 1804**Example** 1805 1806```ts 1807import { BusinessError } from '@ohos.base'; 1808 1809keyboardController.hide().then(() => { 1810 console.log('Succeeded in hiding keyboard.'); 1811}).catch((err: BusinessError) => { 1812 console.log(`Failed to hide: ${JSON.stringify(err)}`); 1813}); 1814``` 1815 1816### hideKeyboard<sup>(deprecated)</sup> 1817 1818hideKeyboard(callback: AsyncCallback<void>): void 1819 1820Hides the keyboard. This API uses an asynchronous callback to return the result. 1821 1822> **NOTE** 1823> 1824> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9) instead. 1825 1826**System capability**: SystemCapability.MiscServices.InputMethodFramework 1827 1828**Parameters** 1829 1830| Name | Type | Mandatory| Description | 1831| -------- | ---------------------- | ---- | -------- | 1832| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1833 1834**Example** 1835 1836```ts 1837import { BusinessError } from '@ohos.base'; 1838 1839keyboardController.hideKeyboard((err: BusinessError) => { 1840 if (err) { 1841 console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`); 1842 return; 1843 } 1844 console.log('Succeeded in hiding keyboard.'); 1845}); 1846``` 1847 1848### hideKeyboard<sup>(deprecated)</sup> 1849 1850hideKeyboard(): Promise<void> 1851 1852Hides the keyboard. This API uses a promise to return the result. 1853 1854> **NOTE** 1855> 1856> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9-1) instead. 1857 1858**System capability**: SystemCapability.MiscServices.InputMethodFramework 1859 1860**Return value** 1861 1862| Type | Description | 1863| ---------------- | ------------------------- | 1864| Promise<void> | Promise that returns no value.| 1865 1866**Example** 1867 1868```ts 1869import { BusinessError } from '@ohos.base'; 1870 1871keyboardController.hideKeyboard().then(() => { 1872 console.log('Succeeded in hiding keyboard.'); 1873}).catch((err: BusinessError) => { 1874 console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`); 1875}); 1876``` 1877 1878### exitCurrentInputType<sup>11+</sup> 1879 1880exitCurrentInputType(callback: AsyncCallback<void>): void 1881 1882Exits this input type. This API can be called only by the preconfigured default input method. This API uses an asynchronous callback to return the result. 1883 1884**System capability**: SystemCapability.MiscServices.InputMethodFramework 1885 1886**Parameters** 1887 1888| Name | Type | Mandatory| Description | 1889| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 1890| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1891 1892**Error codes** 1893 1894For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 1895 1896| ID| Error Message | 1897| -------- | ---------------------------------------------- | 1898| 12800008 | input method manager service error. | 1899| 12800010 | not default input method configured by system. | 1900 1901**Example** 1902 1903```ts 1904import { BusinessError } from '@ohos.base'; 1905 1906keyboardController.exitCurrentInputType((err: BusinessError) => { 1907 if (err) { 1908 console.error(`Failed to exitCurrentInputType: ${JSON.stringify(err)}`); 1909 return; 1910 } 1911 console.log('Succeeded in exiting current input type.'); 1912}); 1913``` 1914 1915### exitCurrentInputType<sup>11+</sup> 1916 1917exitCurrentInputType(): Promise<void> 1918 1919Exits this input type. This API can be called only by the preconfigured default input method. This API uses a promise to return the result. 1920 1921**System capability**: SystemCapability.MiscServices.InputMethodFramework 1922 1923**Return value** 1924 1925| Type | Description | 1926| ---------------- | ------------------------- | 1927| Promise<void> | Promise that returns no value.| 1928 1929**Error codes** 1930 1931For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 1932 1933| ID| Error Message | 1934| -------- | ---------------------------------------------- | 1935| 12800008 | input method manager service error. | 1936| 12800010 | not default input method configured by system. | 1937 1938**Example** 1939 1940```ts 1941import { BusinessError } from '@ohos.base'; 1942 1943keyboardController.exitCurrentInputType().then(() => { 1944 console.log('Succeeded in exiting current input type.'); 1945}).catch((err: BusinessError) => { 1946 console.log(`Failed to exit current input type: ${JSON.stringify(err)}`); 1947}); 1948``` 1949 1950## SecurityMode<sup>11+</sup> 1951 1952Describes the security mode. 1953 1954**System capability**: SystemCapability.MiscServices.InputMethodFramework 1955 1956| Name | Value | Description | 1957| ----- | ---- | -------------------------------------------- | 1958| BASIC | 0 | Basic access mode, where network access is restricted.| 1959| FULL | 1 | Full access mode, where network access is not restricted. | 1960 1961## ExtendAction<sup>10+</sup> 1962 1963Describes the type of the extended edit action on the text box. 1964 1965**System capability**: SystemCapability.MiscServices.InputMethodFramework 1966 1967| Name| Value|Description| 1968| -------- | -------- |-------- | 1969| SELECT_ALL | 0 |Select all.| 1970| CUT | 3 |Cut.| 1971| COPY | 4 |Copy.| 1972| PASTE | 5 |Paste.| 1973 1974## Direction<sup>10+</sup> 1975 1976Enumerates the directions of cursor movement of the input method. 1977 1978**System capability**: SystemCapability.MiscServices.InputMethodFramework 1979 1980| Name| Value|Description| 1981| -------- | -------- |-------- | 1982| CURSOR_UP | 1 |Upward.| 1983| CURSOR_DOWN | 2 |Downward.| 1984| CURSOR_LEFT | 3 |Leftward.| 1985| CURSOR_RIGHT | 4 |Rightward.| 1986 1987## Range<sup>10+</sup> 1988 1989Describes the range of the selected text. 1990 1991**System capability**: SystemCapability.MiscServices.InputMethodFramework 1992 1993| Name| Type| Readable| Writable| Description| 1994| -------- | -------- | -------- | -------- | -------- | 1995| start | number | Yes| Yes| Index of the first selected character in the text box.| 1996| end | number | Yes| Yes| Index of the last selected character in the text box.| 1997 1998## Movement<sup>10+</sup> 1999 2000Describes the direction in which the cursor moves when the text is selected. 2001 2002**System capability**: SystemCapability.MiscServices.InputMethodFramework 2003 2004| Name| Type| Readable| Writable| Description| 2005| -------- | -------- | -------- | -------- | -------- | 2006| direction | [Direction](#direction10) | Yes| Yes| Direction in which the cursor moves when the text is selected.| 2007 2008## InputClient<sup>9+</sup> 2009 2010In the following API examples, you must first use [on('inputStart')](#oninputstart9) to obtain an **InputClient** instance, and then call the APIs using the obtained instance. 2011 2012### sendKeyFunction<sup>9+</sup> 2013 2014sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void 2015 2016Sends the function key. This API uses an asynchronous callback to return the result. 2017 2018**System capability**: SystemCapability.MiscServices.InputMethodFramework 2019 2020 **Parameters** 2021 2022| Name| Type| Mandatory| Description| 2023| -------- | -------- | -------- | -------- | 2024| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).| 2025| 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.| 2026 2027**Error codes** 2028 2029For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2030 2031| ID| Error Message | 2032| -------- | -------------------------- | 2033| 12800003 | input method client error. | 2034 2035 **Example** 2036 2037```ts 2038import { BusinessError } from '@ohos.base'; 2039 2040let action = 1; 2041try { 2042 inputClient.sendKeyFunction(action, (err: BusinessError, result: boolean) => { 2043 if (err) { 2044 console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); 2045 return; 2046 } 2047 if (result) { 2048 console.log('Succeeded in sending key function.'); 2049 } else { 2050 console.error('Failed to sendKeyFunction.'); 2051 } 2052 }); 2053} catch (err) { 2054 console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); 2055} 2056``` 2057 2058### sendKeyFunction<sup>9+</sup> 2059 2060sendKeyFunction(action: number): Promise<boolean> 2061 2062Sends the function key. This API uses a promise to return the result. 2063 2064**System capability**: SystemCapability.MiscServices.InputMethodFramework 2065 2066**Parameters** 2067 2068| Name| Type| Mandatory| Description| 2069| -------- | -------- | -------- | -------- | 2070| action | number | Yes| Action of the function key.<br>**0**: invalid key.<br>**1**: confirm key (Enter key).| 2071 2072**Return value** 2073 2074| Type | Description | 2075| ------------------------------- | ------------------------------------------------------------ | 2076| Promise<boolean> | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.| 2077 2078**Error codes** 2079 2080For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2081 2082| ID| Error Message | 2083| -------- | -------------------------- | 2084| 12800003 | input method client error. | 2085 2086**Example** 2087 2088```ts 2089import { BusinessError } from '@ohos.base'; 2090 2091let action = 1; 2092try { 2093 inputClient.sendKeyFunction(action).then((result: boolean) => { 2094 if (result) { 2095 console.log('Succeeded in sending key function.'); 2096 } else { 2097 console.error('Failed to sendKeyFunction.'); 2098 } 2099 }).catch((err: BusinessError) => { 2100 console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); 2101 }); 2102} catch (err) { 2103 console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); 2104} 2105``` 2106 2107### getForward<sup>9+</sup> 2108 2109getForward(length:number, callback: AsyncCallback<string>): void 2110 2111Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result. 2112 2113**System capability**: SystemCapability.MiscServices.InputMethodFramework 2114 2115**Parameters** 2116 2117| Name| Type| Mandatory| Description| 2118| -------- | -------- | -------- | -------- | 2119| length | number | Yes| Text length.| 2120| callback | AsyncCallback<string> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the obtained text. Otherwise, **err** is an error object.| 2121 2122**Error codes** 2123 2124For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2125 2126| ID| Error Message | 2127| -------- | ------------------------------ | 2128| 12800003 | input method client error. | 2129| 12800006 | Input method controller error. | 2130 2131**Example** 2132 2133```ts 2134import { BusinessError } from '@ohos.base'; 2135 2136let length = 1; 2137try { 2138 inputClient.getForward(length, (err: BusinessError, text: string) => { 2139 if (err) { 2140 console.error(`Failed to getForward: ${JSON.stringify(err)}`); 2141 return; 2142 } 2143 console.log('Succeeded in getting forward, text: ' + text); 2144 }); 2145} catch (err) { 2146 console.error(`Failed to getForward: ${JSON.stringify(err)}`); 2147} 2148``` 2149 2150### getForward<sup>9+</sup> 2151 2152getForward(length:number): Promise<string> 2153 2154Obtains the specific-length text before the cursor. This API uses a promise to return the result. 2155 2156**System capability**: SystemCapability.MiscServices.InputMethodFramework 2157 2158**Parameters** 2159 2160| Name| Type| Mandatory| Description| 2161| -------- | -------- | -------- | -------- | 2162| length | number | Yes| Text length.| 2163 2164**Return value** 2165 2166| Type | Description | 2167| ------------------------------- | ------------------------------------------------------------ | 2168| Promise<string> | Promise used to return the specific-length text before the cursor. | 2169 2170**Error codes** 2171 2172For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2173 2174| ID| Error Message | 2175| -------- | ------------------------------ | 2176| 12800003 | input method client error. | 2177| 12800006 | Input method controller error. | 2178 2179**Example** 2180 2181```ts 2182import { BusinessError } from '@ohos.base'; 2183 2184let length = 1; 2185try { 2186 inputClient.getForward(length).then((text: string) => { 2187 console.log('Succeeded in getting forward, text: ' + text); 2188 }).catch((err: BusinessError) => { 2189 console.error(`Failed to getForward: ${JSON.stringify(err)}`); 2190 }); 2191} catch (err) { 2192 console.error(`Failed to getForward: ${JSON.stringify(err)}`); 2193} 2194``` 2195 2196### getForwardSync<sup>10+</sup> 2197 2198getForwardSync(length:number): string 2199 2200Obtains the specific-length text before the cursor. 2201 2202**System capability**: SystemCapability.MiscServices.InputMethodFramework 2203 2204**Parameters** 2205 2206| Name| Type | Mandatory| Description | 2207| ------ | ------ | ---- | ---------- | 2208| length | number | Yes | Text length.| 2209 2210**Return value** 2211 2212| Type | Description | 2213| ------ | -------------------------- | 2214| string | Specific-length text before the cursor.| 2215 2216**Error codes** 2217 2218For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2219 2220| ID| Error Message | 2221| -------- | ------------------------------ | 2222| 12800003 | input method client error. | 2223| 12800006 | input method controller error. | 2224 2225**Example** 2226 2227```ts 2228let length = 1; 2229try { 2230 let text: string = inputClient.getForwardSync(length); 2231 console.log(`Succeeded in getting forward, text: ${text}`); 2232} catch (err) { 2233 console.error(`Failed to getForwardSync: ${JSON.stringify(err)}`); 2234} 2235``` 2236 2237### getBackward<sup>9+</sup> 2238 2239getBackward(length:number, callback: AsyncCallback<string>): void 2240 2241Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result. 2242 2243**System capability**: SystemCapability.MiscServices.InputMethodFramework 2244 2245**Parameters** 2246 2247| Name| Type| Mandatory| Description| 2248| -------- | -------- | -------- | -------- | 2249| length | number | Yes| Text length.| 2250| callback | AsyncCallback<string> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the obtained text. Otherwise, **err** is an error object.| 2251 2252**Error codes** 2253 2254For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2255 2256| ID| Error Message | 2257| -------- | ------------------------------ | 2258| 12800003 | input method client error. | 2259| 12800006 | Input method controller error. | 2260 2261**Example** 2262 2263```ts 2264import { BusinessError } from '@ohos.base'; 2265 2266let length = 1; 2267try { 2268 inputClient.getBackward(length, (err: BusinessError, text: string) => { 2269 if (err) { 2270 console.error(`Failed to getBackward: ${JSON.stringify(err)}`); 2271 return; 2272 } 2273 console.log('Succeeded in getting backward, text: ' + text); 2274 }); 2275} catch (err) { 2276 console.error(`Failed to getBackward: ${JSON.stringify(err)}`); 2277} 2278``` 2279 2280### getBackward<sup>9+</sup> 2281 2282getBackward(length:number): Promise<string> 2283 2284Obtains the specific-length text after the cursor. This API uses a promise to return the result. 2285 2286**System capability**: SystemCapability.MiscServices.InputMethodFramework 2287 2288**Parameters** 2289 2290| Name| Type| Mandatory| Description| 2291| -------- | -------- | -------- | -------- | 2292| length | number | Yes| Text length.| 2293 2294**Return value** 2295 2296| Type | Description | 2297| ------------------------------- | ------------------------------------------------------------ | 2298| Promise<string> | Promise used to return the specific-length text after the cursor. | 2299 2300**Error codes** 2301 2302For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2303 2304| ID| Error Message | 2305| -------- | ------------------------------ | 2306| 12800003 | input method client error. | 2307| 12800006 | Input method controller error. | 2308 2309**Example** 2310 2311```ts 2312import { BusinessError } from '@ohos.base'; 2313 2314let length = 1; 2315try { 2316 inputClient.getBackward(length).then((text: string) => { 2317 console.log('Succeeded in getting backward, text: ' + text); 2318 }).catch((err: BusinessError) => { 2319 console.error(`Failed to getBackward: ${JSON.stringify(err)}`); 2320 }); 2321} catch (err) { 2322 console.error(`Failed to getBackward: ${JSON.stringify(err)}`); 2323} 2324``` 2325 2326### getBackwardSync<sup>10+</sup> 2327 2328getBackwardSync(length:number): string 2329 2330Obtains the specific-length text after the cursor. 2331 2332**System capability**: SystemCapability.MiscServices.InputMethodFramework 2333 2334**Parameters** 2335 2336| Name| Type | Mandatory| Description | 2337| ------ | ------ | ---- | ---------- | 2338| length | number | Yes | Text length.| 2339 2340**Return value** 2341 2342| Type | Description | 2343| ------ | -------------------------- | 2344| string | Specific-length text after the cursor.| 2345 2346**Error codes** 2347 2348For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2349 2350| ID| Error Message | 2351| -------- | ------------------------------ | 2352| 12800003 | input method client error. | 2353| 12800006 | input method controller error. | 2354 2355**Example** 2356 2357```ts 2358let length = 1; 2359try { 2360 let text: string = inputClient.getBackwardSync(length); 2361 console.log(`Succeeded in getting backward, text: ${text}`); 2362} catch (err) { 2363 console.error(`Failed to getBackwardSync: ${JSON.stringify(err)}`); 2364} 2365``` 2366 2367### deleteForward<sup>9+</sup> 2368 2369deleteForward(length:number, callback: AsyncCallback<boolean>): void 2370 2371Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result. 2372 2373**System capability**: SystemCapability.MiscServices.InputMethodFramework 2374 2375**Parameters** 2376 2377| Name| Type| Mandatory| Description| 2378| -------- | -------- | -------- | -------- | 2379| length | number | Yes| Text length.| 2380| 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.| 2381 2382**Error codes** 2383 2384For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2385 2386| ID| Error Message | 2387| -------- | -------------------------- | 2388| 12800002 | Input method engine error. | 2389| 12800003 | input method client error. | 2390 2391**Example** 2392 2393```ts 2394import { BusinessError } from '@ohos.base'; 2395 2396let length = 1; 2397try { 2398 inputClient.deleteForward(length, (err: BusinessError, result: boolean) => { 2399 if (err) { 2400 console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); 2401 return; 2402 } 2403 if (result) { 2404 console.log('Succeeded in deleting forward.'); 2405 } else { 2406 console.error(`Failed to deleteForward.`); 2407 } 2408 }); 2409} catch (err) { 2410 console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); 2411} 2412``` 2413 2414### deleteForward<sup>9+</sup> 2415 2416deleteForward(length:number): Promise<boolean> 2417 2418Deletes the fixed-length text before the cursor. This API uses a promise to return the result. 2419 2420**System capability**: SystemCapability.MiscServices.InputMethodFramework 2421 2422**Parameters** 2423 2424| Name| Type | Mandatory| Description | 2425| ------ | ------ | ---- | ---------- | 2426| length | number | Yes | Text length.| 2427 2428**Return value** 2429 2430| Type | Description | 2431| ---------------------- | -------------- | 2432| Promise<boolean> | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.| 2433 2434**Error codes** 2435 2436For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2437 2438| ID| Error Message | 2439| -------- | -------------------------- | 2440| 12800002 | Input method engine error. | 2441| 12800003 | input method client error. | 2442 2443**Example** 2444 2445```ts 2446import { BusinessError } from '@ohos.base'; 2447 2448let length = 1; 2449try { 2450 inputClient.deleteForward(length).then((result: boolean) => { 2451 if (result) { 2452 console.log('Succeeded in deleting forward.'); 2453 } else { 2454 console.error('Failed to delete Forward.'); 2455 } 2456 }).catch((err: BusinessError) => { 2457 console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); 2458 }); 2459} catch (err) { 2460 console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); 2461} 2462``` 2463 2464### deleteForwardSync<sup>10+</sup> 2465 2466deleteForwardSync(length:number): void 2467 2468Deletes the fixed-length text before the cursor. 2469 2470**System capability**: SystemCapability.MiscServices.InputMethodFramework 2471 2472**Parameters** 2473 2474| Name| Type | Mandatory| Description | 2475| ------ | ------ | ---- | ---------- | 2476| length | number | Yes | Text length.| 2477 2478**Error codes** 2479 2480For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2481 2482| ID| Error Message | 2483| -------- | -------------------------- | 2484| 12800002 | input method engine error. | 2485| 12800003 | input method client error. | 2486 2487**Example** 2488 2489```ts 2490let length = 1; 2491try { 2492 inputClient.deleteForwardSync(length); 2493 console.log('Succeeded in deleting forward.'); 2494} catch (err) { 2495 console.error('deleteForwardSync err: ' + JSON.stringify(err)); 2496} 2497``` 2498 2499### deleteBackward<sup>9+</sup> 2500 2501deleteBackward(length:number, callback: AsyncCallback<boolean>): void 2502 2503Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result. 2504 2505**System capability**: SystemCapability.MiscServices.InputMethodFramework 2506 2507**Parameters** 2508 2509| Name | Type | Mandatory| Description | 2510| -------- | ---------------------------- | ---- | -------------- | 2511| length | number | Yes | Text length. | 2512| 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.| 2513 2514**Error codes** 2515 2516For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2517 2518| ID| Error Message | 2519| -------- | -------------------------- | 2520| 12800002 | Input method engine error. | 2521| 12800003 | input method client error. | 2522 2523**Example** 2524 2525```ts 2526import { BusinessError } from '@ohos.base'; 2527 2528let length = 1; 2529try { 2530 inputClient.deleteBackward(length, (err: BusinessError, result: boolean) => { 2531 if (err) { 2532 console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); 2533 return; 2534 } 2535 if (result) { 2536 console.log('Succeeded in deleting backward.'); 2537 } else { 2538 console.error(`Failed to deleteBackward.`); 2539 } 2540 }); 2541} catch (err) { 2542 console.error('deleteBackward err: ' + JSON.stringify(err)); 2543} 2544``` 2545 2546### deleteBackward<sup>9+</sup> 2547 2548deleteBackward(length:number): Promise<boolean> 2549 2550Deletes the fixed-length text after the cursor. This API uses a promise to return the result. 2551 2552**System capability**: SystemCapability.MiscServices.InputMethodFramework 2553 2554**Parameters** 2555 2556| Name| Type| Mandatory| Description| 2557| -------- | -------- | -------- | -------- | 2558| length | number | Yes| Text length.| 2559 2560**Return value** 2561 2562| Type | Description | 2563| ------------------------------- | ------------------------------------------------------------ | 2564| Promise<boolean> | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.| 2565 2566**Error codes** 2567 2568For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2569 2570| ID| Error Message | 2571| -------- | -------------------------- | 2572| 12800002 | Input method engine error. | 2573| 12800003 | input method client error. | 2574 2575**Example** 2576 2577```ts 2578import { BusinessError } from '@ohos.base'; 2579 2580let length = 1; 2581inputClient.deleteBackward(length).then((result: boolean) => { 2582 if (result) { 2583 console.log('Succeeded in deleting backward.'); 2584 } else { 2585 console.error('Failed to deleteBackward.'); 2586 } 2587}).catch((err: BusinessError) => { 2588 console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); 2589}); 2590``` 2591 2592### deleteBackwardSync<sup>10+</sup> 2593 2594deleteBackwardSync(length:number): void 2595 2596Deletes the fixed-length text after the cursor. 2597 2598**System capability**: SystemCapability.MiscServices.InputMethodFramework 2599 2600**Parameters** 2601 2602| Name| Type | Mandatory| Description | 2603| ------ | ------ | ---- | ---------- | 2604| length | number | Yes | Text length.| 2605 2606**Error codes** 2607 2608For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2609 2610| ID| Error Message | 2611| -------- | -------------------------- | 2612| 12800002 | input method engine error. | 2613| 12800003 | input method client error. | 2614 2615**Example** 2616 2617```ts 2618let length = 1; 2619try { 2620 inputClient.deleteBackwardSync(length); 2621 console.log('Succeeded in deleting backward.'); 2622} catch (err) { 2623 console.error('deleteBackwardSync err: ' + JSON.stringify(err)); 2624} 2625``` 2626 2627### insertText<sup>9+</sup> 2628 2629insertText(text:string, callback: AsyncCallback<boolean>): void 2630 2631Inserts text. This API uses an asynchronous callback to return the result. 2632 2633**System capability**: SystemCapability.MiscServices.InputMethodFramework 2634 2635**Parameters** 2636 2637| Name| Type| Mandatory| Description| 2638| -------- | -------- | -------- | -------- | 2639| text | string | Yes| Text to insert.| 2640| 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.| 2641 2642**Error codes** 2643 2644For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2645 2646| ID| Error Message | 2647| -------- | -------------------------- | 2648| 12800002 | Input method engine error. | 2649| 12800003 | input method client error. | 2650 2651**Example** 2652 2653```ts 2654import { BusinessError } from '@ohos.base'; 2655 2656inputClient.insertText('test', (err: BusinessError, result: boolean) => { 2657 if (err) { 2658 console.error(`Failed to insertText: ${JSON.stringify(err)}`); 2659 return; 2660 } 2661 if (result) { 2662 console.log('Succeeded in inserting text.'); 2663 } else { 2664 console.error('Failed to insertText.'); 2665 } 2666}); 2667``` 2668 2669### insertText<sup>9+</sup> 2670 2671insertText(text:string): Promise<boolean> 2672 2673Inserts text. This API uses a promise to return the result. 2674 2675**System capability**: SystemCapability.MiscServices.InputMethodFramework 2676 2677**Parameters** 2678 2679| Name| Type| Mandatory| Description| 2680| -------- | -------- | -------- | -------- | 2681| text | string | Yes| Text to insert.| 2682 2683**Return value** 2684 2685| Type | Description | 2686| ------------------------------- | ------------------------------------------------------------ | 2687| Promise<boolean> | Promise used to return the result. The value **true** means that the insertion is successful, and **false** means the opposite. | 2688 2689**Error codes** 2690 2691For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2692 2693| ID| Error Message | 2694| -------- | -------------------------- | 2695| 12800002 | Input method engine error. | 2696| 12800003 | input method client error. | 2697 2698**Example** 2699 2700```ts 2701import { BusinessError } from '@ohos.base'; 2702 2703try { 2704 inputClient.insertText('test').then((result: boolean) => { 2705 if (result) { 2706 console.log('Succeeded in inserting text.'); 2707 } else { 2708 console.error('Failed to insertText.'); 2709 } 2710 }).catch((err: BusinessError) => { 2711 console.error(`Failed to insertText: ${JSON.stringify(err)}`); 2712 }); 2713} catch (err) { 2714 console.error(`Failed to insertText: ${JSON.stringify(err)}`); 2715} 2716``` 2717 2718### insertTextSync<sup>10+</sup> 2719 2720insertTextSync(text: string): void 2721 2722Inserts text. 2723 2724**System capability**: SystemCapability.MiscServices.InputMethodFramework 2725 2726**Parameters** 2727 2728| Name| Type | Mandatory| Description | 2729| ------ | ------ | ---- | ---------- | 2730| text | string | Yes | Text to insert.| 2731 2732**Error codes** 2733 2734For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2735 2736| ID| Error Message | 2737| -------- | -------------------------- | 2738| 12800002 | input method engine error. | 2739| 12800003 | input method client error. | 2740 2741**Example** 2742 2743```ts 2744try { 2745 inputClient.insertTextSync('test'); 2746 console.log('Succeeded in inserting text.'); 2747} catch (err) { 2748 console.error(`Failed to insertTextSync: ${JSON.stringify(err)}`); 2749} 2750``` 2751 2752### getEditorAttribute<sup>9+</sup> 2753 2754getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void 2755 2756Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result. 2757 2758**System capability**: SystemCapability.MiscServices.InputMethodFramework 2759 2760**Parameters** 2761 2762| Name | Type | Mandatory | Description | 2763| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | 2764| callback | AsyncCallback<[EditorAttribute](#editorattribute)> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the attribute of the edit box. Otherwise, **err** is an error object.| 2765 2766**Error codes** 2767 2768For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2769 2770| ID| Error Message | 2771| -------- | -------------------------- | 2772| 12800003 | input method client error. | 2773 2774**Example** 2775 2776```ts 2777import { BusinessError } from '@ohos.base'; 2778 2779inputClient.getEditorAttribute((err: BusinessError, editorAttribute: inputMethodEngine.EditorAttribute) => { 2780 if (err) { 2781 console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); 2782 return; 2783 } 2784 console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); 2785 console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); 2786}); 2787``` 2788 2789### getEditorAttribute<sup>9+</sup> 2790 2791getEditorAttribute(): Promise<EditorAttribute> 2792 2793Obtains the attribute of the edit box. This API uses a promise to return the result. 2794 2795**System capability**: SystemCapability.MiscServices.InputMethodFramework 2796 2797**Return value** 2798 2799| Type | Description | 2800| ------------------------------- | ------------------------------------------------------------ | 2801| Promise<[EditorAttribute](#editorattribute)> | Promise used to return the attribute of the edit box. | 2802 2803**Error codes** 2804 2805For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2806 2807| ID| Error Message | 2808| -------- | -------------------------- | 2809| 12800003 | input method client error. | 2810 2811**Example** 2812 2813```ts 2814import { BusinessError } from '@ohos.base'; 2815 2816try { 2817 inputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => { 2818 console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); 2819 console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); 2820 }).catch((err: BusinessError) => { 2821 console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); 2822 }); 2823} catch(err) { 2824 console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); 2825} 2826``` 2827 2828### getEditorAttributeSync<sup>10+</sup> 2829 2830getEditorAttributeSync(): EditorAttribute 2831 2832Obtains the attribute of the edit box. 2833 2834**System capability**: SystemCapability.MiscServices.InputMethodFramework 2835 2836**Return value** 2837 2838| Type | Description | 2839| ----------------------------------- | -------------- | 2840| [EditorAttribute](#editorattribute) | Attribute of the edit box.| 2841 2842**Error codes** 2843 2844For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2845 2846| ID| Error Message | 2847| -------- | -------------------------- | 2848| 12800003 | input method client error. | 2849 2850**Example** 2851 2852```ts 2853try { 2854 let editorAttribute: inputMethodEngine.EditorAttribute = inputClient.getEditorAttributeSync(); 2855 console.log(`Succeeded in getEditorAttributeSync, editorAttribute = ${JSON.stringify(editorAttribute)}`); 2856} catch (err) { 2857 console.error(`Failed to getEditorAttributeSync: ${JSON.stringify(err)}`); 2858} 2859``` 2860 2861### moveCursor<sup>9+</sup> 2862 2863moveCursor(direction: number, callback: AsyncCallback<void>): void 2864 2865Moves the cursor. This API uses an asynchronous callback to return the result. 2866 2867**System capability**: SystemCapability.MiscServices.InputMethodFramework 2868 2869**Parameters** 2870 2871| Name | Type | Mandatory| Description | 2872| --------- | ------------------------- | ---- | -------------- | 2873| direction | number | Yes | Direction in which the cursor moves.<br>- **1**: upward.<br>- **2**: downward.<br>- **3**: leftward.<br>- **4**: rightward.| 2874| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 2875 2876**Error codes** 2877 2878For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2879 2880| ID| Error Message | 2881| -------- | -------------------------- | 2882| 12800003 | input method client error. | 2883 2884**Example** 2885 2886```ts 2887import { BusinessError } from '@ohos.base'; 2888 2889try { 2890 inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP, (err: BusinessError) => { 2891 if (err) { 2892 console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); 2893 return; 2894 } 2895 console.log('Succeeded in moving cursor.'); 2896 }); 2897} catch (err) { 2898 console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); 2899} 2900``` 2901 2902### moveCursor<sup>9+</sup> 2903 2904moveCursor(direction: number): Promise<void> 2905 2906Moves the cursor. This API uses a promise to return the result. 2907 2908**System capability**: SystemCapability.MiscServices.InputMethodFramework 2909 2910**Parameters** 2911 2912| Name | Type | Mandatory| Description | 2913| --------- | ------ | ---- | ------------------------------------------------------------ | 2914| direction | number | Yes | Direction in which the cursor moves.<br>- **1**: upward.<br>- **2**: downward.<br>- **3**: leftward.<br>- **4**: rightward.| 2915 2916**Return value** 2917 2918| Type | Description | 2919| ------------------- | ------------------------- | 2920| Promise<void> | Promise that returns no value.| 2921 2922**Error codes** 2923 2924For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2925 2926| ID| Error Message | 2927| -------- | -------------------------- | 2928| 12800003 | input method client error. | 2929 2930**Example** 2931 2932```ts 2933import { BusinessError } from '@ohos.base'; 2934 2935try { 2936 inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP).then(() => { 2937 console.log('Succeeded in moving cursor.'); 2938 }).catch((err: BusinessError) => { 2939 console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); 2940 }); 2941} catch (err) { 2942 console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); 2943} 2944``` 2945 2946### moveCursorSync<sup>10+</sup> 2947 2948moveCursorSync(direction: number): void 2949 2950Moves the cursor. 2951 2952**System capability**: SystemCapability.MiscServices.InputMethodFramework 2953 2954**Parameters** 2955 2956| Name | Type | Mandatory| Description | 2957| --------- | ------ | ---- | ------------------------------------------------------------ | 2958| direction | number | Yes | Direction in which the cursor moves.<br>- **1**: upward.<br>- **2**: downward.<br>- **3**: leftward.<br>- **4**: rightward.| 2959 2960**Error codes** 2961 2962For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2963 2964| ID| Error Message | 2965| -------- | -------------------------- | 2966| 12800003 | input method client error. | 2967 2968**Example** 2969 2970```ts 2971try { 2972 inputClient.moveCursorSync(inputMethodEngine.Direction.CURSOR_UP); 2973 console.log('Succeeded in moving cursor.'); 2974} catch (err) { 2975 console.error(`Failed to moveCursorSync: ${JSON.stringify(err)}`); 2976} 2977``` 2978 2979### selectByRange<sup>10+</sup> 2980 2981selectByRange(range: Range, callback: AsyncCallback<void>): void 2982 2983Selects text based on the specified range. This API uses an asynchronous callback to return the result. 2984 2985**System capability**: SystemCapability.MiscServices.InputMethodFramework 2986 2987**Parameters** 2988 2989| Name | Type | Mandatory| Description | 2990| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2991| range | [Range](#range10) | Yes | Range of the selected text. | 2992| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the selection event is sent, **err** is **undefined**; otherwise, **err** is an error object.| 2993 2994**Error codes** 2995 2996For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 2997 2998| ID| Error Message | 2999| -------- | -------------------------- | 3000| 401 | parameter error. | 3001| 12800003 | input method client error. | 3002 3003**Example** 3004 3005```ts 3006import { BusinessError } from '@ohos.base'; 3007 3008try { 3009 let range: inputMethodEngine.Range = { start: 0, end: 1 }; 3010 inputClient.selectByRange(range, (err: BusinessError) => { 3011 if (err) { 3012 console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); 3013 return; 3014 } 3015 console.log('Succeeded in selecting by range.'); 3016 }); 3017} catch (err) { 3018 console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); 3019} 3020``` 3021 3022### selectByRange<sup>10+</sup> 3023 3024selectByRange(range: Range): Promise<void> 3025 3026Selects text based on the specified range. This API uses a promise to return the result. 3027 3028**System capability**: SystemCapability.MiscServices.InputMethodFramework 3029 3030**Parameters** 3031 3032| Name| Type | Mandatory| Description | 3033| ------ | --------------------------------------------------------- | ---- | ---------------- | 3034| range | [Range](#range10) | Yes | Range of the selected text.| 3035 3036**Return value** 3037 3038| Type | Description | 3039| ------------------- | ------------------------- | 3040| Promise<void> | Promise that returns no value.| 3041 3042**Error codes** 3043 3044For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 3045 3046| ID| Error Message | 3047| -------- | -------------------------- | 3048| 401 | parameter error. | 3049| 12800003 | input method client error. | 3050 3051**Example** 3052 3053```ts 3054import { BusinessError } from '@ohos.base'; 3055 3056try { 3057 let range: inputMethodEngine.Range = { start: 0, end: 1 }; 3058 inputClient.selectByRange(range).then(() => { 3059 console.log('Succeeded in selecting by range.'); 3060 }).catch((err: BusinessError) => { 3061 console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); 3062 }); 3063} catch (err) { 3064 console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); 3065} 3066``` 3067 3068### selectByRangeSync<sup>10+</sup> 3069 3070selectByRangeSync(range: Range): void 3071 3072Selects text based on the specified range. 3073 3074**System capability**: SystemCapability.MiscServices.InputMethodFramework 3075 3076**Parameters** 3077 3078| Name| Type | Mandatory| Description | 3079| ------ | ----------------- | ---- | ---------------- | 3080| range | [Range](#range10) | Yes | Range of the selected text.| 3081 3082**Error codes** 3083 3084For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 3085 3086| ID| Error Message | 3087| -------- | -------------------------- | 3088| 401 | parameter error. | 3089| 12800003 | input method client error. | 3090 3091**Example** 3092 3093```ts 3094try { 3095 let range: inputMethodEngine.Range = { start: 0, end: 1 }; 3096 inputClient.selectByRangeSync(range); 3097 console.log('Succeeded in selecting by range.'); 3098} catch (err) { 3099 console.error(`Failed to selectByRangeSync: ${JSON.stringify(err)}`); 3100} 3101``` 3102 3103### selectByMovement<sup>10+</sup> 3104 3105selectByMovement(movement: Movement, callback: AsyncCallback<void>): void 3106 3107Selects text based on the cursor movement direction. This API uses an asynchronous callback to return the result. 3108 3109**System capability**: SystemCapability.MiscServices.InputMethodFramework 3110 3111**Parameters** 3112 3113| Name | Type | Mandatory| Description | 3114| -------- | ------ | ---- | ------ | 3115| movement | [Movement](#movement10) | Yes | Direction in which the cursor moves when the text is selected. | 3116| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the selection event is sent, **err** is **undefined**; otherwise, **err** is an error object.| 3117 3118**Error codes** 3119 3120For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 3121 3122| ID| Error Message | 3123| -------- | -------------------------- | 3124| 401 | parameter error. | 3125| 12800003 | input method client error. | 3126 3127**Example** 3128 3129```ts 3130import { BusinessError } from '@ohos.base'; 3131 3132try { 3133 let movement: inputMethodEngine.Movement = { direction: 1 }; 3134 inputClient.selectByMovement(movement, (err: BusinessError) => { 3135 if (err) { 3136 console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); 3137 return; 3138 } 3139 console.log('Succeeded in selecting by movement.'); 3140 }); 3141} catch (err) { 3142 console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); 3143} 3144``` 3145 3146### selectByMovement<sup>10+</sup> 3147 3148selectByMovement(movement: Movement): Promise<void> 3149 3150Selects text based on the specified range. This API uses a promise to return the result. 3151 3152**System capability**: SystemCapability.MiscServices.InputMethodFramework 3153 3154**Parameters** 3155 3156| Name | Type | Mandatory| Description | 3157| -------- | ------------------------------------------------------------ | ---- | ---------------------- | 3158| movement | [Movement](#movement10) | Yes | Direction in which the cursor moves when the text is selected.| 3159 3160**Return value** 3161 3162| Type | Description | 3163| ------------------- | ------------------------- | 3164| Promise<void> | Promise that returns no value.| 3165 3166**Error codes** 3167 3168For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 3169 3170| ID| Error Message | 3171| -------- | -------------------------- | 3172| 401 | parameter error. | 3173| 12800003 | input method client error. | 3174 3175**Example** 3176 3177```ts 3178import { BusinessError } from '@ohos.base'; 3179 3180try { 3181 let movement: inputMethodEngine.Movement = { direction: 1 }; 3182 inputClient.selectByMovement(movement).then(() => { 3183 console.log('Succeeded in selecting by movement.'); 3184 }).catch((err: BusinessError) => { 3185 console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); 3186 }); 3187} catch (err) { 3188 console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); 3189} 3190``` 3191 3192### selectByMovementSync<sup>10+</sup> 3193 3194selectByMovementSync(movement: Movement): void 3195 3196Selects text based on the cursor movement direction. 3197 3198**System capability**: SystemCapability.MiscServices.InputMethodFramework 3199 3200**Parameters** 3201 3202| Name | Type | Mandatory| Description | 3203| -------- | ----------------------- | ---- | ---------------------- | 3204| movement | [Movement](#movement10) | Yes | Direction in which the cursor moves when the text is selected.| 3205 3206**Error codes** 3207 3208For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 3209 3210| ID| Error Message | 3211| -------- | -------------------------- | 3212| 401 | parameter error. | 3213| 12800003 | input method client error. | 3214 3215**Example** 3216 3217```ts 3218try { 3219 let movement: inputMethodEngine.Movement = { direction: 1 }; 3220 inputClient.selectByMovementSync(movement); 3221 console.log('Succeeded in selecting by movement.'); 3222} catch (err) { 3223 console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); 3224} 3225``` 3226 3227### getTextIndexAtCursor<sup>10+</sup> 3228 3229getTextIndexAtCursor(callback: AsyncCallback<number>): void 3230 3231Obtains the index of the text where the cursor is located. This API uses an asynchronous callback to return the result. 3232 3233**System capability**: SystemCapability.MiscServices.InputMethodFramework 3234 3235**Parameters** 3236 3237| Name | Type | Mandatory| Description | 3238| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 3239| callback | AsyncCallback<number> | Yes | Callback used to return the result. If the text index is obtained, **err** is **undefined**; otherwise, **err** is an error object.| 3240 3241**Error codes** 3242 3243For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 3244 3245| ID| Error Message | 3246| -------- | ------------------------------ | 3247| 12800003 | input method client error. | 3248| 12800006 | Input method controller error. | 3249 3250**Example** 3251 3252```ts 3253import { BusinessError } from '@ohos.base'; 3254 3255inputClient.getTextIndexAtCursor((err: BusinessError, index: number) => { 3256 if (err) { 3257 console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); 3258 return; 3259 } 3260 console.log('Succeeded in getTextIndexAtCursor: ' + index); 3261}); 3262``` 3263 3264### getTextIndexAtCursor<sup>10+</sup> 3265 3266getTextIndexAtCursor(): Promise<number> 3267 3268Obtains the index of the text where the cursor is located. This API uses a promise to return the result. 3269 3270**System capability**: SystemCapability.MiscServices.InputMethodFramework 3271 3272**Return value** 3273 3274| Type | Description | 3275| --------------------- | --------------------------------------- | 3276| Promise<number> | Promise used to return the result.| 3277 3278**Error codes** 3279 3280For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 3281 3282| ID| Error Message | 3283| -------- | ------------------------------ | 3284| 12800003 | input method client error. | 3285| 12800006 | Input method controller error. | 3286 3287**Example** 3288 3289```ts 3290import { BusinessError } from '@ohos.base'; 3291 3292inputClient.getTextIndexAtCursor().then((index: number) => { 3293 console.log('Succeeded in getTextIndexAtCursor: ' + index); 3294}).catch((err: BusinessError) => { 3295 console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); 3296}); 3297``` 3298 3299### getTextIndexAtCursorSync<sup>10+</sup> 3300 3301getTextIndexAtCursorSync(): number 3302 3303Obtains the index of the text where the cursor is located. 3304 3305**System capability**: SystemCapability.MiscServices.InputMethodFramework 3306 3307**Return value** 3308 3309| Type | Description | 3310| ------ | -------------------------- | 3311| number | Index of the text where the cursor is located.| 3312 3313**Error codes** 3314 3315For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 3316 3317| ID| Error Message | 3318| -------- | ------------------------------ | 3319| 12800003 | input method client error. | 3320| 12800006 | Input method controller error. | 3321 3322**Example** 3323 3324```ts 3325try{ 3326 let index: number = inputClient.getTextIndexAtCursorSync(); 3327 console.log(`Succeeded in getTextIndexAtCursorSync, index: ${index}`); 3328} catch (err) { 3329 console.error(`Failed to getTextIndexAtCursorSync: ${JSON.stringify(err)}`); 3330} 3331``` 3332 3333### sendExtendAction<sup>10+</sup> 3334 3335sendExtendAction(action: ExtendAction, callback: AsyncCallback<void>): void 3336 3337Sends an extended edit action. This API uses an asynchronous callback to return the result. 3338 3339> **NOTE** 3340> 3341> The input method calls this API to send an extended edit action to an edit box, which in turn listens for the corresponding event [on('handleExtendAction')](./js-apis-inputmethod.md#onhandleextendaction10) for further processing. 3342 3343**System capability**: SystemCapability.MiscServices.InputMethodFramework 3344 3345**Parameters** 3346 3347| Name | Type | Mandatory| Description | 3348| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 3349| action | [ExtendAction](#extendaction10) | Yes | Extended edit action to send.| 3350| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 3351 3352**Error codes** 3353 3354For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 3355 3356| ID| Error Message | 3357| -------- | ------------------------------ | 3358| 12800003 | input method client error. | 3359| 12800006 | Input method controller error. | 3360 3361**Example** 3362 3363```ts 3364import { BusinessError } from '@ohos.base'; 3365 3366try { 3367 inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err: BusinessError) => { 3368 if (err) { 3369 console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); 3370 return; 3371 } 3372 console.log('Succeeded in sending extend action.'); 3373 }); 3374} catch(err) { 3375 console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); 3376} 3377``` 3378 3379### sendExtendAction<sup>10+</sup> 3380 3381sendExtendAction(action: ExtendAction): Promise<void> 3382 3383Sends an extended edit action. This API uses a promise to return the result. 3384 3385>**NOTE** 3386> 3387> The input method calls this API to send an extended edit action to an edit box, which in turn listens for the corresponding event [on('handleExtendAction')](./js-apis-inputmethod.md#onhandleextendaction10) for further processing. 3388 3389**System capability**: SystemCapability.MiscServices.InputMethodFramework 3390 3391**Parameters** 3392 3393| Name| Type| Mandatory| Description| 3394| -------- | -------- | -------- | -------- | 3395| action | [ExtendAction](#extendaction10) | Yes| Extended edit action to send.| 3396 3397**Return value** 3398 3399| Type | Description | 3400| --------------------- | --------------------------------------- | 3401| Promise<void> | Promise that returns no value.| 3402 3403**Error codes** 3404 3405For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md). 3406 3407| ID| Error Message | 3408| -------- | ------------------------------ | 3409| 12800003 | input method client error. | 3410| 12800006 | Input method controller error. | 3411 3412**Example** 3413 3414```ts 3415import { BusinessError } from '@ohos.base'; 3416 3417try { 3418 inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => { 3419 console.log('Succeeded in sending extend action.'); 3420 }).catch((err: BusinessError) => { 3421 console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); 3422 }); 3423} catch(err) { 3424 console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); 3425} 3426``` 3427 3428## EditorAttribute 3429 3430Describes the attribute of the edit box. 3431 3432**System capability**: SystemCapability.MiscServices.InputMethodFramework 3433 3434| Name | Type| Readable| Writable| Description | 3435| ------------ | -------- | ---- | ---- | ------------------ | 3436| enterKeyType | number | Yes | No | Function of the edit box.| 3437| inputPattern | number | Yes | No | Text of the edit box.| 3438 3439## KeyEvent 3440 3441Describes the attribute of a key. 3442 3443**System capability**: SystemCapability.MiscServices.InputMethodFramework 3444 3445| Name | Type| Readable| Writable| Description | 3446| --------- | -------- | ---- | ---- | ------------ | 3447| keyCode | number | Yes | No | Key value. For details, see [KeyCode](js-apis-keycode.md#keycode).| 3448| keyAction | number | Yes | No | Key event type.<br>- **2**: keydown event.<br>- **3**: keyup event.| 3449 3450## PanelFlag<sup>10+</sup> 3451 3452Enumerates the state types of the input method panel. 3453 3454**System capability**: SystemCapability.MiscServices.InputMethodFramework 3455 3456| Name | Value| Description | 3457| ------------ | -- | ------------------ | 3458| FLG_FIXED | 0 | Fixed state type.| 3459| FLG_FLOATING | 1 | Floating state type.| 3460 3461## PanelType<sup>10+</sup> 3462 3463Enumerates the types of the input method panel. 3464 3465**System capability**: SystemCapability.MiscServices.InputMethodFramework 3466 3467| Name | Value| Description | 3468| ------------ | -- | ------------------ | 3469| SOFT_KEYBOARD | 0 | Soft keyboard type.| 3470| STATUS_BAR | 1 | Status bar type.| 3471 3472## PanelInfo<sup>10+</sup> 3473 3474**System capability**: SystemCapability.MiscServices.InputMethodFramework 3475 3476Describes the attributes of the input method panel. 3477 3478| Name | Type| Readable| Writable| Description | 3479| --------- | -------- | ---- | ---- | ------------ | 3480| type | number | Yes | Yes | Type of the panel.| 3481| flag | number | Yes | Yes | State type of the panel.| 3482 3483## TextInputClient<sup>(deprecated)</sup> 3484 3485> **NOTE** 3486> 3487> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [InputClient](#inputclient9) instead. 3488 3489In the following API examples, you must first use [on('inputStart')](#oninputstart) to obtain a **TextInputClient** instance, and then call the APIs using the obtained instance. 3490 3491### getForward<sup>(deprecated)</sup> 3492 3493getForward(length:number, callback: AsyncCallback<string>): void 3494 3495Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result. 3496 3497> **NOTE** 3498> 3499> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9) instead. 3500 3501**System capability**: SystemCapability.MiscServices.InputMethodFramework 3502 3503**Parameters** 3504 3505| Name| Type| Mandatory| Description| 3506| -------- | -------- | -------- | -------- | 3507| length | number | Yes| Text length.| 3508| callback | AsyncCallback<string> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the obtained text. Otherwise, **err** is an error object.| 3509 3510**Example** 3511 3512```ts 3513import { BusinessError } from '@ohos.base'; 3514 3515let length = 1; 3516textInputClient.getForward(length, (err: BusinessError, text: string) => { 3517 if (err) { 3518 console.error(`Failed to getForward: ${JSON.stringify(err)}`); 3519 return; 3520 } 3521 console.log('Succeeded in getting forward, text: ' + text); 3522}); 3523``` 3524 3525### getForward<sup>(deprecated)</sup> 3526 3527getForward(length:number): Promise<string> 3528 3529Obtains the specific-length text before the cursor. This API uses a promise to return the result. 3530 3531> **NOTE** 3532> 3533> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9) instead. 3534 3535**System capability**: SystemCapability.MiscServices.InputMethodFramework 3536 3537**Parameters** 3538 3539| Name| Type| Mandatory| Description| 3540| -------- | -------- | -------- | -------- | 3541| length | number | Yes| Text length.| 3542 3543**Return value** 3544 3545| Type | Description | 3546| ------------------------------- | ------------------------------------------------------------ | 3547| Promise<string> | Promise used to return the specific-length text before the cursor. | 3548 3549**Example** 3550 3551```ts 3552import { BusinessError } from '@ohos.base'; 3553 3554let length = 1; 3555textInputClient.getForward(length).then((text: string) => { 3556 console.log('Succeeded in getting forward, text: ' + text); 3557}).catch((err: BusinessError) => { 3558 console.error(`Failed to getForward: ${JSON.stringify(err)}`); 3559}); 3560``` 3561 3562### getBackward<sup>(deprecated)</sup> 3563 3564getBackward(length:number, callback: AsyncCallback<string>): void 3565 3566Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result. 3567 3568> **NOTE** 3569> 3570> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9) instead. 3571 3572**System capability**: SystemCapability.MiscServices.InputMethodFramework 3573 3574**Parameters** 3575 3576| Name| Type| Mandatory| Description| 3577| -------- | -------- | -------- | -------- | 3578| length | number | Yes| Text length.| 3579| callback | AsyncCallback<string> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the obtained text. Otherwise, **err** is an error object.| 3580 3581**Example** 3582 3583```ts 3584import { BusinessError } from '@ohos.base'; 3585 3586let length = 1; 3587textInputClient.getBackward(length, (err: BusinessError, text: string) => { 3588 if (err) { 3589 console.error(`Failed to getBackward: ${JSON.stringify(err)}`); 3590 return; 3591 } 3592 console.log('Succeeded in getting borward, text: ' + text); 3593}); 3594``` 3595 3596### getBackward<sup>(deprecated)</sup> 3597 3598getBackward(length:number): Promise<string> 3599 3600Obtains the specific-length text after the cursor. This API uses a promise to return the result. 3601 3602> **NOTE** 3603> 3604> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9) instead. 3605 3606**System capability**: SystemCapability.MiscServices.InputMethodFramework 3607 3608**Parameters** 3609 3610| Name| Type| Mandatory| Description| 3611| -------- | -------- | -------- | -------- | 3612| length | number | Yes| Text length.| 3613 3614**Return value** 3615 3616| Type | Description | 3617| ------------------------------- | ------------------------------------------------------------ | 3618| Promise<string> | Promise used to return the specific-length text after the cursor. | 3619 3620**Example** 3621 3622```ts 3623import { BusinessError } from '@ohos.base'; 3624 3625let length = 1; 3626textInputClient.getBackward(length).then((text: string) => { 3627 console.log('Succeeded in getting backward: ' + JSON.stringify(text)); 3628}).catch((err: BusinessError) => { 3629 console.error(`Failed to getBackward: ${JSON.stringify(err)}`); 3630}); 3631``` 3632 3633### deleteForward<sup>(deprecated)</sup> 3634 3635deleteForward(length:number, callback: AsyncCallback<boolean>): void 3636 3637Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result. 3638 3639> **NOTE** 3640> 3641> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9) instead. 3642 3643**System capability**: SystemCapability.MiscServices.InputMethodFramework 3644 3645**Parameters** 3646 3647| Name| Type| Mandatory| Description| 3648| -------- | -------- | -------- | -------- | 3649| length | number | Yes| Text length.| 3650| 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.| 3651 3652**Example** 3653 3654```ts 3655import { BusinessError } from '@ohos.base'; 3656 3657let length = 1; 3658textInputClient.deleteForward(length, (err: BusinessError, result: boolean) => { 3659 if (err) { 3660 console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); 3661 return; 3662 } 3663 if (result) { 3664 console.log('Succeeded in deleting forward.'); 3665 } else { 3666 console.error('Failed to deleteForward.'); 3667 } 3668}); 3669``` 3670 3671### deleteForward<sup>(deprecated)</sup> 3672 3673deleteForward(length:number): Promise<boolean> 3674 3675Deletes the fixed-length text before the cursor. This API uses a promise to return the result. 3676 3677> **NOTE** 3678> 3679> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9) instead. 3680 3681**System capability**: SystemCapability.MiscServices.InputMethodFramework 3682 3683**Parameters** 3684 3685| Name| Type | Mandatory| Description | 3686| ------ | ------ | ---- | ---------- | 3687| length | number | Yes | Text length.| 3688 3689**Return value** 3690 3691| Type | Description | 3692| ---------------------- | -------------- | 3693| Promise<boolean> | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.| 3694 3695**Example** 3696 3697```ts 3698import { BusinessError } from '@ohos.base'; 3699 3700let length = 1; 3701textInputClient.deleteForward(length).then((result: boolean) => { 3702 if (result) { 3703 console.log('Succeeded in deleting forward.'); 3704 } else { 3705 console.error('Failed to delete forward.'); 3706 } 3707}).catch((err: BusinessError) => { 3708 console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); 3709}); 3710``` 3711 3712### deleteBackward<sup>(deprecated)</sup> 3713 3714deleteBackward(length:number, callback: AsyncCallback<boolean>): void 3715 3716Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result. 3717 3718> **NOTE** 3719> 3720> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9) instead. 3721 3722**System capability**: SystemCapability.MiscServices.InputMethodFramework 3723 3724**Parameters** 3725 3726| Name | Type | Mandatory| Description | 3727| -------- | ---------------------------- | ---- | -------------- | 3728| length | number | Yes | Text length. | 3729| 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.| 3730 3731**Example** 3732 3733```ts 3734import { BusinessError } from '@ohos.base'; 3735 3736let length = 1; 3737textInputClient.deleteBackward(length, (err: BusinessError, result: boolean) => { 3738 if (err) { 3739 console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); 3740 return; 3741 } 3742 if (result) { 3743 console.log('Succeeded in deleting backward.'); 3744 } else { 3745 console.error('Failed to deleteBackward.'); 3746 } 3747}); 3748``` 3749 3750### deleteBackward<sup>(deprecated)</sup> 3751 3752deleteBackward(length:number): Promise<boolean> 3753 3754Deletes the fixed-length text after the cursor. This API uses a promise to return the result. 3755 3756> **NOTE** 3757> 3758> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9) instead. 3759 3760**System capability**: SystemCapability.MiscServices.InputMethodFramework 3761 3762**Parameters** 3763 3764| Name| Type| Mandatory| Description| 3765| -------- | -------- | -------- | -------- | 3766| length | number | Yes| Text length.| 3767 3768**Return value** 3769 3770| Type | Description | 3771| ------------------------------- | ------------------------------------------------------------ | 3772| Promise<boolean> | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.| 3773 3774**Example** 3775 3776```ts 3777import { BusinessError } from '@ohos.base'; 3778 3779let length = 1; 3780textInputClient.deleteBackward(length).then((result: boolean) => { 3781 if (result) { 3782 console.log('Succeeded in deleting backward.'); 3783 } else { 3784 console.error('Failed to deleteBackward.'); 3785 } 3786}).catch((err: BusinessError) => { 3787 console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); 3788}); 3789``` 3790### sendKeyFunction<sup>(deprecated)</sup> 3791 3792sendKeyFunction(action: number, callback: AsyncCallback<boolean>): void 3793 3794Sends the function key. This API uses an asynchronous callback to return the result. 3795 3796> **NOTE** 3797> 3798> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9) instead. 3799 3800**System capability**: SystemCapability.MiscServices.InputMethodFramework 3801 3802**Parameters** 3803 3804| Name| Type| Mandatory| Description| 3805| -------- | -------- | -------- | -------- | 3806| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).| 3807| 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.| 3808 3809**Example** 3810 3811```ts 3812import { BusinessError } from '@ohos.base'; 3813 3814let action = 1; 3815textInputClient.sendKeyFunction(action, (err: BusinessError, result: boolean) => { 3816 if (err) { 3817 console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); 3818 return; 3819 } 3820 if (result) { 3821 console.log('Succeeded in sending key function.'); 3822 } else { 3823 console.error('Failed to sendKeyFunction.'); 3824 } 3825}); 3826``` 3827 3828### sendKeyFunction<sup>(deprecated)</sup> 3829 3830sendKeyFunction(action: number): Promise<boolean> 3831 3832Sends the function key. This API uses a promise to return the result. 3833 3834> **NOTE** 3835> 3836> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9) instead. 3837 3838**System capability**: SystemCapability.MiscServices.InputMethodFramework 3839 3840**Parameters** 3841 3842| Name| Type| Mandatory| Description| 3843| -------- | -------- | -------- | -------- | 3844| action | number | Yes| Action of the function key.<br>**0**: invalid key.<br>**1**: confirm key (Enter key).| 3845 3846**Return value** 3847 3848| Type | Description | 3849| ------------------------------- | ------------------------------------------------------------ | 3850| Promise<boolean> | Promise used to return the result. The value **true** means that the setting is successful, and **false** means the opposite.| 3851 3852**Example** 3853 3854```ts 3855import { BusinessError } from '@ohos.base'; 3856 3857let action = 1; 3858textInputClient.sendKeyFunction(action).then((result: boolean) => { 3859 if (result) { 3860 console.log('Succeeded in sending key function.'); 3861 } else { 3862 console.error('Failed to sendKeyFunction.'); 3863 } 3864}).catch((err: BusinessError) => { 3865 console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); 3866}); 3867``` 3868 3869### insertText<sup>(deprecated)</sup> 3870 3871insertText(text:string, callback: AsyncCallback<boolean>): void 3872 3873Inserts text. This API uses an asynchronous callback to return the result. 3874 3875> **NOTE** 3876> 3877> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9) instead. 3878 3879**System capability**: SystemCapability.MiscServices.InputMethodFramework 3880 3881**Parameters** 3882 3883| Name| Type| Mandatory| Description| 3884| -------- | -------- | -------- | -------- | 3885| text | string | Yes| Text to insert.| 3886| 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.| 3887 3888**Example** 3889 3890```ts 3891import { BusinessError } from '@ohos.base'; 3892 3893textInputClient.insertText('test', (err: BusinessError, result: boolean) => { 3894 if (err) { 3895 console.error(`Failed to insertText: ${JSON.stringify(err)}`); 3896 return; 3897 } 3898 if (result) { 3899 console.log('Succeeded in inserting text.'); 3900 } else { 3901 console.error('Failed to insertText.'); 3902 } 3903}); 3904``` 3905 3906### insertText<sup>(deprecated)</sup> 3907 3908insertText(text:string): Promise<boolean> 3909 3910Inserts text. This API uses a promise to return the result. 3911 3912> **NOTE** 3913> 3914> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9) instead. 3915 3916**System capability**: SystemCapability.MiscServices.InputMethodFramework 3917 3918**Parameters** 3919 3920| Name| Type| Mandatory| Description| 3921| -------- | -------- | -------- | -------- | 3922| text | string | Yes| Text to insert.| 3923 3924**Return value** 3925 3926| Type | Description | 3927| ------------------------------- | ------------------------------------------------------------ | 3928| Promise<boolean> | Promise used to return the result. The value **true** means that the insertion is successful, and **false** means the opposite.| 3929 3930**Example** 3931 3932```ts 3933import { BusinessError } from '@ohos.base'; 3934 3935textInputClient.insertText('test').then((result: boolean) => { 3936 if (result) { 3937 console.log('Succeeded in inserting text.'); 3938 } else { 3939 console.error('Failed to insertText.'); 3940 } 3941}).catch((err: BusinessError) => { 3942 console.error(`Failed to insertText: ${JSON.stringify(err)}`); 3943}); 3944``` 3945 3946### getEditorAttribute<sup>(deprecated)</sup> 3947 3948getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void 3949 3950Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result. 3951 3952> **NOTE** 3953> 3954> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9) instead. 3955 3956**System capability**: SystemCapability.MiscServices.InputMethodFramework 3957 3958**Parameters** 3959 3960| Name | Type | Mandatory | Description | 3961| -------- | ----- | ----- | ----- | 3962| callback | AsyncCallback<[EditorAttribute](#editorattribute)> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the attribute of the edit box. Otherwise, **err** is an error object.| 3963 3964**Example** 3965 3966```ts 3967import { BusinessError } from '@ohos.base'; 3968 3969textInputClient.getEditorAttribute((err: BusinessError, editorAttribute: inputMethodEngine.EditorAttribute) => { 3970 if (err) { 3971 console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); 3972 return; 3973 } 3974 console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); 3975 console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); 3976}); 3977``` 3978 3979### getEditorAttribute<sup>(deprecated)</sup> 3980 3981getEditorAttribute(): Promise<EditorAttribute> 3982 3983Obtains the attribute of the edit box. This API uses a promise to return the result. 3984 3985> **NOTE** 3986> 3987> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9) instead. 3988 3989**System capability**: SystemCapability.MiscServices.InputMethodFramework 3990 3991**Return value** 3992 3993| Type | Description | 3994| ------------------------------- | ------------------------------------------------------------ | 3995| Promise<[EditorAttribute](#editorattribute)> | Promise used to return the attribute of the edit box. | 3996 3997**Example** 3998 3999```ts 4000import { BusinessError } from '@ohos.base'; 4001 4002textInputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => { 4003 console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); 4004 console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); 4005}).catch((err: BusinessError) => { 4006 console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); 4007}); 4008``` 4009 4010