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