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