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