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## 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 instances related to input method operations.| 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](#commanddatatype12)>> | 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 the preconfigured default input method. | 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](#commanddatatype12)>> | 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 the preconfigured default input method. | 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. | 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: AsyncCallback\<Panel>): void 750 751Creates an input method panel, which can be called only by input method applications. 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 application.| 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. | 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): Promise\<Panel> 796 797Creates an input method panel, which can be called only by input method applications. 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. | 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.(keyDown): ${keyEvent.keyCode}`); 987 console.log(`inputMethodEngine keyAction.(keyDown): ${keyEvent.keyAction}`); 988 return true; 989 }); 990 inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent: inputMethodEngine.KeyEvent) => { 991 console.log(`inputMethodEngine keyCode.(keyDown): ${keyEvent.keyCode}`); 992 console.log(`inputMethodEngine keyAction.(keyDown): ${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 | (event: [InputKeyEvent](../apis-input-kit/js-apis-keyevent.md#keyevent)) => boolean | Yes | Callback used to return the result. The input parameter is the key event information and the return value is of the Boolean type.<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: ${keyEvent.ctrlKey}`); 1057 console.log(`inputMethodEngine keyEvent.unicodeChar: ${keyEvent.unicodeChar}`); 1058 return true; 1059 }); 1060} catch(err) { 1061 console.error(`Failed to inputMethodEngine: ${JSON.stringify(err)}`); 1062} 1063``` 1064 1065### off('keyEvent')<sup>10+</sup> 1066 1067off(type: 'keyEvent', callback?: (event: InputKeyEvent) => boolean): void 1068 1069Disables listening for a keyboard event. This API uses an asynchronous callback to return the result. 1070 1071**System capability**: SystemCapability.MiscServices.InputMethodFramework 1072 1073**Parameters** 1074 1075| Name | Type | Mandatory| Description | 1076| -------- | -------- | ---- | ------------------------------------------------------------ | 1077| type | string | Yes | Event type, which is **'keyEvent'**.| 1078| callback | function | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified type.| 1079 1080**Example** 1081 1082```ts 1083import type { KeyEvent } from '@kit.InputKit'; 1084 1085try { 1086 inputMethodEngine.getKeyboardDelegate().off('keyEvent', (keyEvent: KeyEvent) => { 1087 console.log('This is a callback function which will be deregistered.'); 1088 return true; 1089 }); 1090 inputMethodEngine.getKeyboardDelegate().off('keyEvent'); 1091} catch(err) { 1092 console.error(`Failed to keyEvent: ${JSON.stringify(err)}`); 1093} 1094``` 1095 1096### on('cursorContextChange') 1097 1098on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void 1099 1100Enables listening for the cursor change event. This API uses an asynchronous callback to return the result. 1101 1102**System capability**: SystemCapability.MiscServices.InputMethodFramework 1103 1104**Parameters** 1105 1106| Name | Type | Mandatory | Description | 1107| -------- | ---- | ---- | ----- | 1108| type | string | Yes | Event type, which is **'cursorContextChange'**.| 1109| callback | (x: number, y: number, height: number) => void | Yes | Callback used to return the cursor information.<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.| 1110 1111**Example** 1112 1113```ts 1114try { 1115 inputMethodEngine.getKeyboardDelegate().on('cursorContextChange', (x: number, y: number, height: number) => { 1116 console.log('inputMethodEngine cursorContextChange x:' + x); 1117 console.log('inputMethodEngine cursorContextChange y:' + y); 1118 console.log('inputMethodEngine cursorContextChange height:' + height); 1119 }); 1120} catch(err) { 1121 console.error(`Failed to cursorContextChange: ${JSON.stringify(err)}`); 1122} 1123``` 1124 1125### off('cursorContextChange') 1126 1127off(type: 'cursorContextChange', callback?: (x: number, y: number, height: number) => void): void 1128 1129Disables listening for cursor context changes. This API uses an asynchronous callback to return the result. 1130 1131**System capability**: SystemCapability.MiscServices.InputMethodFramework 1132 1133 **Parameters** 1134 1135| Name | Type | Mandatory | Description | 1136| -------- | ---- | ---- | ------ | 1137| type | string | Yes | Event type, which is **'cursorContextChange'**.| 1138| 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.| 1139 1140 1141 **Example** 1142 1143```ts 1144try { 1145 inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x: number, y: number, height: number) => { 1146 console.log('delete cursorContextChange notification.'); 1147 }); 1148} catch(err) { 1149 console.error(`Failed to cursorContextChange: ${JSON.stringify(err)}`); 1150} 1151``` 1152### on('selectionChange') 1153 1154on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void 1155 1156Enables listening for the text selection change event. This API uses an asynchronous callback to return the result. 1157 1158**System capability**: SystemCapability.MiscServices.InputMethodFramework 1159 1160**Parameters** 1161 1162| Name | Type | Mandatory | Description | 1163| -------- | ----- | ---- | ---- | 1164| type | string | Yes | Event type, which is **'selectionChange'**.| 1165| 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.| 1166 1167**Example** 1168 1169```ts 1170try { 1171 inputMethodEngine.getKeyboardDelegate() 1172 .on('selectionChange', (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => { 1173 console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin); 1174 console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd); 1175 console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin); 1176 console.log('inputMethodEngine beforeEach selectionChange newEnd:' + newEnd); 1177 }); 1178} catch(err) { 1179 console.error(`Failed to selectionChange: ${JSON.stringify(err)}`); 1180} 1181``` 1182 1183### off('selectionChange') 1184 1185off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void 1186 1187Disables listening for the text selection change event. This API uses an asynchronous callback to return the result. 1188 1189**System capability**: SystemCapability.MiscServices.InputMethodFramework 1190 1191**Parameters** 1192 1193| Name | Type | Mandatory | Description | 1194| -------- | ------- | ---- | ------- | 1195| type | string | Yes | Event type, which is **'selectionChange'**. | 1196| 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.| 1197 1198**Example** 1199 1200```ts 1201try { 1202 inputMethodEngine.getKeyboardDelegate() 1203 .off('selectionChange', (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => { 1204 console.log('delete selectionChange notification.'); 1205 }); 1206} catch(err) { 1207 console.error(`Failed to selectionChange: ${JSON.stringify(err)}`); 1208} 1209``` 1210 1211 1212### on('textChange') 1213 1214on(type: 'textChange', callback: (text: string) => void): void 1215 1216Enables listening for the text change event. This API uses an asynchronous callback to return the result. 1217 1218**System capability**: SystemCapability.MiscServices.InputMethodFramework 1219 1220**Parameters** 1221 1222| Name | Type | Mandatory | Description | 1223| -------- | ------ | ---- | ------------------------------------------------------------ | 1224| type | string | Yes | Event type, which is **'textChange'**. | 1225| callback | (text: string) => void | Yes | Callback used to return the text content.| 1226 1227**Example** 1228 1229```ts 1230try { 1231 inputMethodEngine.getKeyboardDelegate().on('textChange', (text: string) => { 1232 console.log('inputMethodEngine textChange. text:' + text); 1233 }); 1234} catch(err) { 1235 console.error(`Failed to textChange: ${JSON.stringify(err)}`); 1236} 1237``` 1238 1239### off('textChange') 1240 1241off(type: 'textChange', callback?: (text: string) => void): void 1242 1243Disables listening for the text change event. This API uses an asynchronous callback to return the result. 1244 1245**System capability**: SystemCapability.MiscServices.InputMethodFramework 1246 1247**Parameters** 1248 1249| Name | Type | Mandatory | Description | 1250| -------- | ------ | ---- | ------------------------------------------------------------ | 1251| type | string | Yes | Event type, which is **'textChange'**. | 1252| callback | (text: string) => void | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified type.| 1253 1254**Example** 1255 1256```ts 1257try { 1258 inputMethodEngine.getKeyboardDelegate().off('textChange', (text: string) => { 1259 console.log('delete textChange notification. text:' + text); 1260 }); 1261} catch(err) { 1262 console.error(`Failed to textChange: ${JSON.stringify(err)}`); 1263} 1264``` 1265 1266### on('editorAttributeChanged')<sup>10+</sup> 1267 1268on(type: 'editorAttributeChanged', callback: (attr: EditorAttribute) => void): void 1269 1270Enables listening for the edit box attribute change event. This API uses an asynchronous callback to return the result. 1271 1272**System capability**: SystemCapability.MiscServices.InputMethodFramework 1273 1274**Parameters** 1275 1276| Name | Type | Mandatory | Description | 1277| -------- | ------ | ---- | ------------------------------------------------------------ | 1278| type | string | Yes | Event type, which is **'editorAttributeChanged'**. | 1279| callback | (attr: EditorAttribute) => void | Yes | Callback used to return the changed edit box attribute.| 1280 1281**Example** 1282 1283```ts 1284try { 1285 inputMethodEngine.getKeyboardDelegate().on('editorAttributeChanged', (attr: inputMethodEngine.EditorAttribute) => { 1286 console.log(`Succeeded in receiving attribute of editor, inputPattern = ${attr.inputPattern}, enterKeyType = ${attr.enterKeyType}`); 1287 }); 1288} catch(err) { 1289 console.error(`Failed to textChange: ${JSON.stringify(err)}`); 1290} 1291``` 1292 1293### off('editorAttributeChanged')<sup>10+</sup> 1294 1295off(type: 'editorAttributeChanged', callback?: (attr: EditorAttribute) => void): void 1296 1297Disables listening for the edit box attribute change event. This API uses an asynchronous callback to return the result. 1298 1299**System capability**: SystemCapability.MiscServices.InputMethodFramework 1300 1301**Parameters** 1302 1303| Name | Type | Mandatory | Description | 1304| -------- | ------ | ---- | ------------------------------------------------------------ | 1305| type | string | Yes | Event type, which is **'editorAttributeChanged'**. | 1306| callback | (attr: EditorAttribute) => void | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified type.| 1307 1308**Example** 1309 1310```ts 1311inputMethodEngine.getKeyboardDelegate().off('editorAttributeChanged'); 1312``` 1313 1314## Panel<sup>10+</sup> 1315 1316In the following API examples, you must first use [createPanel](#createpanel10) to obtain a **Panel** instance, and then call the APIs using the obtained instance. 1317 1318### setUiContent<sup>10+</sup> 1319 1320setUiContent(path: string, callback: AsyncCallback\<void>): void 1321 1322Loads content from a page to this input method panel. This API uses an asynchronous callback to return the result. 1323 1324**System capability**: SystemCapability.MiscServices.InputMethodFramework 1325 1326**Parameters** 1327 1328| Name | Type | Mandatory | Description | 1329| -------- | ---------------------- | ---- | -------- | 1330| path | string | Yes | Path of the page from which the content will be loaded. | 1331| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1332 1333**Error codes** 1334 1335For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1336 1337| ID| Error Message | 1338| -------- | ------------------------------------------------------- | 1339| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1340 1341**Example** 1342 1343```ts 1344import { BusinessError } from '@kit.BasicServicesKit'; 1345 1346try { 1347 panel.setUiContent('pages/page2/page2', (err: BusinessError) => { 1348 if (err) { 1349 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1350 return; 1351 } 1352 console.log('Succeeded in setting the content.'); 1353 }); 1354} catch (err) { 1355 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1356} 1357``` 1358 1359### setUiContent<sup>10+</sup> 1360 1361setUiContent(path: string): Promise\<void> 1362 1363Loads content from a page to this input method panel. This API uses a promise to return the result. 1364 1365**System capability**: SystemCapability.MiscServices.InputMethodFramework 1366 1367**Parameters** 1368 1369| Name | Type | Mandatory | Description | 1370| -------- | ---------------------- | ---- | -------- | 1371| path | string | Yes | Path of the page from which the content will be loaded. | 1372 1373**Return value** 1374 1375| Type | Description | 1376| ------- | ------------------------------ | 1377| Promise\<void> | Promise that returns no value. | 1378 1379**Error codes** 1380 1381For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1382 1383| ID| Error Message | 1384| -------- | ------------------------------------------------------- | 1385| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1386 1387**Example** 1388 1389```ts 1390import { BusinessError } from '@kit.BasicServicesKit'; 1391 1392try { 1393 panel.setUiContent('pages/page2/page2').then(() => { 1394 console.log('Succeeded in setting the content.'); 1395 }).catch((err: BusinessError) => { 1396 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1397 }); 1398} catch (err) { 1399 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1400} 1401``` 1402 1403### setUiContent<sup>10+</sup> 1404 1405setUiContent(path: string, storage: LocalStorage, callback: AsyncCallback\<void>): void 1406 1407Loads content from a page linked to LocalStorage to this input method panel. This API uses an asynchronous callback to return the result. 1408 1409**System capability**: SystemCapability.MiscServices.InputMethodFramework 1410 1411**Parameters** 1412 1413| Name | Type | Mandatory | Description | 1414| -------- | ---------------------- | ---- | -------- | 1415| path | string | Yes | Path of the page linked to LocalStorage. | 1416| 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.| 1417| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1418 1419**Error codes** 1420 1421For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1422 1423| ID| Error Message | 1424| -------- | ------------------------------------------------------- | 1425| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1426 1427**Example** 1428 1429```ts 1430import { BusinessError } from '@kit.BasicServicesKit'; 1431 1432let storage = new LocalStorage(); 1433storage.setOrCreate('storageSimpleProp',121); 1434try { 1435 panel.setUiContent('pages/page2/page2', storage, (err: BusinessError) => { 1436 if (err) { 1437 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1438 return; 1439 } 1440 console.log('Succeeded in setting the content.'); 1441 }); 1442} catch (err) { 1443 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1444} 1445``` 1446 1447### setUiContent<sup>10+</sup> 1448 1449setUiContent(path: string, storage: LocalStorage): Promise\<void> 1450 1451Loads content from a page linked to LocalStorage to this panel. This API uses a promise to return the result. 1452 1453**System capability**: SystemCapability.MiscServices.InputMethodFramework 1454 1455**Parameters** 1456 1457| Name | Type | Mandatory | Description | 1458| -------- | ---------------------- | ---- | -------- | 1459| path | string | Yes | Path of the page from which the content will be loaded. | 1460| 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.| 1461 1462**Return value** 1463 1464| Type | Description | 1465| ------- | ------------------------------ | 1466| Promise\<void> | Promise that returns no value. | 1467 1468**Error codes** 1469 1470For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1471 1472| ID| Error Message | 1473| -------- | ------------------------------------------------------- | 1474| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1475 1476**Example** 1477 1478```ts 1479import { BusinessError } from '@kit.BasicServicesKit'; 1480 1481let storage = new LocalStorage(); 1482storage.setOrCreate('storageSimpleProp',121); 1483try { 1484 panel.setUiContent('pages/page2/page2', storage).then(() => { 1485 console.log('Succeeded in setting the content.'); 1486 }).catch((err: BusinessError) => { 1487 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1488 }); 1489} catch (err) { 1490 console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); 1491} 1492``` 1493 1494### resize<sup>10+</sup> 1495 1496resize(width: number, height: number, callback: AsyncCallback\<void>): void 1497 1498Resizes this input method panel. This API uses an asynchronous callback to return the result. 1499 1500> **NOTE** 1501> 1502> The panel width cannot exceed the screen width, and the panel height cannot be 0.6 times higher than the screen height. 1503 1504**System capability**: SystemCapability.MiscServices.InputMethodFramework 1505 1506**Parameters** 1507 1508| Name | Type | Mandatory | Description | 1509| -------- | ---------------------- | ---- | -------- | 1510| width | number | Yes | Target width of the panel, in px.| 1511| height | number | Yes | Target height of the panel, in px.| 1512| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1513 1514**Error codes** 1515 1516For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1517 1518| ID| Error Message | 1519| -------- | ------------------------------------------------------- | 1520| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1521 1522**Example** 1523 1524```ts 1525import { BusinessError } from '@kit.BasicServicesKit'; 1526 1527try { 1528 panel.resize(500, 1000, (err: BusinessError) => { 1529 if (err) { 1530 console.error(`Failed to resize panel: ${JSON.stringify(err)}`); 1531 return; 1532 } 1533 console.log('Succeeded in changing the panel size.'); 1534 }); 1535} catch (err) { 1536 console.error(`Failed to resize panel: ${JSON.stringify(err)}`); 1537} 1538``` 1539 1540### resize<sup>10+</sup> 1541 1542resize(width: number, height: number): Promise\<void> 1543 1544Resizes this input method panel. This API uses a promise to return the result. 1545 1546> **NOTE** 1547> 1548> The panel width cannot exceed the screen width, and the panel height cannot be 0.6 times higher than the screen height. 1549 1550**System capability**: SystemCapability.MiscServices.InputMethodFramework 1551 1552**Parameters** 1553 1554| Name | Type | Mandatory| Description | 1555| -------- | ---------------------- | ---- | -------- | 1556| width | number | Yes | Target width of the panel, in px.| 1557| height | number | Yes | Target height of the panel, in px.| 1558 1559**Return value** 1560 1561| Type | Description | 1562| ------- | ------------------------------ | 1563| Promise\<void> | Promise that returns no value. | 1564 1565**Error codes** 1566 1567For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1568 1569| ID| Error Message | 1570| -------- | ------------------------------------------------------- | 1571| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1572 1573**Example** 1574 1575```ts 1576import { BusinessError } from '@kit.BasicServicesKit'; 1577 1578try { 1579 panel.resize(500, 1000).then(() => { 1580 console.log('Succeeded in changing the panel size.'); 1581 }).catch((err: BusinessError) => { 1582 console.error(`Failed to resize panel: ${JSON.stringify(err)}`); 1583 }); 1584} catch (err) { 1585 console.error(`Failed to resize panel: ${JSON.stringify(err)}`); 1586} 1587``` 1588 1589### moveTo<sup>10+</sup> 1590 1591moveTo(x: number, y: number, callback: AsyncCallback\<void>): void 1592 1593Moves 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. 1594 1595**System capability**: SystemCapability.MiscServices.InputMethodFramework 1596 1597**Parameters** 1598 1599| Name | Type | Mandatory| Description | 1600| -------- | ---------------------- | ---- | -------- | 1601| x | number | Yes | Distance to move along the x-axis, in px. A positive value indicates moving rightwards.| 1602| y | number | Yes | Distance to move along the y-axis, in px. A positive value indicates moving downwards.| 1603| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1604 1605**Error codes** 1606 1607For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1608 1609| ID| Error Message | 1610| -------- | ------------------------------------------------------- | 1611| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1612 1613**Example** 1614 1615```ts 1616import { BusinessError } from '@kit.BasicServicesKit'; 1617 1618try { 1619 panel.moveTo(300, 300, (err: BusinessError) =>{ 1620 if (err) { 1621 console.error(`Failed to move panel: ${JSON.stringify(err)}`); 1622 return; 1623 } 1624 console.log('Succeeded in moving the panel.'); 1625 }); 1626} catch (err) { 1627 console.error(`Failed to move panel: ${JSON.stringify(err)}`); 1628} 1629``` 1630 1631### moveTo<sup>10+</sup> 1632 1633moveTo(x: number, y: number): Promise\<void> 1634 1635Moves 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. 1636 1637**System capability**: SystemCapability.MiscServices.InputMethodFramework 1638 1639**Parameters** 1640 1641| Name | Type | Mandatory| Description | 1642| -------- | ---------------------- | ---- | -------- | 1643| x | number | Yes |Distance to move along the x-axis, in px. A positive value indicates moving rightwards.| 1644| y | number | Yes |Distance to move along the y-axis, in px. A positive value indicates moving downwards.| 1645 1646**Return value** 1647 1648| Type | Description | 1649| ------- | ------------------------------ | 1650| Promise\<void> | Promise that returns no value. | 1651 1652**Error codes** 1653 1654For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1655 1656| ID| Error Message | 1657| -------- | ------------------------------------------------------- | 1658| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1659 1660**Example** 1661 1662```ts 1663import { BusinessError } from '@kit.BasicServicesKit'; 1664 1665try { 1666 panel.moveTo(300, 300).then(() => { 1667 console.log('Succeeded in moving the panel.'); 1668 }).catch((err: BusinessError) => { 1669 console.error(`Failed to move panel: ${JSON.stringify(err)}`); 1670 }); 1671} catch (err) { 1672 console.error(`Failed to move panel: ${JSON.stringify(err)}`); 1673} 1674``` 1675 1676### show<sup>10+</sup> 1677 1678show(callback: AsyncCallback\<void>): void 1679 1680Shows 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. 1681 1682**System capability**: SystemCapability.MiscServices.InputMethodFramework 1683 1684**Parameters** 1685 1686| Name | Type | Mandatory| Description | 1687| -------- | ---------------------- | ---- | -------- | 1688| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1689 1690**Example** 1691 1692```ts 1693import { BusinessError } from '@kit.BasicServicesKit'; 1694 1695panel.show((err: BusinessError) => { 1696 if (err) { 1697 console.error(`Failed to show panel: ${JSON.stringify(err)}`); 1698 return; 1699 } 1700 console.log('Succeeded in showing the panel.'); 1701}); 1702``` 1703 1704### show<sup>10+</sup> 1705 1706show(): Promise\<void> 1707 1708Shows 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. 1709 1710**System capability**: SystemCapability.MiscServices.InputMethodFramework 1711 1712**Return value** 1713 1714| Type | Description | 1715| ------- | ------------------------------ | 1716| Promise\<void> | Promise that returns no value. | 1717 1718**Example** 1719 1720```ts 1721import { BusinessError } from '@kit.BasicServicesKit'; 1722 1723panel.show().then(() => { 1724 console.log('Succeeded in showing the panel.'); 1725}).catch((err: BusinessError) => { 1726 console.error(`Failed to show panel: ${JSON.stringify(err)}`); 1727}); 1728``` 1729 1730### hide<sup>10+</sup> 1731 1732hide(callback: AsyncCallback\<void>): void 1733 1734Hides this panel. This API uses an asynchronous callback to return the result. 1735 1736**System capability**: SystemCapability.MiscServices.InputMethodFramework 1737 1738**Parameters** 1739 1740| Name | Type | Mandatory| Description | 1741| -------- | ---------------------- | ---- | -------- | 1742| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 1743 1744**Example** 1745 1746```ts 1747import { BusinessError } from '@kit.BasicServicesKit'; 1748 1749panel.hide((err: BusinessError) => { 1750 if (err) { 1751 console.error(`Failed to hide panel: ${JSON.stringify(err)}`); 1752 return; 1753 } 1754 console.log('Succeeded in hiding the panel.'); 1755}); 1756``` 1757 1758### hide<sup>10+</sup> 1759 1760hide(): Promise\<void> 1761 1762Hides this panel. This API uses a promise to return the result. 1763 1764**System capability**: SystemCapability.MiscServices.InputMethodFramework 1765 1766**Return value** 1767 1768| Type | Description | 1769| ------- | ------------------------------ | 1770| Promise\<void> | Promise that returns no value. | 1771 1772**Example** 1773 1774```ts 1775import { BusinessError } from '@kit.BasicServicesKit'; 1776 1777panel.hide().then(() => { 1778 console.log('Succeeded in hiding the panel.'); 1779}).catch((err: BusinessError) => { 1780 console.error(`Failed to hide panel: ${JSON.stringify(err)}`); 1781}); 1782``` 1783 1784### adjustPanelRect<sup>12+</sup> 1785 1786adjustPanelRect(flag: PanelFlag, rect: PanelRect): void 1787 1788Adjusts the panel rectangle. 1789 1790**System capability**: SystemCapability.MiscServices.InputMethodFramework 1791 1792**Parameters** 1793 1794| Name | Type | Mandatory| Description | 1795| -------- | ---------------------- | ---- | -------- | 1796| flag | [PanelFlag](#panelflag10) | Yes| Type of the state of the target panel. It can be **FLG_FIXED** or **FLG_FLOATING**.| 1797| 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.| 1798 1799**Error codes** 1800 1801For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 1802 1803| ID| Error Message | 1804| -------- | ------------------------------------------------------- | 1805| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1806| 12800013 | window manager service error. | 1807 1808**Example** 1809 1810```ts 1811import { BusinessError } from '@kit.BasicServicesKit'; 1812 1813try { 1814 let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED; 1815 let panelRect:inputMethodEngine.PanelRect = { 1816 landscapeRect:{left:100, top:100, width:400, height:400}, 1817 portraitRect:{left:200, top:200, width:300, height:300} 1818 }; 1819 panel.adjustPanelRect(panelFlag, panelRect); 1820} catch(err) { 1821 console.error(`Failed to adjustPanelRect: ${JSON.stringify(err)}`); 1822} 1823``` 1824 1825### on('show')<sup>10+</sup> 1826 1827on(type: 'show', callback: () => void): void 1828 1829Enables listening for the show event of this panel. This API uses an asynchronous callback to return the result. 1830 1831**System capability**: SystemCapability.MiscServices.InputMethodFramework 1832 1833**Parameters** 1834 1835| Name | Type | Mandatory| Description | 1836| -------- | ---------------------- | ---- | -------- | 1837| type | string | Yes| Event type, which is **'show'**.| 1838| callback | () => void | Yes | Callback used to return the result.| 1839 1840**Example** 1841 1842```ts 1843try { 1844 panel.on('show', () => { 1845 console.log('Panel is showing.'); 1846 }); 1847} catch(err) { 1848 console.error(`Failed to show: ${JSON.stringify(err)}`); 1849} 1850``` 1851 1852### on('hide')<sup>10+</sup> 1853 1854on(type: 'hide', callback: () => void): void 1855 1856Enables listening for the hide event of this panel. This API uses an asynchronous callback to return the result. 1857 1858**System capability**: SystemCapability.MiscServices.InputMethodFramework 1859 1860**Parameters** 1861 1862| Name | Type | Mandatory| Description | 1863| -------- | ---------------------- | ---- | -------- | 1864| type | string | Yes| Event type, which is **'hide'**.| 1865| callback | () => void | Yes | Callback used to return the result.| 1866 1867**Example** 1868 1869```ts 1870try { 1871 panel.on('hide', () => { 1872 console.log('Panel is hiding.'); 1873 }); 1874} catch(err) { 1875 console.error(`Failed to hide: ${JSON.stringify(err)}`); 1876} 1877``` 1878 1879### on('sizeChange')<sup>12+</sup> 1880 1881on(type: 'sizeChange', callback: Callback<window.Size>): void; 1882 1883Enables listening for the panel size change. This API uses an asynchronous callback to return the result. 1884 1885>**NOTE** 1886> 1887> 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. 1888 1889**System capability**: SystemCapability.MiscServices.InputMethodFramework 1890 1891**Parameters** 1892 1893| Name | Type | Mandatory| Description | 1894| -------- | ---------------------- | ---- | -------- | 1895| type | string | Yes| Event type, which is **'sizeChange'**.| 1896| 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.| 1897 1898**Example** 1899 1900```ts 1901import { window } from '@kit.ArkUI'; 1902try { 1903 panel.on('sizeChange', (windowSize: window.Size) => { 1904 console.info(`panel is size changes, width: ${windowSize.width}, height: ${windowSize.height}`); 1905 }); 1906} catch(err) { 1907 console.error(`Failed to sizeChange: ${JSON.stringify(err)}`); 1908} 1909``` 1910 1911### off('show')<sup>10+</sup> 1912 1913off(type: 'show', callback?: () => void): void 1914 1915Disables listening for the show event of this panel. This API uses an asynchronous callback to return the result. 1916 1917**System capability**: SystemCapability.MiscServices.InputMethodFramework 1918 1919**Parameters** 1920 1921| Name | Type | Mandatory| Description | 1922| -------- | ---------------------- | ---- | -------- | 1923| type | string | Yes| Event type, which is **'show'**.| 1924| callback | () => void | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified type.| 1925 1926**Error codes** 1927 1928For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1929 1930| ID| Error Message | 1931| -------- | ------------------------------------------------------- | 1932| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1933 1934**Example** 1935 1936```ts 1937try { 1938 panel.off('show'); 1939} catch(err) { 1940 console.error(`Failed to show: ${JSON.stringify(err)}`); 1941} 1942``` 1943 1944### off('hide')<sup>10+</sup> 1945 1946off(type: 'hide', callback?: () => void): void 1947 1948Disables listening for the hide event of this panel. This API uses an asynchronous callback to return the result. 1949 1950**System capability**: SystemCapability.MiscServices.InputMethodFramework 1951 1952**Parameters** 1953 1954| Name | Type | Mandatory| Description | 1955| -------- | ---------------------- | ---- | -------- | 1956| type | string | Yes| Event type, which is **'hide'**.| 1957| callback | () => void | No | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified type.| 1958 1959**Error codes** 1960 1961For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 1962 1963| ID| Error Message | 1964| -------- | ------------------------------------------------------- | 1965| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1966 1967**Example** 1968 1969```ts 1970try { 1971 panel.off('hide'); 1972} catch(err) { 1973 console.error(`Failed to hide: ${JSON.stringify(err)}`); 1974} 1975``` 1976 1977### off('sizeChange')<sup>12+</sup> 1978 1979off(type: 'sizeChange', callback?: Callback<window.Size>): void; 1980 1981Disables listening for the panel size change. This API uses an asynchronous callback to return the result. 1982 1983**System capability**: SystemCapability.MiscServices.InputMethodFramework 1984 1985**Parameters** 1986 1987| Name | Type | Mandatory| Description | 1988| -------- | ---------------------- | ---- | -------- | 1989| type | string | Yes| Event type, which is **'sizeChange'**.| 1990| callback | Callback\<[window.Size](../apis-arkui/js-apis-window.md#size7)> | No | Callback used to return the size of the soft keyboard panel, including the width and height.| 1991 1992**Example** 1993 1994```ts 1995import { window } from '@kit.ArkUI'; 1996try { 1997 panel.off('sizeChange', (windowSize: window.Size) => { 1998 console.info(`panel is size changes, width: ${windowSize.width}, height: ${windowSize.height}`); 1999 }); 2000} catch(err) { 2001 console.error(`Failed to sizeChange: ${JSON.stringify(err)}`); 2002} 2003``` 2004 2005### changeFlag<sup>10+</sup> 2006 2007changeFlag(flag: PanelFlag): void 2008 2009Changes the state type of this input method panel. This API only works for [SOFT_KEYBOARD](#paneltype10) panels. 2010 2011**System capability**: SystemCapability.MiscServices.InputMethodFramework 2012 2013**Parameters** 2014 2015| Name | Type | Mandatory| Description | 2016| -------- | ---------------------- | ---- | -------- | 2017| flag | [PanelFlag](#panelflag10) | Yes| Type of the state of the target panel.| 2018 2019**Error codes** 2020 2021For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2022 2023| ID| Error Message | 2024| -------- | ------------------------------------------------------- | 2025| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2026 2027**Example** 2028 2029```ts 2030try { 2031 let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED; 2032 panel.changeFlag(panelFlag); 2033} catch(err) { 2034 console.error(`Failed to panelFlag: ${JSON.stringify(err)}`); 2035} 2036``` 2037 2038### setPrivacyMode<sup>11+</sup> 2039 2040setPrivacyMode(isPrivacyMode: boolean): void 2041 2042Sets the input method panel to privacy mode. In privacy mode, screenshot and screen recording are blocked. 2043 2044**Required permissions**: ohos.permission.PRIVACY_WINDOW 2045 2046**System capability**: SystemCapability.MiscServices.InputMethodFramework 2047 2048**Parameters** 2049 2050| Name | Type | Mandatory| Description | 2051| ------------- | ------- | ---- | ------------------ | 2052| isPrivacyMode | boolean | Yes | Whether to set the input method panel to privacy mode.| 2053 2054**Error codes** 2055 2056For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2057 2058| ID| Error Message | 2059| -------- | ------------------------------------------------------- | 2060| 201 | permissions check fails. | 2061| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2062 2063**Example** 2064 2065```ts 2066try { 2067 let isPrivacyMode = true; 2068 panel.setPrivacyMode(isPrivacyMode); 2069} catch(err) { 2070 console.error(`Failed to set privacy mode: ${JSON.stringify(err)}`); 2071} 2072``` 2073 2074## KeyboardController 2075 2076In 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. 2077 2078### hide<sup>9+</sup> 2079 2080hide(callback: AsyncCallback<void>): void 2081 2082Hides the keyboard. This API uses an asynchronous callback to return the result. 2083 2084**System capability**: SystemCapability.MiscServices.InputMethodFramework 2085 2086**Parameters** 2087 2088| Name | Type | Mandatory| Description | 2089| -------- | ---------------------- | ---- | -------- | 2090| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 2091 2092**Error codes** 2093 2094For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 2095 2096| ID| Error Message | 2097| -------- | -------------------------- | 2098| 12800003 | input method client error. | 2099 2100**Example** 2101 2102```ts 2103import { BusinessError } from '@kit.BasicServicesKit'; 2104 2105keyboardController.hide((err: BusinessError) => { 2106 if (err) { 2107 console.error(`Failed to hide: ${JSON.stringify(err)}`); 2108 return; 2109 } 2110 console.log('Succeeded in hiding keyboard.'); 2111}); 2112``` 2113 2114### hide<sup>9+</sup> 2115 2116hide(): Promise<void> 2117 2118Hides the keyboard. This API uses a promise to return the result. 2119 2120**System capability**: SystemCapability.MiscServices.InputMethodFramework 2121 2122**Return value** 2123 2124| Type | Description | 2125| ---------------- | ------------------------- | 2126| Promise<void> | Promise that returns no value.| 2127 2128**Error codes** 2129 2130For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 2131 2132| ID| Error Message | 2133| -------- | -------------------------- | 2134| 12800003 | input method client error. | 2135 2136**Example** 2137 2138```ts 2139import { BusinessError } from '@kit.BasicServicesKit'; 2140 2141keyboardController.hide().then(() => { 2142 console.log('Succeeded in hiding keyboard.'); 2143}).catch((err: BusinessError) => { 2144 console.log(`Failed to hide: ${JSON.stringify(err)}`); 2145}); 2146``` 2147 2148### hideKeyboard<sup>(deprecated)</sup> 2149 2150hideKeyboard(callback: AsyncCallback<void>): void 2151 2152Hides the keyboard. This API uses an asynchronous callback to return the result. 2153 2154> **NOTE** 2155> 2156> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9) instead. 2157 2158**System capability**: SystemCapability.MiscServices.InputMethodFramework 2159 2160**Parameters** 2161 2162| Name | Type | Mandatory| Description | 2163| -------- | ---------------------- | ---- | -------- | 2164| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 2165 2166**Example** 2167 2168```ts 2169import { BusinessError } from '@kit.BasicServicesKit'; 2170 2171keyboardController.hideKeyboard((err: BusinessError) => { 2172 if (err) { 2173 console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`); 2174 return; 2175 } 2176 console.log('Succeeded in hiding keyboard.'); 2177}); 2178``` 2179 2180### hideKeyboard<sup>(deprecated)</sup> 2181 2182hideKeyboard(): Promise<void> 2183 2184Hides the keyboard. This API uses a promise to return the result. 2185 2186> **NOTE** 2187> 2188> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9-1) instead. 2189 2190**System capability**: SystemCapability.MiscServices.InputMethodFramework 2191 2192**Return value** 2193 2194| Type | Description | 2195| ---------------- | ------------------------- | 2196| Promise<void> | Promise that returns no value.| 2197 2198**Example** 2199 2200```ts 2201import { BusinessError } from '@kit.BasicServicesKit'; 2202 2203keyboardController.hideKeyboard().then(() => { 2204 console.log('Succeeded in hiding keyboard.'); 2205}).catch((err: BusinessError) => { 2206 console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`); 2207}); 2208``` 2209 2210### exitCurrentInputType<sup>11+</sup> 2211 2212exitCurrentInputType(callback: AsyncCallback<void>): void 2213 2214Exits 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. 2215 2216**System capability**: SystemCapability.MiscServices.InputMethodFramework 2217 2218**Parameters** 2219 2220| Name | Type | Mandatory| Description | 2221| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 2222| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 2223 2224**Error codes** 2225 2226For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 2227 2228| ID| Error Message | 2229| -------- | ---------------------------------------------- | 2230| 12800008 | input method manager service error. | 2231| 12800010 | not the preconfigured default input method. | 2232 2233**Example** 2234 2235```ts 2236import { BusinessError } from '@kit.BasicServicesKit'; 2237 2238keyboardController.exitCurrentInputType((err: BusinessError) => { 2239 if (err) { 2240 console.error(`Failed to exitCurrentInputType: ${JSON.stringify(err)}`); 2241 return; 2242 } 2243 console.log('Succeeded in exiting current input type.'); 2244}); 2245``` 2246 2247### exitCurrentInputType<sup>11+</sup> 2248 2249exitCurrentInputType(): Promise<void> 2250 2251Exits this input type. This API can be called only by the preconfigured default input method. This API uses a promise to return the result. 2252 2253**System capability**: SystemCapability.MiscServices.InputMethodFramework 2254 2255**Return value** 2256 2257| Type | Description | 2258| ---------------- | ------------------------- | 2259| Promise<void> | Promise that returns no value.| 2260 2261**Error codes** 2262 2263For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 2264 2265| ID| Error Message | 2266| -------- | ---------------------------------------------- | 2267| 12800008 | input method manager service error. | 2268| 12800010 | not the preconfigured default input method. | 2269 2270**Example** 2271 2272```ts 2273import { BusinessError } from '@kit.BasicServicesKit'; 2274 2275keyboardController.exitCurrentInputType().then(() => { 2276 console.log('Succeeded in exiting current input type.'); 2277}).catch((err: BusinessError) => { 2278 console.log(`Failed to exit current input type: ${JSON.stringify(err)}`); 2279}); 2280``` 2281 2282## SecurityMode<sup>11+</sup> 2283 2284Describes the security mode. 2285 2286**System capability**: SystemCapability.MiscServices.InputMethodFramework 2287 2288| Name | Value | Description | 2289| ----- | ---- | -------------------------------------------- | 2290| BASIC | 0 | Basic access mode, where network access is restricted.| 2291| FULL | 1 | Full access mode, where network access is not restricted. | 2292 2293## ExtendAction<sup>10+</sup> 2294 2295Describes the type of the extended edit action on the text box. 2296 2297**System capability**: SystemCapability.MiscServices.InputMethodFramework 2298 2299| Name| Value|Description| 2300| -------- | -------- |-------- | 2301| SELECT_ALL | 0 |Select all.| 2302| CUT | 3 |Cut.| 2303| COPY | 4 |Copy.| 2304| PASTE | 5 |Paste.| 2305 2306## Direction<sup>10+</sup> 2307 2308Enumerates the directions of cursor movement of the input method. 2309 2310**System capability**: SystemCapability.MiscServices.InputMethodFramework 2311 2312| Name| Value|Description| 2313| -------- | -------- |-------- | 2314| CURSOR_UP | 1 |Upward.| 2315| CURSOR_DOWN | 2 |Downward.| 2316| CURSOR_LEFT | 3 |Leftward.| 2317| CURSOR_RIGHT | 4 |Rightward.| 2318 2319## Range<sup>10+</sup> 2320 2321Describes the range of the selected text. 2322 2323**System capability**: SystemCapability.MiscServices.InputMethodFramework 2324 2325| Name| Type| Read-Only| Optional| Description| 2326| -------- | -------- | -------- | -------- | -------- | 2327| start | number | No| No| Index of the first selected character in the text box.| 2328| end | number | No| No| Index of the last selected character in the text box.| 2329 2330## Movement<sup>10+</sup> 2331 2332Describes the direction in which the cursor moves when the text is selected. 2333 2334**System capability**: SystemCapability.MiscServices.InputMethodFramework 2335 2336| Name| Type| Read-Only| Optional| Description| 2337| -------- | -------- | -------- | -------- | -------- | 2338| direction | [Direction](#direction10) | No| No| Direction in which the cursor moves when the text is selected.| 2339 2340## InputClient<sup>9+</sup> 2341 2342In 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. 2343 2344### sendKeyFunction<sup>9+</sup> 2345 2346sendKeyFunction(action:number, callback: AsyncCallback<boolean>): void 2347 2348Sends the function key. This API uses an asynchronous callback to return the result. 2349 2350**System capability**: SystemCapability.MiscServices.InputMethodFramework 2351 2352 **Parameters** 2353 2354| Name| Type| Mandatory| Description| 2355| -------- | -------- | -------- | -------- | 2356| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).| 2357| 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.| 2358 2359**Error codes** 2360 2361For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2362 2363| ID| Error Message | 2364| -------- | -------------------------- | 2365| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2366| 12800003 | input method client error. | 2367 2368 **Example** 2369 2370```ts 2371import { BusinessError } from '@kit.BasicServicesKit'; 2372 2373let action = 1; 2374try { 2375 inputClient.sendKeyFunction(action, (err: BusinessError, result: boolean) => { 2376 if (err) { 2377 console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); 2378 return; 2379 } 2380 if (result) { 2381 console.log('Succeeded in sending key function.'); 2382 } else { 2383 console.error('Failed to sendKeyFunction.'); 2384 } 2385 }); 2386} catch (err) { 2387 console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); 2388} 2389``` 2390 2391### sendKeyFunction<sup>9+</sup> 2392 2393sendKeyFunction(action: number): Promise<boolean> 2394 2395Sends the function key. This API uses a promise to return the result. 2396 2397**System capability**: SystemCapability.MiscServices.InputMethodFramework 2398 2399**Parameters** 2400 2401| Name| Type| Mandatory| Description| 2402| -------- | -------- | -------- | -------- | 2403| action | number | Yes| Action of the function key.<br>**0**: invalid key.<br>**1**: confirm key (Enter key).| 2404 2405**Return value** 2406 2407| Type | Description | 2408| ------------------------------- | ------------------------------------------------------------ | 2409| Promise<boolean> | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.| 2410 2411**Error codes** 2412 2413For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2414 2415| ID| Error Message | 2416| -------- | -------------------------- | 2417| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2418| 12800003 | input method client error. | 2419 2420**Example** 2421 2422```ts 2423import { BusinessError } from '@kit.BasicServicesKit'; 2424 2425let action = 1; 2426try { 2427 inputClient.sendKeyFunction(action).then((result: boolean) => { 2428 if (result) { 2429 console.log('Succeeded in sending key function.'); 2430 } else { 2431 console.error('Failed to sendKeyFunction.'); 2432 } 2433 }).catch((err: BusinessError) => { 2434 console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); 2435 }); 2436} catch (err) { 2437 console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); 2438} 2439``` 2440 2441### getForward<sup>9+</sup> 2442 2443getForward(length:number, callback: AsyncCallback<string>): void 2444 2445Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result. 2446 2447**System capability**: SystemCapability.MiscServices.InputMethodFramework 2448 2449**Parameters** 2450 2451| Name| Type| Mandatory| Description| 2452| -------- | -------- | -------- | -------- | 2453| length | number | Yes| Text length, which cannot be less than 0.| 2454| 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.| 2455 2456**Error codes** 2457 2458For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2459 2460| ID| Error Message | 2461| -------- | ------------------------------ | 2462| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2463| 12800003 | input method client error. | 2464| 12800006 | Input method controller error. | 2465 2466**Example** 2467 2468```ts 2469import { BusinessError } from '@kit.BasicServicesKit'; 2470 2471let length = 1; 2472try { 2473 inputClient.getForward(length, (err: BusinessError, text: string) => { 2474 if (err) { 2475 console.error(`Failed to getForward: ${JSON.stringify(err)}`); 2476 return; 2477 } 2478 console.log('Succeeded in getting forward, text: ' + text); 2479 }); 2480} catch (err) { 2481 console.error(`Failed to getForward: ${JSON.stringify(err)}`); 2482} 2483``` 2484 2485### getForward<sup>9+</sup> 2486 2487getForward(length:number): Promise<string> 2488 2489Obtains the specific-length text before the cursor. This API uses a promise to return the result. 2490 2491**System capability**: SystemCapability.MiscServices.InputMethodFramework 2492 2493**Parameters** 2494 2495| Name| Type| Mandatory| Description| 2496| -------- | -------- | -------- | -------- | 2497| length | number | Yes| Text length, which cannot be less than 0.| 2498 2499**Return value** 2500 2501| Type | Description | 2502| ------------------------------- | ------------------------------------------------------------ | 2503| Promise<string> | Promise used to return the specific-length text before the cursor. | 2504 2505**Error codes** 2506 2507For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2508 2509| ID| Error Message | 2510| -------- | ------------------------------ | 2511| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2512| 12800003 | input method client error. | 2513| 12800006 | Input method controller error. | 2514 2515**Example** 2516 2517```ts 2518import { BusinessError } from '@kit.BasicServicesKit'; 2519 2520let length = 1; 2521try { 2522 inputClient.getForward(length).then((text: string) => { 2523 console.log('Succeeded in getting forward, text: ' + text); 2524 }).catch((err: BusinessError) => { 2525 console.error(`Failed to getForward: ${JSON.stringify(err)}`); 2526 }); 2527} catch (err) { 2528 console.error(`Failed to getForward: ${JSON.stringify(err)}`); 2529} 2530``` 2531 2532### getForwardSync<sup>10+</sup> 2533 2534getForwardSync(length:number): string 2535 2536Obtains the specific-length text before the cursor. 2537 2538**System capability**: SystemCapability.MiscServices.InputMethodFramework 2539 2540**Parameters** 2541 2542| Name| Type | Mandatory| Description | 2543| ------ | ------ | ---- | ---------- | 2544| length | number | Yes | Text length, which cannot be less than 0.| 2545 2546**Return value** 2547 2548| Type | Description | 2549| ------ | -------------------------- | 2550| string | Specific-length text before the cursor.| 2551 2552**Error codes** 2553 2554For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2555 2556| ID| Error Message | 2557| -------- | ------------------------------ | 2558| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2559| 12800003 | input method client error. | 2560| 12800006 | input method controller error. | 2561 2562**Example** 2563 2564```ts 2565let length = 1; 2566try { 2567 let text: string = inputClient.getForwardSync(length); 2568 console.log(`Succeeded in getting forward, text: ${text}`); 2569} catch (err) { 2570 console.error(`Failed to getForwardSync: ${JSON.stringify(err)}`); 2571} 2572``` 2573 2574### getBackward<sup>9+</sup> 2575 2576getBackward(length:number, callback: AsyncCallback<string>): void 2577 2578Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result. 2579 2580**System capability**: SystemCapability.MiscServices.InputMethodFramework 2581 2582**Parameters** 2583 2584| Name| Type| Mandatory| Description| 2585| -------- | -------- | -------- | -------- | 2586| length | number | Yes| Text length, which cannot be less than 0.| 2587| 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.| 2588 2589**Error codes** 2590 2591For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2592 2593| ID| Error Message | 2594| -------- | ------------------------------ | 2595| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2596| 12800003 | input method client error. | 2597| 12800006 | Input method controller error. | 2598 2599**Example** 2600 2601```ts 2602import { BusinessError } from '@kit.BasicServicesKit'; 2603 2604let length = 1; 2605try { 2606 inputClient.getBackward(length, (err: BusinessError, text: string) => { 2607 if (err) { 2608 console.error(`Failed to getBackward: ${JSON.stringify(err)}`); 2609 return; 2610 } 2611 console.log('Succeeded in getting backward, text: ' + text); 2612 }); 2613} catch (err) { 2614 console.error(`Failed to getBackward: ${JSON.stringify(err)}`); 2615} 2616``` 2617 2618### getBackward<sup>9+</sup> 2619 2620getBackward(length:number): Promise<string> 2621 2622Obtains the specific-length text after the cursor. This API uses a promise to return the result. 2623 2624**System capability**: SystemCapability.MiscServices.InputMethodFramework 2625 2626**Parameters** 2627 2628| Name| Type| Mandatory| Description| 2629| -------- | -------- | -------- | -------- | 2630| length | number | Yes| Text length, which cannot be less than 0.| 2631 2632**Return value** 2633 2634| Type | Description | 2635| ------------------------------- | ------------------------------------------------------------ | 2636| Promise<string> | Promise used to return the specific-length text after the cursor. | 2637 2638**Error codes** 2639 2640For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2641 2642| ID| Error Message | 2643| -------- | ------------------------------ | 2644| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2645| 12800003 | input method client error. | 2646| 12800006 | Input method controller error. | 2647 2648**Example** 2649 2650```ts 2651import { BusinessError } from '@kit.BasicServicesKit'; 2652 2653let length = 1; 2654try { 2655 inputClient.getBackward(length).then((text: string) => { 2656 console.log('Succeeded in getting backward, text: ' + text); 2657 }).catch((err: BusinessError) => { 2658 console.error(`Failed to getBackward: ${JSON.stringify(err)}`); 2659 }); 2660} catch (err) { 2661 console.error(`Failed to getBackward: ${JSON.stringify(err)}`); 2662} 2663``` 2664 2665### getBackwardSync<sup>10+</sup> 2666 2667getBackwardSync(length:number): string 2668 2669Obtains the specific-length text after the cursor. 2670 2671**System capability**: SystemCapability.MiscServices.InputMethodFramework 2672 2673**Parameters** 2674 2675| Name| Type | Mandatory| Description | 2676| ------ | ------ | ---- | ---------- | 2677| length | number | Yes | Text length, which cannot be less than 0.| 2678 2679**Return value** 2680 2681| Type | Description | 2682| ------ | -------------------------- | 2683| string | Specific-length text after the cursor.| 2684 2685**Error codes** 2686 2687For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2688 2689| ID| Error Message | 2690| -------- | ------------------------------ | 2691| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2692| 12800003 | input method client error. | 2693| 12800006 | input method controller error. | 2694 2695**Example** 2696 2697```ts 2698let length = 1; 2699try { 2700 let text: string = inputClient.getBackwardSync(length); 2701 console.log(`Succeeded in getting backward, text: ${text}`); 2702} catch (err) { 2703 console.error(`Failed to getBackwardSync: ${JSON.stringify(err)}`); 2704} 2705``` 2706 2707### deleteForward<sup>9+</sup> 2708 2709deleteForward(length:number, callback: AsyncCallback<boolean>): void 2710 2711Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result. 2712 2713**System capability**: SystemCapability.MiscServices.InputMethodFramework 2714 2715**Parameters** 2716 2717| Name| Type| Mandatory| Description| 2718| -------- | -------- | -------- | -------- | 2719| length | number | Yes| Text length, which cannot be less than 0.| 2720| 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.| 2721 2722**Error codes** 2723 2724For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2725 2726| ID| Error Message | 2727| -------- | -------------------------- | 2728| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2729| 12800002 | Input method engine error. | 2730| 12800003 | input method client error. | 2731 2732**Example** 2733 2734```ts 2735import { BusinessError } from '@kit.BasicServicesKit'; 2736 2737let length = 1; 2738try { 2739 inputClient.deleteForward(length, (err: BusinessError, result: boolean) => { 2740 if (err) { 2741 console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); 2742 return; 2743 } 2744 if (result) { 2745 console.log('Succeeded in deleting forward.'); 2746 } else { 2747 console.error(`Failed to deleteForward.`); 2748 } 2749 }); 2750} catch (err) { 2751 console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); 2752} 2753``` 2754 2755### deleteForward<sup>9+</sup> 2756 2757deleteForward(length:number): Promise<boolean> 2758 2759Deletes the fixed-length text before the cursor. This API uses a promise to return the result. 2760 2761**System capability**: SystemCapability.MiscServices.InputMethodFramework 2762 2763**Parameters** 2764 2765| Name| Type | Mandatory| Description | 2766| ------ | ------ | ---- | ---------- | 2767| length | number | Yes | Text length, which cannot be less than 0.| 2768 2769**Return value** 2770 2771| Type | Description | 2772| ---------------------- | -------------- | 2773| Promise<boolean> | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.| 2774 2775**Error codes** 2776 2777For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2778 2779| ID| Error Message | 2780| -------- | -------------------------- | 2781| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2782| 12800002 | Input method engine error. | 2783| 12800003 | input method client error. | 2784 2785**Example** 2786 2787```ts 2788import { BusinessError } from '@kit.BasicServicesKit'; 2789 2790let length = 1; 2791try { 2792 inputClient.deleteForward(length).then((result: boolean) => { 2793 if (result) { 2794 console.log('Succeeded in deleting forward.'); 2795 } else { 2796 console.error('Failed to delete Forward.'); 2797 } 2798 }).catch((err: BusinessError) => { 2799 console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); 2800 }); 2801} catch (err) { 2802 console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); 2803} 2804``` 2805 2806### deleteForwardSync<sup>10+</sup> 2807 2808deleteForwardSync(length:number): void 2809 2810Deletes the fixed-length text before the cursor. 2811 2812**System capability**: SystemCapability.MiscServices.InputMethodFramework 2813 2814**Parameters** 2815 2816| Name| Type | Mandatory| Description | 2817| ------ | ------ | ---- | ---------- | 2818| length | number | Yes | Text length, which cannot be less than 0.| 2819 2820**Error codes** 2821 2822For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2823 2824| ID| Error Message | 2825| -------- | -------------------------- | 2826| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2827| 12800002 | input method engine error. | 2828| 12800003 | input method client error. | 2829 2830**Example** 2831 2832```ts 2833let length = 1; 2834try { 2835 inputClient.deleteForwardSync(length); 2836 console.log('Succeeded in deleting forward.'); 2837} catch (err) { 2838 console.error('deleteForwardSync err: ' + JSON.stringify(err)); 2839} 2840``` 2841 2842### deleteBackward<sup>9+</sup> 2843 2844deleteBackward(length:number, callback: AsyncCallback<boolean>): void 2845 2846Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result. 2847 2848**System capability**: SystemCapability.MiscServices.InputMethodFramework 2849 2850**Parameters** 2851 2852| Name | Type | Mandatory| Description | 2853| -------- | ---------------------------- | ---- | -------------- | 2854| length | number | Yes | Text length, which cannot be less than 0. | 2855| 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.| 2856 2857**Error codes** 2858 2859For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2860 2861| ID| Error Message | 2862| -------- | -------------------------- | 2863| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2864| 12800002 | Input method engine error. | 2865| 12800003 | input method client error. | 2866 2867**Example** 2868 2869```ts 2870import { BusinessError } from '@kit.BasicServicesKit'; 2871 2872let length = 1; 2873try { 2874 inputClient.deleteBackward(length, (err: BusinessError, result: boolean) => { 2875 if (err) { 2876 console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); 2877 return; 2878 } 2879 if (result) { 2880 console.log('Succeeded in deleting backward.'); 2881 } else { 2882 console.error(`Failed to deleteBackward.`); 2883 } 2884 }); 2885} catch (err) { 2886 console.error('deleteBackward err: ' + JSON.stringify(err)); 2887} 2888``` 2889 2890### deleteBackward<sup>9+</sup> 2891 2892deleteBackward(length:number): Promise<boolean> 2893 2894Deletes the fixed-length text after the cursor. This API uses a promise to return the result. 2895 2896**System capability**: SystemCapability.MiscServices.InputMethodFramework 2897 2898**Parameters** 2899 2900| Name| Type| Mandatory| Description| 2901| -------- | -------- | -------- | -------- | 2902| length | number | Yes| Text length, which cannot be less than 0. | 2903 2904**Return value** 2905 2906| Type | Description | 2907| ------------------------------- | ------------------------------------------------------------ | 2908| Promise<boolean> | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.| 2909 2910**Error codes** 2911 2912For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2913 2914| ID| Error Message | 2915| -------- | -------------------------- | 2916| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2917| 12800002 | Input method engine error. | 2918| 12800003 | input method client error. | 2919 2920**Example** 2921 2922```ts 2923import { BusinessError } from '@kit.BasicServicesKit'; 2924 2925let length = 1; 2926inputClient.deleteBackward(length).then((result: boolean) => { 2927 if (result) { 2928 console.log('Succeeded in deleting backward.'); 2929 } else { 2930 console.error('Failed to deleteBackward.'); 2931 } 2932}).catch((err: BusinessError) => { 2933 console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); 2934}); 2935``` 2936 2937### deleteBackwardSync<sup>10+</sup> 2938 2939deleteBackwardSync(length:number): void 2940 2941Deletes the fixed-length text after the cursor. 2942 2943**System capability**: SystemCapability.MiscServices.InputMethodFramework 2944 2945**Parameters** 2946 2947| Name| Type | Mandatory| Description | 2948| ------ | ------ | ---- | ---------- | 2949| length | number | Yes | Text length, which cannot be less than 0. | 2950 2951**Error codes** 2952 2953For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2954 2955| ID| Error Message | 2956| -------- | -------------------------- | 2957| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2958| 12800002 | input method engine error. | 2959| 12800003 | input method client error. | 2960 2961**Example** 2962 2963```ts 2964let length = 1; 2965try { 2966 inputClient.deleteBackwardSync(length); 2967 console.log('Succeeded in deleting backward.'); 2968} catch (err) { 2969 console.error('deleteBackwardSync err: ' + JSON.stringify(err)); 2970} 2971``` 2972 2973### insertText<sup>9+</sup> 2974 2975insertText(text:string, callback: AsyncCallback<boolean>): void 2976 2977Inserts text. This API uses an asynchronous callback to return the result. 2978 2979**System capability**: SystemCapability.MiscServices.InputMethodFramework 2980 2981**Parameters** 2982 2983| Name| Type| Mandatory| Description| 2984| -------- | -------- | -------- | -------- | 2985| text | string | Yes| Text to insert.| 2986| 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.| 2987 2988**Error codes** 2989 2990For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 2991 2992| ID| Error Message | 2993| -------- | -------------------------- | 2994| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2995| 12800002 | Input method engine error. | 2996| 12800003 | input method client error. | 2997 2998**Example** 2999 3000```ts 3001import { BusinessError } from '@kit.BasicServicesKit'; 3002 3003inputClient.insertText('test', (err: BusinessError, result: boolean) => { 3004 if (err) { 3005 console.error(`Failed to insertText: ${JSON.stringify(err)}`); 3006 return; 3007 } 3008 if (result) { 3009 console.log('Succeeded in inserting text.'); 3010 } else { 3011 console.error('Failed to insertText.'); 3012 } 3013}); 3014``` 3015 3016### insertText<sup>9+</sup> 3017 3018insertText(text:string): Promise<boolean> 3019 3020Inserts text. This API uses a promise to return the result. 3021 3022**System capability**: SystemCapability.MiscServices.InputMethodFramework 3023 3024**Parameters** 3025 3026| Name| Type| Mandatory| Description| 3027| -------- | -------- | -------- | -------- | 3028| text | string | Yes| Text to insert.| 3029 3030**Return value** 3031 3032| Type | Description | 3033| ------------------------------- | ------------------------------------------------------------ | 3034| Promise<boolean> | Promise used to return the result. The value **true** means that the insertion is successful, and **false** means the opposite. | 3035 3036**Error codes** 3037 3038For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3039 3040| ID| Error Message | 3041| -------- | -------------------------- | 3042| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3043| 12800002 | Input method engine error. | 3044| 12800003 | input method client error. | 3045 3046**Example** 3047 3048```ts 3049import { BusinessError } from '@kit.BasicServicesKit'; 3050 3051try { 3052 inputClient.insertText('test').then((result: boolean) => { 3053 if (result) { 3054 console.log('Succeeded in inserting text.'); 3055 } else { 3056 console.error('Failed to insertText.'); 3057 } 3058 }).catch((err: BusinessError) => { 3059 console.error(`Failed to insertText: ${JSON.stringify(err)}`); 3060 }); 3061} catch (err) { 3062 console.error(`Failed to insertText: ${JSON.stringify(err)}`); 3063} 3064``` 3065 3066### insertTextSync<sup>10+</sup> 3067 3068insertTextSync(text: string): void 3069 3070Inserts text. 3071 3072**System capability**: SystemCapability.MiscServices.InputMethodFramework 3073 3074**Parameters** 3075 3076| Name| Type | Mandatory| Description | 3077| ------ | ------ | ---- | ---------- | 3078| text | string | Yes | Text to insert.| 3079 3080**Error codes** 3081 3082For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3083 3084| ID| Error Message | 3085| -------- | -------------------------- | 3086| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3087| 12800002 | input method engine error. | 3088| 12800003 | input method client error. | 3089 3090**Example** 3091 3092```ts 3093try { 3094 inputClient.insertTextSync('test'); 3095 console.log('Succeeded in inserting text.'); 3096} catch (err) { 3097 console.error(`Failed to insertTextSync: ${JSON.stringify(err)}`); 3098} 3099``` 3100 3101### getEditorAttribute<sup>9+</sup> 3102 3103getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void 3104 3105Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result. 3106 3107**System capability**: SystemCapability.MiscServices.InputMethodFramework 3108 3109**Parameters** 3110 3111| Name | Type | Mandatory | Description | 3112| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | 3113| 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.| 3114 3115**Error codes** 3116 3117For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3118 3119| ID| Error Message | 3120| -------- | -------------------------- | 3121| 12800003 | input method client error. | 3122 3123**Example** 3124 3125```ts 3126import { BusinessError } from '@kit.BasicServicesKit'; 3127 3128inputClient.getEditorAttribute((err: BusinessError, editorAttribute: inputMethodEngine.EditorAttribute) => { 3129 if (err) { 3130 console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); 3131 return; 3132 } 3133 console.log(`editorAttribute.inputPattern: ${editorAttribute.inputPattern}`); 3134 console.log(`editorAttribute.enterKeyType: ${editorAttribute.enterKeyType}`); 3135}); 3136``` 3137 3138### getEditorAttribute<sup>9+</sup> 3139 3140getEditorAttribute(): Promise<EditorAttribute> 3141 3142Obtains the attribute of the edit box. This API uses a promise to return the result. 3143 3144**System capability**: SystemCapability.MiscServices.InputMethodFramework 3145 3146**Return value** 3147 3148| Type | Description | 3149| ------------------------------- | ------------------------------------------------------------ | 3150| Promise<[EditorAttribute](#editorattribute)> | Promise used to return the attribute of the edit box. | 3151 3152**Error codes** 3153 3154For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3155 3156| ID| Error Message | 3157| -------- | -------------------------- | 3158| 12800003 | input method client error. | 3159 3160**Example** 3161 3162```ts 3163import { BusinessError } from '@kit.BasicServicesKit'; 3164 3165try { 3166 inputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => { 3167 console.log(`editorAttribute.inputPattern: ${editorAttribute.inputPattern}`); 3168 console.log(`editorAttribute.enterKeyType: ${editorAttribute.enterKeyType}`); 3169 }).catch((err: BusinessError) => { 3170 console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); 3171 }); 3172} catch(err) { 3173 console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); 3174} 3175``` 3176 3177### getEditorAttributeSync<sup>10+</sup> 3178 3179getEditorAttributeSync(): EditorAttribute 3180 3181Obtains the attribute of the edit box. 3182 3183**System capability**: SystemCapability.MiscServices.InputMethodFramework 3184 3185**Return value** 3186 3187| Type | Description | 3188| ----------------------------------- | -------------- | 3189| [EditorAttribute](#editorattribute) | Attribute object of the edit box.| 3190 3191**Error codes** 3192 3193For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3194 3195| ID| Error Message | 3196| -------- | -------------------------- | 3197| 12800003 | input method client error. | 3198 3199**Example** 3200 3201```ts 3202try { 3203 let editorAttribute: inputMethodEngine.EditorAttribute = inputClient.getEditorAttributeSync(); 3204 console.log(`editorAttribute.inputPattern: ${editorAttribute.inputPattern}`); 3205 console.log(`editorAttribute.enterKeyType: ${editorAttribute.enterKeyType}`); 3206} catch (err) { 3207 console.error(`Failed to getEditorAttributeSync: ${JSON.stringify(err)}`); 3208} 3209``` 3210 3211### moveCursor<sup>9+</sup> 3212 3213moveCursor(direction: number, callback: AsyncCallback<void>): void 3214 3215Moves the cursor. This API uses an asynchronous callback to return the result. 3216 3217**System capability**: SystemCapability.MiscServices.InputMethodFramework 3218 3219**Parameters** 3220 3221| Name | Type | Mandatory| Description | 3222| --------- | ------------------------- | ---- | -------------- | 3223| 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.| 3224| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. | 3225 3226**Error codes** 3227 3228For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3229 3230| ID| Error Message | 3231| -------- | -------------------------- | 3232| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3233| 12800003 | input method client error. | 3234 3235**Example** 3236 3237```ts 3238import { BusinessError } from '@kit.BasicServicesKit'; 3239 3240try { 3241 inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP, (err: BusinessError) => { 3242 if (err) { 3243 console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); 3244 return; 3245 } 3246 console.log('Succeeded in moving cursor.'); 3247 }); 3248} catch (err) { 3249 console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); 3250} 3251``` 3252 3253### moveCursor<sup>9+</sup> 3254 3255moveCursor(direction: number): Promise<void> 3256 3257Moves the cursor. This API uses a promise to return the result. 3258 3259**System capability**: SystemCapability.MiscServices.InputMethodFramework 3260 3261**Parameters** 3262 3263| Name | Type | Mandatory| Description | 3264| --------- | ------ | ---- | ------------------------------------------------------------ | 3265| 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.| 3266 3267**Return value** 3268 3269| Type | Description | 3270| ------------------- | ------------------------- | 3271| Promise<void> | Promise that returns no value.| 3272 3273**Error codes** 3274 3275For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3276 3277| ID| Error Message | 3278| -------- | -------------------------- | 3279| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3280| 12800003 | input method client error. | 3281 3282**Example** 3283 3284```ts 3285import { BusinessError } from '@kit.BasicServicesKit'; 3286 3287try { 3288 inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP).then(() => { 3289 console.log('Succeeded in moving cursor.'); 3290 }).catch((err: BusinessError) => { 3291 console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); 3292 }); 3293} catch (err) { 3294 console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); 3295} 3296``` 3297 3298### moveCursorSync<sup>10+</sup> 3299 3300moveCursorSync(direction: number): void 3301 3302Moves the cursor. 3303 3304**System capability**: SystemCapability.MiscServices.InputMethodFramework 3305 3306**Parameters** 3307 3308| Name | Type | Mandatory| Description | 3309| --------- | ------ | ---- | ------------------------------------------------------------ | 3310| 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.| 3311 3312**Error codes** 3313 3314For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3315 3316| ID| Error Message | 3317| -------- | -------------------------- | 3318| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3319| 12800003 | input method client error. | 3320 3321**Example** 3322 3323```ts 3324try { 3325 inputClient.moveCursorSync(inputMethodEngine.Direction.CURSOR_UP); 3326 console.log('Succeeded in moving cursor.'); 3327} catch (err) { 3328 console.error(`Failed to moveCursorSync: ${JSON.stringify(err)}`); 3329} 3330``` 3331 3332### selectByRange<sup>10+</sup> 3333 3334selectByRange(range: Range, callback: AsyncCallback<void>): void 3335 3336Selects text based on the specified range. This API uses an asynchronous callback to return the result. 3337 3338**System capability**: SystemCapability.MiscServices.InputMethodFramework 3339 3340**Parameters** 3341 3342| Name | Type | Mandatory| Description | 3343| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3344| range | [Range](#range10) | Yes | Range of the selected text. | 3345| 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.| 3346 3347**Error codes** 3348 3349For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3350 3351| ID| Error Message | 3352| -------- | -------------------------- | 3353| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3354| 12800003 | input method client error. | 3355 3356**Example** 3357 3358```ts 3359import { BusinessError } from '@kit.BasicServicesKit'; 3360 3361try { 3362 let range: inputMethodEngine.Range = { start: 0, end: 1 }; 3363 inputClient.selectByRange(range, (err: BusinessError) => { 3364 if (err) { 3365 console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); 3366 return; 3367 } 3368 console.log('Succeeded in selecting by range.'); 3369 }); 3370} catch (err) { 3371 console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); 3372} 3373``` 3374 3375### selectByRange<sup>10+</sup> 3376 3377selectByRange(range: Range): Promise<void> 3378 3379Selects text based on the specified range. This API uses a promise to return the result. 3380 3381**System capability**: SystemCapability.MiscServices.InputMethodFramework 3382 3383**Parameters** 3384 3385| Name| Type | Mandatory| Description | 3386| ------ | --------------------------------------------------------- | ---- | ---------------- | 3387| range | [Range](#range10) | Yes | Range of the selected text.| 3388 3389**Return value** 3390 3391| Type | Description | 3392| ------------------- | ------------------------- | 3393| Promise<void> | Promise that returns no value.| 3394 3395**Error codes** 3396 3397For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3398 3399| ID| Error Message | 3400| -------- | -------------------------- | 3401| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3402| 12800003 | input method client error. | 3403 3404**Example** 3405 3406```ts 3407import { BusinessError } from '@kit.BasicServicesKit'; 3408 3409try { 3410 let range: inputMethodEngine.Range = { start: 0, end: 1 }; 3411 inputClient.selectByRange(range).then(() => { 3412 console.log('Succeeded in selecting by range.'); 3413 }).catch((err: BusinessError) => { 3414 console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); 3415 }); 3416} catch (err) { 3417 console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); 3418} 3419``` 3420 3421### selectByRangeSync<sup>10+</sup> 3422 3423selectByRangeSync(range: Range): void 3424 3425Selects text based on the specified range. 3426 3427**System capability**: SystemCapability.MiscServices.InputMethodFramework 3428 3429**Parameters** 3430 3431| Name| Type | Mandatory| Description | 3432| ------ | ----------------- | ---- | ---------------- | 3433| range | [Range](#range10) | Yes | Range of the selected text.| 3434 3435**Error codes** 3436 3437For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3438 3439| ID| Error Message | 3440| -------- | -------------------------- | 3441| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3442| 12800003 | input method client error. | 3443 3444**Example** 3445 3446```ts 3447try { 3448 let range: inputMethodEngine.Range = { start: 0, end: 1 }; 3449 inputClient.selectByRangeSync(range); 3450 console.log('Succeeded in selecting by range.'); 3451} catch (err) { 3452 console.error(`Failed to selectByRangeSync: ${JSON.stringify(err)}`); 3453} 3454``` 3455 3456### selectByMovement<sup>10+</sup> 3457 3458selectByMovement(movement: Movement, callback: AsyncCallback<void>): void 3459 3460Selects text based on the cursor movement direction. This API uses an asynchronous callback to return the result. 3461 3462**System capability**: SystemCapability.MiscServices.InputMethodFramework 3463 3464**Parameters** 3465 3466| Name | Type | Mandatory| Description | 3467| -------- | ------ | ---- | ------ | 3468| movement | [Movement](#movement10) | Yes | Direction in which the cursor moves when the text is selected. | 3469| 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.| 3470 3471**Error codes** 3472 3473For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3474 3475| ID| Error Message | 3476| -------- | -------------------------- | 3477| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3478| 12800003 | input method client error. | 3479 3480**Example** 3481 3482```ts 3483import { BusinessError } from '@kit.BasicServicesKit'; 3484 3485try { 3486 let movement: inputMethodEngine.Movement = { direction: 1 }; 3487 inputClient.selectByMovement(movement, (err: BusinessError) => { 3488 if (err) { 3489 console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); 3490 return; 3491 } 3492 console.log('Succeeded in selecting by movement.'); 3493 }); 3494} catch (err) { 3495 console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); 3496} 3497``` 3498 3499### selectByMovement<sup>10+</sup> 3500 3501selectByMovement(movement: Movement): Promise<void> 3502 3503Selects text based on the specified range. This API uses a promise to return the result. 3504 3505**System capability**: SystemCapability.MiscServices.InputMethodFramework 3506 3507**Parameters** 3508 3509| Name | Type | Mandatory| Description | 3510| -------- | ------------------------------------------------------------ | ---- | ---------------------- | 3511| movement | [Movement](#movement10) | Yes | Direction in which the cursor moves when the text is selected.| 3512 3513**Return value** 3514 3515| Type | Description | 3516| ------------------- | ------------------------- | 3517| Promise<void> | Promise that returns no value.| 3518 3519**Error codes** 3520 3521For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3522 3523| ID| Error Message | 3524| -------- | -------------------------- | 3525| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3526| 12800003 | input method client error. | 3527 3528**Example** 3529 3530```ts 3531import { BusinessError } from '@kit.BasicServicesKit'; 3532 3533try { 3534 let movement: inputMethodEngine.Movement = { direction: 1 }; 3535 inputClient.selectByMovement(movement).then(() => { 3536 console.log('Succeeded in selecting by movement.'); 3537 }).catch((err: BusinessError) => { 3538 console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); 3539 }); 3540} catch (err) { 3541 console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); 3542} 3543``` 3544 3545### selectByMovementSync<sup>10+</sup> 3546 3547selectByMovementSync(movement: Movement): void 3548 3549Selects text based on the cursor movement direction. 3550 3551**System capability**: SystemCapability.MiscServices.InputMethodFramework 3552 3553**Parameters** 3554 3555| Name | Type | Mandatory| Description | 3556| -------- | ----------------------- | ---- | ---------------------- | 3557| movement | [Movement](#movement10) | Yes | Direction in which the cursor moves when the text is selected.| 3558 3559**Error codes** 3560 3561For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3562 3563| ID| Error Message | 3564| -------- | -------------------------- | 3565| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3566| 12800003 | input method client error. | 3567 3568**Example** 3569 3570```ts 3571try { 3572 let movement: inputMethodEngine.Movement = { direction: 1 }; 3573 inputClient.selectByMovementSync(movement); 3574 console.log('Succeeded in selecting by movement.'); 3575} catch (err) { 3576 console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); 3577} 3578``` 3579 3580### getTextIndexAtCursor<sup>10+</sup> 3581 3582getTextIndexAtCursor(callback: AsyncCallback<number>): void 3583 3584Obtains the index of the text where the cursor is located. This API uses an asynchronous callback to return the result. 3585 3586**System capability**: SystemCapability.MiscServices.InputMethodFramework 3587 3588**Parameters** 3589 3590| Name | Type | Mandatory| Description | 3591| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 3592| 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.| 3593 3594**Error codes** 3595 3596For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3597 3598| ID| Error Message | 3599| -------- | ------------------------------ | 3600| 12800003 | input method client error. | 3601| 12800006 | Input method controller error. | 3602 3603**Example** 3604 3605```ts 3606import { BusinessError } from '@kit.BasicServicesKit'; 3607 3608inputClient.getTextIndexAtCursor((err: BusinessError, index: number) => { 3609 if (err) { 3610 console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); 3611 return; 3612 } 3613 console.log('Succeeded in getTextIndexAtCursor: ' + index); 3614}); 3615``` 3616 3617### getTextIndexAtCursor<sup>10+</sup> 3618 3619getTextIndexAtCursor(): Promise<number> 3620 3621Obtains the index of the text where the cursor is located. This API uses a promise to return the result. 3622 3623**System capability**: SystemCapability.MiscServices.InputMethodFramework 3624 3625**Return value** 3626 3627| Type | Description | 3628| --------------------- | --------------------------------------- | 3629| Promise<number> | Promise used to return the result.| 3630 3631**Error codes** 3632 3633For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3634 3635| ID| Error Message | 3636| -------- | ------------------------------ | 3637| 12800003 | input method client error. | 3638| 12800006 | Input method controller error. | 3639 3640**Example** 3641 3642```ts 3643import { BusinessError } from '@kit.BasicServicesKit'; 3644 3645inputClient.getTextIndexAtCursor().then((index: number) => { 3646 console.log('Succeeded in getTextIndexAtCursor: ' + index); 3647}).catch((err: BusinessError) => { 3648 console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); 3649}); 3650``` 3651 3652### getTextIndexAtCursorSync<sup>10+</sup> 3653 3654getTextIndexAtCursorSync(): number 3655 3656Obtains the index of the text where the cursor is located. 3657 3658**System capability**: SystemCapability.MiscServices.InputMethodFramework 3659 3660**Return value** 3661 3662| Type | Description | 3663| ------ | -------------------------- | 3664| number | Index of the text where the cursor is located.| 3665 3666**Error codes** 3667 3668For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3669 3670| ID| Error Message | 3671| -------- | ------------------------------ | 3672| 12800003 | input method client error. | 3673| 12800006 | Input method controller error. | 3674 3675**Example** 3676 3677```ts 3678try{ 3679 let index: number = inputClient.getTextIndexAtCursorSync(); 3680 console.log(`Succeeded in getTextIndexAtCursorSync, index: ${index}`); 3681} catch (err) { 3682 console.error(`Failed to getTextIndexAtCursorSync: ${JSON.stringify(err)}`); 3683} 3684``` 3685 3686### sendExtendAction<sup>10+</sup> 3687 3688sendExtendAction(action: ExtendAction, callback: AsyncCallback<void>): void 3689 3690Sends an extended edit action. This API uses an asynchronous callback to return the result. 3691 3692> **NOTE** 3693> 3694> 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. 3695 3696**System capability**: SystemCapability.MiscServices.InputMethodFramework 3697 3698**Parameters** 3699 3700| Name | Type | Mandatory| Description | 3701| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 3702| action | [ExtendAction](#extendaction10) | Yes | Extended edit action to send.| 3703| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| 3704 3705**Error codes** 3706 3707For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3708 3709| ID| Error Message | 3710| -------- | ------------------------------ | 3711| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3712| 12800003 | input method client error. | 3713| 12800006 | Input method controller error. | 3714 3715**Example** 3716 3717```ts 3718import { BusinessError } from '@kit.BasicServicesKit'; 3719 3720try { 3721 inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err: BusinessError) => { 3722 if (err) { 3723 console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); 3724 return; 3725 } 3726 console.log('Succeeded in sending extend action.'); 3727 }); 3728} catch(err) { 3729 console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); 3730} 3731``` 3732 3733### sendExtendAction<sup>10+</sup> 3734 3735sendExtendAction(action: ExtendAction): Promise<void> 3736 3737Sends an extended edit action. This API uses a promise to return the result. 3738 3739>**NOTE** 3740> 3741> 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. 3742 3743**System capability**: SystemCapability.MiscServices.InputMethodFramework 3744 3745**Parameters** 3746 3747| Name| Type| Mandatory| Description| 3748| -------- | -------- | -------- | -------- | 3749| action | [ExtendAction](#extendaction10) | Yes| Extended edit action to send.| 3750 3751**Return value** 3752 3753| Type | Description | 3754| --------------------- | --------------------------------------- | 3755| Promise<void> | Promise that returns no value.| 3756 3757**Error codes** 3758 3759For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3760 3761| ID| Error Message | 3762| -------- | ------------------------------ | 3763| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3764| 12800003 | input method client error. | 3765| 12800006 | Input method controller error. | 3766 3767**Example** 3768 3769```ts 3770import { BusinessError } from '@kit.BasicServicesKit'; 3771 3772try { 3773 inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => { 3774 console.log('Succeeded in sending extend action.'); 3775 }).catch((err: BusinessError) => { 3776 console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); 3777 }); 3778} catch(err) { 3779 console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); 3780} 3781``` 3782 3783### sendPrivateCommand<sup>12+</sup> 3784 3785sendPrivateCommand(commandData: Record<string, CommandDataType>): Promise<void> 3786 3787Sends private data to the system component that needs to communicate with the input method application. 3788 3789>**NOTE** 3790> 3791> - 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. 3792> - The total size of the private data is 32 KB, and the maximum number of private data records is 5. 3793 3794**System capability**: SystemCapability.MiscServices.InputMethodFramework 3795 3796**Parameters** 3797 3798| Name | Type | Mandatory| Description | 3799| ----------- | ------------------------------- | ---- | ---------- | 3800| commandData | Record<string, [CommandDataType](#commanddatatype12)> | Yes | Private data to send.| 3801 3802**Return value** 3803 3804| Type | Description | 3805| ------------------- | ------------------------- | 3806| Promise<void> | Promise that returns no value.| 3807 3808**Error codes** 3809 3810For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3811 3812| ID| Error Message | 3813| -------- | ---------------------------------------------- | 3814| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3815| 12800003 | input method client error. | 3816| 12800010 | not the preconfigured default input method. | 3817 3818**Example** 3819 3820```ts 3821import { inputMethodEngine } from '@kit.IMEKit'; 3822import { BusinessError } from '@kit.BasicServicesKit'; 3823 3824inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, textInputClient) => { 3825 try { 3826 let record: Record<string, inputMethodEngine.CommandDataType> = { 3827 "valueString1": "abcdefg", 3828 "valueString2": true, 3829 "valueString3": 500, 3830 } 3831 textInputClient.sendPrivateCommand(record).then(() => { 3832 }).catch((err: BusinessError) => { 3833 if (err !== undefined) { 3834 let error = err as BusinessError; 3835 console.error(`sendPrivateCommand catch error: ${error.code} ${error.message}`); 3836 } 3837 }); 3838 } catch (err) { 3839 let error = err as BusinessError; 3840 console.error(`sendPrivateCommand catch error: ${error.code} ${error.message}`); 3841 } 3842}) 3843``` 3844 3845### getCallingWindowInfo<sup>12+</sup> 3846 3847getCallingWindowInfo(): Promise<WindowInfo> 3848 3849Obtains 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. 3850 3851>**NOTE** 3852> 3853>This API applies only to the input method applications that use [Panel](#panel10) as the soft keyboard window. 3854 3855**System capability**: SystemCapability.MiscServices.InputMethodFramework 3856 3857**Return value** 3858 3859| Type | Description | 3860| ------------------------------------------ | ----------------------------------------------------- | 3861| Promise<[WindowInfo](#windowinfo12)> | Promise used to return the information obtained.| 3862 3863**Error codes** 3864 3865For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3866 3867| ID| Error Message | 3868| -------- | --------------------------------- | 3869| 12800003 | input method client error. | 3870| 12800012 | the input method panel does not exist. | 3871| 12800013 | window manager service error. | 3872 3873**Example** 3874 3875```ts 3876import { BusinessError } from '@kit.BasicServicesKit'; 3877 3878try { 3879 inputClient.getCallingWindowInfo().then((windowInfo: inputMethodEngine.WindowInfo) => { 3880 console.log(`windowInfo.rect: ${JSON.stringify(windowInfo.rect)}`); 3881 console.log('windowInfo.status: ' + JSON.stringify(windowInfo.status)); 3882 }).catch((err: BusinessError) => { 3883 console.error(`Failed to getCallingWindowInfo: ${JSON.stringify(err)}`); 3884 }); 3885} catch(err) { 3886 console.error(`Failed to getCallingWindowInfo: ${JSON.stringify(err)}`); 3887} 3888``` 3889 3890### setPreviewText<sup>12+</sup> 3891 3892setPreviewText(text: string, range: Range): Promise<void> 3893 3894Sets the preview text. This API uses a promise to return the result. 3895 3896**System capability**: SystemCapability.MiscServices.InputMethodFramework 3897 3898**Parameters** 3899 3900| Name| Type | Mandatory| Description | 3901| ------ | ----------------- | ---- | ------------------------------------------------------------ | 3902| text | string | Yes | Preview text to set. | 3903| 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.| 3904 3905**Return value** 3906 3907| Type | Description | 3908| ------------------- | ------------------------- | 3909| Promise<void> | Promise that returns no value.| 3910 3911**Error codes** 3912 3913For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3914 3915| ID| Error Message | 3916| -------- | ------------------------------------------------------------ | 3917| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3918| 12800003 | input method client error. | 3919| 12800011 | text preview not supported. | 3920 3921**Example** 3922 3923```ts 3924import { BusinessError } from '@kit.BasicServicesKit'; 3925 3926try { 3927 let range: inputMethodEngine.Range = { start: 0, end: 1 }; 3928 inputClient.setPreviewText('test', range).then(() => { 3929 console.log('Succeeded in setting preview text.'); 3930 }).catch((err: BusinessError) => { 3931 console.error(`Failed to setPreviewText: ${JSON.stringify(err)}`); 3932 }); 3933} catch(err) { 3934 console.error(`Failed to setPreviewText: ${JSON.stringify(err)}`); 3935} 3936``` 3937 3938### setPreviewTextSync<sup>12+</sup> 3939 3940setPreviewTextSync(text: string, range: Range): void 3941 3942Sets the preview text. 3943 3944**System capability**: SystemCapability.MiscServices.InputMethodFramework 3945 3946**Parameters** 3947 3948| Name| Type | Mandatory| Description | 3949| ------ | ----------------- | ---- | ------------------------------------------------------------ | 3950| text | string | Yes | Preview text to set. | 3951| 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.| 3952 3953**Error codes** 3954 3955For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md). 3956 3957| ID| Error Message | 3958| -------- | ------------------------------------------------------------ | 3959| 401 | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3960| 12800003 | input method client error. | 3961| 12800011 | text preview not supported. | 3962 3963**Example** 3964 3965```ts 3966try { 3967 let range: inputMethodEngine.Range = { start: 0, end: 1 }; 3968 inputClient.setPreviewTextSync('test', range); 3969 console.log('Succeeded in setting preview text with synchronized method.'); 3970} catch (err) { 3971 console.error(`Failed to setPreviewTextSync: ${JSON.stringify(err)}`); 3972} 3973``` 3974 3975### finishTextPreview<sup>12+</sup> 3976 3977finishTextPreview(): Promise<void> 3978 3979Finishes the text preview. This API uses a promise to return the result. 3980 3981>**NOTE** 3982> 3983>If there is preview text in the current text box, calling this API will display the preview text on the screen. 3984 3985**System capability**: SystemCapability.MiscServices.InputMethodFramework 3986 3987**Return value** 3988 3989| Type | Description | 3990| ------------------- | ------------------------- | 3991| Promise<void> | Promise that returns no value.| 3992 3993**Error codes** 3994 3995For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 3996 3997| ID| Error Message | 3998| -------- | ------------------------------ | 3999| 12800003 | input method client error. | 4000| 12800011 | text preview not supported. | 4001 4002**Example** 4003 4004```ts 4005import { BusinessError } from '@kit.BasicServicesKit'; 4006 4007try { 4008 inputClient.finishTextPreview().then(() => { 4009 console.log('Succeeded in finishing text preview.'); 4010 }).catch((err: BusinessError) => { 4011 console.error(`Failed to finishTextPreview: ${JSON.stringify(err)}`); 4012 }); 4013} catch(err) { 4014 console.error(`Failed to finishTextPreview: ${JSON.stringify(err)}`); 4015} 4016``` 4017 4018### finishTextPreviewSync<sup>12+</sup> 4019 4020finishTextPreviewSync(): void 4021 4022Finishes the text preview. 4023 4024>**NOTE** 4025> 4026>If there is preview text in the current text box, calling this API will display the preview text on the screen. 4027 4028**System capability**: SystemCapability.MiscServices.InputMethodFramework 4029 4030**Error codes** 4031 4032For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md). 4033 4034| ID| Error Message | 4035| -------- | ------------------------------ | 4036| 12800003 | input method client error. | 4037| 12800011 | text preview not supported. | 4038 4039**Example** 4040 4041```ts 4042try { 4043 inputClient.finishTextPreviewSync(); 4044 console.log('Succeeded in finishing text preview with synchronized method.'); 4045} catch (err) { 4046 console.error(`Failed to finishTextPreviewSync: ${JSON.stringify(err)}`); 4047} 4048``` 4049 4050## EditorAttribute 4051 4052Represents the attributes of the edit box. 4053 4054**System capability**: SystemCapability.MiscServices.InputMethodFramework 4055 4056| Name | Type| Read-Only| Optional| Description | 4057| ------------ | -------- | ---- | ---- | ------------------ | 4058| enterKeyType | number | Yes | No | Function of the edit box.| 4059| inputPattern | number | Yes | No | Text of the edit box.| 4060| isTextPreviewSupported<sup>12+</sup> | boolean | No| No| Whether text preview is supported.| 4061| bundleName<sup>14+</sup> | string | Yes| Yes| Name of the application package to which the edit box belongs. The value may be **""** When this attribute is used, the scenario where the value is **""** must be considered.| 4062 4063## KeyEvent 4064 4065Represents the attributes of a key. 4066 4067**System capability**: SystemCapability.MiscServices.InputMethodFramework 4068 4069| Name | Type| Read-Only| Optional| Description | 4070| --------- | -------- | ---- | ---- | ------------ | 4071| keyCode | number | Yes | No | Key value. For details, see [KeyCode](../apis-input-kit/js-apis-keycode.md#keycode).| 4072| keyAction | number | Yes | No | Key event type.<br>- **2**: keydown event.<br>- **3**: keyup event.| 4073 4074## PanelFlag<sup>10+</sup> 4075 4076Enumerates the state types of the input method panel. 4077 4078**System capability**: SystemCapability.MiscServices.InputMethodFramework 4079 4080| Name | Value| Description | 4081| ------------ | -- | ------------------ | 4082| FLG_FIXED | 0 | Fixed state type.| 4083| FLG_FLOATING | 1 | Floating state type.| 4084 4085## PanelType<sup>10+</sup> 4086 4087Enumerates the types of the input method panel. 4088 4089**System capability**: SystemCapability.MiscServices.InputMethodFramework 4090 4091| Name | Value| Description | 4092| ------------ | -- | ------------------ | 4093| SOFT_KEYBOARD | 0 | Soft keyboard type.| 4094| STATUS_BAR | 1 | Status bar type.| 4095 4096## PanelInfo<sup>10+</sup> 4097 4098Describes the attributes of the input method panel. 4099 4100**System capability**: SystemCapability.MiscServices.InputMethodFramework 4101 4102| Name | Type| Read-Only| Optional| Description | 4103| --------- | -------- | ---- | ---- | ------------ | 4104| type | [PanelType](#paneltype10) | No | No | Type of the panel.| 4105| flag | [PanelFlag](#panelflag10) | No | Yes | State type of the panel.| 4106 4107## PanelRect<sup>12+</sup> 4108 4109Represents the size of the input method panel. 4110 4111**System capability**: SystemCapability.MiscServices.InputMethodFramework 4112 4113| Name | Type| Read-Only| Optional| Description | 4114| ------------ | -------- | ---- | ---- | ------------------ | 4115| landscapeRect | [window.Rect](../apis-arkui/js-apis-window.md#rect7) | No | No | Size of the input method panel window in landscape mode.| 4116| portraitRect | [window.Rect](../apis-arkui/js-apis-window.md#rect7) | No | No | Size of the input method panel window in portrait mode.| 4117 4118## WindowInfo<sup>12+</sup> 4119 4120Represents window information. 4121 4122**System capability**: SystemCapability.MiscServices.InputMethodFramework 4123 4124| Name | Type | Read-Only| Optional| Description | 4125| ------ | ------------------------------------------------------------ | ---- | ---- | -------------- | 4126| rect | [window.Rect](../apis-arkui/js-apis-window.md#rect7) | No | No | Rectangular area of the window.| 4127| status | [window.WindowStatusType](../apis-arkui/js-apis-window.md#windowstatustype11) | No | No | Window status type.| 4128 4129## TextInputClient<sup>(deprecated)</sup> 4130 4131> **NOTE** 4132> 4133> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [InputClient](#inputclient9) instead. 4134 4135In 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. 4136 4137### getForward<sup>(deprecated)</sup> 4138 4139getForward(length:number, callback: AsyncCallback<string>): void 4140 4141Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result. 4142 4143> **NOTE** 4144> 4145> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9) instead. 4146 4147**System capability**: SystemCapability.MiscServices.InputMethodFramework 4148 4149**Parameters** 4150 4151| Name| Type| Mandatory| Description| 4152| -------- | -------- | -------- | -------- | 4153| length | number | Yes| Text length, which cannot be less than 0.| 4154| 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.| 4155 4156**Example** 4157 4158```ts 4159import { BusinessError } from '@kit.BasicServicesKit'; 4160 4161let length = 1; 4162textInputClient.getForward(length, (err: BusinessError, text: string) => { 4163 if (err) { 4164 console.error(`Failed to getForward: ${JSON.stringify(err)}`); 4165 return; 4166 } 4167 console.log('Succeeded in getting forward, text: ' + text); 4168}); 4169``` 4170 4171### getForward<sup>(deprecated)</sup> 4172 4173getForward(length:number): Promise<string> 4174 4175Obtains the specific-length text before the cursor. This API uses a promise to return the result. 4176 4177> **NOTE** 4178> 4179> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9) instead. 4180 4181**System capability**: SystemCapability.MiscServices.InputMethodFramework 4182 4183**Parameters** 4184 4185| Name| Type| Mandatory| Description| 4186| -------- | -------- | -------- | -------- | 4187| length | number | Yes| Text length, which cannot be less than 0.| 4188 4189**Return value** 4190 4191| Type | Description | 4192| ------------------------------- | ------------------------------------------------------------ | 4193| Promise<string> | Promise used to return the specific-length text before the cursor. | 4194 4195**Example** 4196 4197```ts 4198import { BusinessError } from '@kit.BasicServicesKit'; 4199 4200let length = 1; 4201textInputClient.getForward(length).then((text: string) => { 4202 console.log('Succeeded in getting forward, text: ' + text); 4203}).catch((err: BusinessError) => { 4204 console.error(`Failed to getForward: ${JSON.stringify(err)}`); 4205}); 4206``` 4207 4208### getBackward<sup>(deprecated)</sup> 4209 4210getBackward(length:number, callback: AsyncCallback<string>): void 4211 4212Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result. 4213 4214> **NOTE** 4215> 4216> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9) instead. 4217 4218**System capability**: SystemCapability.MiscServices.InputMethodFramework 4219 4220**Parameters** 4221 4222| Name| Type| Mandatory| Description| 4223| -------- | -------- | -------- | -------- | 4224| length | number | Yes| Text length, which cannot be less than 0.| 4225| 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.| 4226 4227**Example** 4228 4229```ts 4230import { BusinessError } from '@kit.BasicServicesKit'; 4231 4232let length = 1; 4233textInputClient.getBackward(length, (err: BusinessError, text: string) => { 4234 if (err) { 4235 console.error(`Failed to getBackward: ${JSON.stringify(err)}`); 4236 return; 4237 } 4238 console.log('Succeeded in getting borward, text: ' + text); 4239}); 4240``` 4241 4242### getBackward<sup>(deprecated)</sup> 4243 4244getBackward(length:number): Promise<string> 4245 4246Obtains the specific-length text after the cursor. This API uses a promise to return the result. 4247 4248> **NOTE** 4249> 4250> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9) instead. 4251 4252**System capability**: SystemCapability.MiscServices.InputMethodFramework 4253 4254**Parameters** 4255 4256| Name| Type| Mandatory| Description| 4257| -------- | -------- | -------- | -------- | 4258| length | number | Yes| Text length, which cannot be less than 0.| 4259 4260**Return value** 4261 4262| Type | Description | 4263| ------------------------------- | ------------------------------------------------------------ | 4264| Promise<string> | Promise used to return the specific-length text after the cursor. | 4265 4266**Example** 4267 4268```ts 4269import { BusinessError } from '@kit.BasicServicesKit'; 4270 4271let length = 1; 4272textInputClient.getBackward(length).then((text: string) => { 4273 console.log('Succeeded in getting backward: ' + JSON.stringify(text)); 4274}).catch((err: BusinessError) => { 4275 console.error(`Failed to getBackward: ${JSON.stringify(err)}`); 4276}); 4277``` 4278 4279### deleteForward<sup>(deprecated)</sup> 4280 4281deleteForward(length:number, callback: AsyncCallback<boolean>): void 4282 4283Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result. 4284 4285> **NOTE** 4286> 4287> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9) instead. 4288 4289**System capability**: SystemCapability.MiscServices.InputMethodFramework 4290 4291**Parameters** 4292 4293| Name| Type| Mandatory| Description| 4294| -------- | -------- | -------- | -------- | 4295| length | number | Yes| Text length, which cannot be less than 0.| 4296| 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.| 4297 4298**Example** 4299 4300```ts 4301import { BusinessError } from '@kit.BasicServicesKit'; 4302 4303let length = 1; 4304textInputClient.deleteForward(length, (err: BusinessError, result: boolean) => { 4305 if (err) { 4306 console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); 4307 return; 4308 } 4309 if (result) { 4310 console.log('Succeeded in deleting forward.'); 4311 } else { 4312 console.error('Failed to deleteForward.'); 4313 } 4314}); 4315``` 4316 4317### deleteForward<sup>(deprecated)</sup> 4318 4319deleteForward(length:number): Promise<boolean> 4320 4321Deletes the fixed-length text before the cursor. This API uses a promise to return the result. 4322 4323> **NOTE** 4324> 4325> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9) instead. 4326 4327**System capability**: SystemCapability.MiscServices.InputMethodFramework 4328 4329**Parameters** 4330 4331| Name| Type | Mandatory| Description | 4332| ------ | ------ | ---- | ---------- | 4333| length | number | Yes | Text length, which cannot be less than 0.| 4334 4335**Return value** 4336 4337| Type | Description | 4338| ---------------------- | -------------- | 4339| Promise<boolean> | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.| 4340 4341**Example** 4342 4343```ts 4344import { BusinessError } from '@kit.BasicServicesKit'; 4345 4346let length = 1; 4347textInputClient.deleteForward(length).then((result: boolean) => { 4348 if (result) { 4349 console.log('Succeeded in deleting forward.'); 4350 } else { 4351 console.error('Failed to delete forward.'); 4352 } 4353}).catch((err: BusinessError) => { 4354 console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); 4355}); 4356``` 4357 4358### deleteBackward<sup>(deprecated)</sup> 4359 4360deleteBackward(length:number, callback: AsyncCallback<boolean>): void 4361 4362Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result. 4363 4364> **NOTE** 4365> 4366> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9) instead. 4367 4368**System capability**: SystemCapability.MiscServices.InputMethodFramework 4369 4370**Parameters** 4371 4372| Name | Type | Mandatory| Description | 4373| -------- | ---------------------------- | ---- | -------------- | 4374| length | number | Yes | Text length, which cannot be less than 0. | 4375| 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.| 4376 4377**Example** 4378 4379```ts 4380import { BusinessError } from '@kit.BasicServicesKit'; 4381 4382let length = 1; 4383textInputClient.deleteBackward(length, (err: BusinessError, result: boolean) => { 4384 if (err) { 4385 console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); 4386 return; 4387 } 4388 if (result) { 4389 console.log('Succeeded in deleting backward.'); 4390 } else { 4391 console.error('Failed to deleteBackward.'); 4392 } 4393}); 4394``` 4395 4396### deleteBackward<sup>(deprecated)</sup> 4397 4398deleteBackward(length:number): Promise<boolean> 4399 4400Deletes the fixed-length text after the cursor. This API uses a promise to return the result. 4401 4402> **NOTE** 4403> 4404> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9) instead. 4405 4406**System capability**: SystemCapability.MiscServices.InputMethodFramework 4407 4408**Parameters** 4409 4410| Name| Type| Mandatory| Description| 4411| -------- | -------- | -------- | -------- | 4412| length | number | Yes| Text length, which cannot be less than 0. | 4413 4414**Return value** 4415 4416| Type | Description | 4417| ------------------------------- | ------------------------------------------------------------ | 4418| Promise<boolean> | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.| 4419 4420**Example** 4421 4422```ts 4423import { BusinessError } from '@kit.BasicServicesKit'; 4424 4425let length = 1; 4426textInputClient.deleteBackward(length).then((result: boolean) => { 4427 if (result) { 4428 console.log('Succeeded in deleting backward.'); 4429 } else { 4430 console.error('Failed to deleteBackward.'); 4431 } 4432}).catch((err: BusinessError) => { 4433 console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); 4434}); 4435``` 4436### sendKeyFunction<sup>(deprecated)</sup> 4437 4438sendKeyFunction(action: number, callback: AsyncCallback<boolean>): void 4439 4440Sends the function key. This API uses an asynchronous callback to return the result. 4441 4442> **NOTE** 4443> 4444> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9) instead. 4445 4446**System capability**: SystemCapability.MiscServices.InputMethodFramework 4447 4448**Parameters** 4449 4450| Name| Type| Mandatory| Description| 4451| -------- | -------- | -------- | -------- | 4452| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).| 4453| 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.| 4454 4455**Example** 4456 4457```ts 4458import { BusinessError } from '@kit.BasicServicesKit'; 4459 4460let action = 1; 4461textInputClient.sendKeyFunction(action, (err: BusinessError, result: boolean) => { 4462 if (err) { 4463 console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); 4464 return; 4465 } 4466 if (result) { 4467 console.log('Succeeded in sending key function.'); 4468 } else { 4469 console.error('Failed to sendKeyFunction.'); 4470 } 4471}); 4472``` 4473 4474### sendKeyFunction<sup>(deprecated)</sup> 4475 4476sendKeyFunction(action: number): Promise<boolean> 4477 4478Sends the function key. This API uses a promise to return the result. 4479 4480> **NOTE** 4481> 4482> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9) instead. 4483 4484**System capability**: SystemCapability.MiscServices.InputMethodFramework 4485 4486**Parameters** 4487 4488| Name| Type| Mandatory| Description| 4489| -------- | -------- | -------- | -------- | 4490| action | number | Yes| Action of the function key.<br>**0**: invalid key.<br>**1**: confirm key (Enter key).| 4491 4492**Return value** 4493 4494| Type | Description | 4495| ------------------------------- | ------------------------------------------------------------ | 4496| Promise<boolean> | Promise used to return the result. The value **true** means that the setting is successful, and **false** means the opposite.| 4497 4498**Example** 4499 4500```ts 4501import { BusinessError } from '@kit.BasicServicesKit'; 4502 4503let action = 1; 4504textInputClient.sendKeyFunction(action).then((result: boolean) => { 4505 if (result) { 4506 console.log('Succeeded in sending key function.'); 4507 } else { 4508 console.error('Failed to sendKeyFunction.'); 4509 } 4510}).catch((err: BusinessError) => { 4511 console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); 4512}); 4513``` 4514 4515### insertText<sup>(deprecated)</sup> 4516 4517insertText(text:string, callback: AsyncCallback<boolean>): void 4518 4519Inserts text. This API uses an asynchronous callback to return the result. 4520 4521> **NOTE** 4522> 4523> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9) instead. 4524 4525**System capability**: SystemCapability.MiscServices.InputMethodFramework 4526 4527**Parameters** 4528 4529| Name| Type| Mandatory| Description| 4530| -------- | -------- | -------- | -------- | 4531| text | string | Yes| Text to insert.| 4532| 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.| 4533 4534**Example** 4535 4536```ts 4537import { BusinessError } from '@kit.BasicServicesKit'; 4538 4539textInputClient.insertText('test', (err: BusinessError, result: boolean) => { 4540 if (err) { 4541 console.error(`Failed to insertText: ${JSON.stringify(err)}`); 4542 return; 4543 } 4544 if (result) { 4545 console.log('Succeeded in inserting text.'); 4546 } else { 4547 console.error('Failed to insertText.'); 4548 } 4549}); 4550``` 4551 4552### insertText<sup>(deprecated)</sup> 4553 4554insertText(text:string): Promise<boolean> 4555 4556Inserts text. This API uses a promise to return the result. 4557 4558> **NOTE** 4559> 4560> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9) instead. 4561 4562**System capability**: SystemCapability.MiscServices.InputMethodFramework 4563 4564**Parameters** 4565 4566| Name| Type| Mandatory| Description| 4567| -------- | -------- | -------- | -------- | 4568| text | string | Yes| Text to insert.| 4569 4570**Return value** 4571 4572| Type | Description | 4573| ------------------------------- | ------------------------------------------------------------ | 4574| Promise<boolean> | Promise used to return the result. The value **true** means that the insertion is successful, and **false** means the opposite.| 4575 4576**Example** 4577 4578```ts 4579import { BusinessError } from '@kit.BasicServicesKit'; 4580 4581textInputClient.insertText('test').then((result: boolean) => { 4582 if (result) { 4583 console.log('Succeeded in inserting text.'); 4584 } else { 4585 console.error('Failed to insertText.'); 4586 } 4587}).catch((err: BusinessError) => { 4588 console.error(`Failed to insertText: ${JSON.stringify(err)}`); 4589}); 4590``` 4591 4592### getEditorAttribute<sup>(deprecated)</sup> 4593 4594getEditorAttribute(callback: AsyncCallback<EditorAttribute>): void 4595 4596Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result. 4597 4598> **NOTE** 4599> 4600> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9) instead. 4601 4602**System capability**: SystemCapability.MiscServices.InputMethodFramework 4603 4604**Parameters** 4605 4606| Name | Type | Mandatory | Description | 4607| -------- | ----- | ----- | ----- | 4608| 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.| 4609 4610**Example** 4611 4612```ts 4613import { BusinessError } from '@kit.BasicServicesKit'; 4614 4615textInputClient.getEditorAttribute((err: BusinessError, editorAttribute: inputMethodEngine.EditorAttribute) => { 4616 if (err) { 4617 console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); 4618 return; 4619 } 4620 console.log(`editorAttribute.inputPattern: ${editorAttribute.inputPattern}`; 4621 console.log(`editorAttribute.enterKeyType: ${editorAttribute.enterKeyType}`); 4622}); 4623``` 4624 4625### getEditorAttribute<sup>(deprecated)</sup> 4626 4627getEditorAttribute(): Promise<EditorAttribute> 4628 4629Obtains the attribute of the edit box. This API uses a promise to return the result. 4630 4631> **NOTE** 4632> 4633> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9) instead. 4634 4635**System capability**: SystemCapability.MiscServices.InputMethodFramework 4636 4637**Return value** 4638 4639| Type | Description | 4640| ------------------------------- | ------------------------------------------------------------ | 4641| Promise<[EditorAttribute](#editorattribute)> | Promise used to return the attribute of the edit box. | 4642 4643**Example** 4644 4645```ts 4646import { BusinessError } from '@kit.BasicServicesKit'; 4647 4648textInputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => { 4649 console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); 4650 console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); 4651}).catch((err: BusinessError) => { 4652 console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); 4653}); 4654``` 4655 4656