• 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.7 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.7 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) and [Universal Error Codes](../errorcode-universal.md).
1700
1701| ID| Error Message                                               |
1702| -------- | ------------------------------------------------------- |
1703| 801 | capability not supported. |
1704| 12800002 | input method engine error. |
1705| 12800013 | window manager service error. |
1706| 12800017 | invalid panel type or panel flag. |
1707
1708**Example**
1709
1710```ts
1711
1712try {
1713  panel.startMoving();
1714  console.log('Succeeded in moving the panel.');
1715} catch (err) {
1716  console.error(`Failed to move panel: ${JSON.stringify(err)}`);
1717}
1718```
1719
1720### getDisplayId<sup>15+</sup>
1721
1722getDisplayId(): Promise\<number>
1723
1724Obtains the window ID. This API uses a promise to return the result.
1725
1726**System capability**: SystemCapability.MiscServices.InputMethodFramework
1727
1728**Return value**
1729
1730| Type  | Description                            |
1731| ------- | ------------------------------ |
1732|Promise\<number>| Promise used to return the result. Returns the **displayId** of the window. |
1733
1734**Error codes**
1735
1736For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1737
1738| ID| Error Message                                               |
1739| -------- | ------------------------------------------------------- |
1740| 12800002 | input method engine error. |
1741| 12800013 | window manager service error. |
1742
1743**Example**
1744
1745```ts
1746import { BusinessError } from '@kit.BasicServicesKit';
1747
1748try {
1749  panel.getDisplayId().then((result: number) => {
1750    console.log('get displayId:' + result);
1751  }).catch((err: BusinessError) => {
1752    console.error(`Failed to get displayId: ${JSON.stringify(err)}`);
1753  });
1754} catch (err) {
1755  console.error(`Failed to get displayId: ${JSON.stringify(err)}`);
1756}
1757```
1758
1759### show<sup>10+</sup>
1760
1761show(callback: AsyncCallback\<void>): void
1762
1763Shows 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.
1764
1765**System capability**: SystemCapability.MiscServices.InputMethodFramework
1766
1767**Parameters**
1768
1769| Name  | Type                  | Mandatory| Description    |
1770| -------- | ---------------------- | ---- | -------- |
1771| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1772
1773**Example**
1774
1775```ts
1776import { BusinessError } from '@kit.BasicServicesKit';
1777
1778panel.show((err: BusinessError) => {
1779  if (err) {
1780    console.error(`Failed to show panel: ${JSON.stringify(err)}`);
1781    return;
1782  }
1783  console.log('Succeeded in showing the panel.');
1784});
1785```
1786
1787### show<sup>10+</sup>
1788
1789show(): Promise\<void>
1790
1791Shows 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.
1792
1793**System capability**: SystemCapability.MiscServices.InputMethodFramework
1794
1795**Return value**
1796
1797| Type  | Description                            |
1798| ------- | ------------------------------ |
1799| Promise\<void> | Promise that returns no value. |
1800
1801**Example**
1802
1803```ts
1804import { BusinessError } from '@kit.BasicServicesKit';
1805
1806panel.show().then(() => {
1807  console.log('Succeeded in showing the panel.');
1808}).catch((err: BusinessError) => {
1809  console.error(`Failed to show panel: ${JSON.stringify(err)}`);
1810});
1811```
1812
1813### hide<sup>10+</sup>
1814
1815hide(callback: AsyncCallback\<void>): void
1816
1817Hides this panel. This API uses an asynchronous callback to return the result.
1818
1819**System capability**: SystemCapability.MiscServices.InputMethodFramework
1820
1821**Parameters**
1822
1823| Name  | Type                  | Mandatory| Description    |
1824| -------- | ---------------------- | ---- | -------- |
1825| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1826
1827**Example**
1828
1829```ts
1830import { BusinessError } from '@kit.BasicServicesKit';
1831
1832panel.hide((err: BusinessError) => {
1833  if (err) {
1834    console.error(`Failed to hide panel: ${JSON.stringify(err)}`);
1835    return;
1836  }
1837  console.log('Succeeded in hiding the panel.');
1838});
1839```
1840
1841### hide<sup>10+</sup>
1842
1843hide(): Promise\<void>
1844
1845Hides this panel. This API uses a promise to return the result.
1846
1847**System capability**: SystemCapability.MiscServices.InputMethodFramework
1848
1849**Return value**
1850
1851| Type  | Description                            |
1852| ------- | ------------------------------ |
1853| Promise\<void> | Promise that returns no value. |
1854
1855**Example**
1856
1857```ts
1858import { BusinessError } from '@kit.BasicServicesKit';
1859
1860panel.hide().then(() => {
1861  console.log('Succeeded in hiding the panel.');
1862}).catch((err: BusinessError) => {
1863  console.error(`Failed to hide panel: ${JSON.stringify(err)}`);
1864});
1865```
1866
1867### adjustPanelRect<sup>12+</sup>
1868
1869adjustPanelRect(flag: PanelFlag, rect: PanelRect): void
1870
1871Adjusts the panel rectangle. After the API is called, the adjust request is submitted to the input method framework, but the execution is not complete.
1872
1873**System capability**: SystemCapability.MiscServices.InputMethodFramework
1874
1875**Parameters**
1876
1877| Name  | Type                  | Mandatory| Description    |
1878| -------- | ---------------------- | ---- | -------- |
1879| flag | [PanelFlag](#panelflag10) | Yes| Type of the state of the target panel. It can be **FLG_FIXED** or **FLG_FLOATING**.|
1880| 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.|
1881
1882**Error codes**
1883
1884For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1885
1886| ID| Error Message                                               |
1887| -------- | ------------------------------------------------------- |
1888| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1889| 12800013 | window manager service error. |
1890
1891**Example**
1892
1893```ts
1894import { BusinessError } from '@kit.BasicServicesKit';
1895
1896try {
1897  let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED;
1898  let panelRect:inputMethodEngine.PanelRect = {
1899    landscapeRect:{left:100, top:100, width:400, height:400},
1900    portraitRect:{left:200, top:200, width:300, height:300}
1901  };
1902  panel.adjustPanelRect(panelFlag, panelRect);
1903} catch(err) {
1904  console.error(`Failed to adjustPanelRect: ${JSON.stringify(err)}`);
1905}
1906```
1907
1908### adjustPanelRect<sup>15+</sup>
1909
1910adjustPanelRect(flag: PanelFlag, rect: EnhancedPanelRect): void
1911
1912Adjusts the panel rectangle, and customizes the avoid area and touch area.
1913
1914> **NOTE**
1915>
1916> 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.
1917>
1918> This API returns the result synchronously. The return only indicates that the system receives the setting request, not that the setting is complete.
1919
1920**System capability**: SystemCapability.MiscServices.InputMethodFramework
1921
1922**Parameters**
1923
1924| Name| Type                                     | Mandatory| Description                                                      |
1925| ------ | ----------------------------------------- | ---- | ---------------------------------------------------------- |
1926| flag   | [PanelFlag](#panelflag10)                 | Yes  | Type of the state of the target panel. It can be **FLG_FIXED** or **FLG_FLOATING**.         |
1927| rect   | [EnhancedPanelRect](#enhancedpanelrect15) | Yes  | The target panel rectangle, avoid area, and touch area.|
1928
1929**Error codes**
1930
1931For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1932
1933| ID| Error Message                                                    |
1934| -------- | ------------------------------------------------------------ |
1935| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1936| 12800013 | window manager service error.                                |
1937| 12800017 | invalid panel type or panel flag.                            |
1938
1939**Example**
1940
1941```ts
1942import { BusinessError } from '@kit.BasicServicesKit';
1943
1944try {
1945  let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED;
1946  let panelRect:inputMethodEngine.EnhancedPanelRect = {
1947    landscapeAvoidY: 650,
1948    landscapeInputRegion: [{left:300, top:650, width:2000, height:500}],
1949    portraitAvoidY: 1800,
1950    portraitInputRegion: [{left:0, top:1800, width:1200, height:800}],
1951    fullScreenMode: true
1952  };
1953  panel.adjustPanelRect(panelFlag, panelRect);
1954} catch(err) {
1955  console.error(`Failed to adjustPanelRect: ${JSON.stringify(err)}`);
1956}
1957```
1958
1959### updatelnputRegion<sup>15+</sup>
1960
1961updateRegion(inputRegion: Array&lt;window.Rect&gt;): void
1962
1963Updates the hot zone on the input method panel in the current state.
1964
1965> **NOTE**
1966>
1967> This API applies only to the panels of the **SOFT_KEYBOARD** type in the **FLG_FIXED** or **FLG_FLOATING** state.
1968>
1969> 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.
1970
1971**System capability**: SystemCapability.MiscServices.InputMethodFramework
1972
1973**Parameters**
1974
1975| Name     | Type                                                        | Mandatory| Description                                                        |
1976| ----------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1977| 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.|
1978
1979**Error codes**
1980
1981For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1982
1983| ID| Error Message                                                    |
1984| -------- | ------------------------------------------------------------ |
1985| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1986| 12800013 | window manager service error.                                |
1987| 12800017 | invalid panel type or panel flag.                            |
1988
1989**Example**
1990
1991```ts
1992import { BusinessError } from '@kit.BasicServicesKit';
1993import { window } from '@kit.ArkUI';
1994
1995try {
1996  let inputRegion: Array<window.Rect> = [{left:300, top:650, width:2000, height:500}];
1997  panel.updateRegion(inputRegion);
1998} catch(err) {
1999  console.error(`Failed to updateRegion: ${JSON.stringify(err)}`);
2000}
2001```
2002
2003### on('show')<sup>10+</sup>
2004
2005on(type: 'show', callback: () => void): void
2006
2007Enables listening for the show event of this panel. This API uses an asynchronous callback to return the result.
2008
2009**System capability**: SystemCapability.MiscServices.InputMethodFramework
2010
2011**Parameters**
2012
2013| Name  | Type                  | Mandatory| Description    |
2014| -------- | ---------------------- | ---- | -------- |
2015| type | string | Yes| Event type, which is **'show'**.|
2016| callback | () => void | Yes  | Callback used to return the result.|
2017
2018**Example**
2019
2020```ts
2021try {
2022  panel.on('show', () => {
2023    console.log('Panel is showing.');
2024  });
2025} catch(err) {
2026    console.error(`Failed to show: ${JSON.stringify(err)}`);
2027}
2028```
2029
2030### on('hide')<sup>10+</sup>
2031
2032on(type: 'hide', callback: () => void): void
2033
2034Enables listening for the hide event of this panel. This API uses an asynchronous callback to return the result.
2035
2036**System capability**: SystemCapability.MiscServices.InputMethodFramework
2037
2038**Parameters**
2039
2040| Name  | Type                  | Mandatory| Description    |
2041| -------- | ---------------------- | ---- | -------- |
2042| type | string | Yes| Event type, which is **'hide'**.|
2043| callback | () => void | Yes  | Callback used to return the result.|
2044
2045**Example**
2046
2047```ts
2048try {
2049  panel.on('hide', () => {
2050    console.log('Panel is hiding.');
2051  });
2052} catch(err) {
2053    console.error(`Failed to hide: ${JSON.stringify(err)}`);
2054}
2055```
2056
2057### on('sizeChange')<sup>12+</sup>
2058
2059on(type: 'sizeChange', callback: SizeChangeCallback): void
2060
2061Enables listening for the panel size change. This API uses an asynchronous callback to return the result.
2062
2063> **NOTE**
2064>
2065> 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.
2066>
2067>-  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.
2068>-  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.
2069
2070**System capability**: SystemCapability.MiscServices.InputMethodFramework
2071
2072**Parameters**
2073
2074| Name  | Type                                       | Mandatory| Description                                                  |
2075| -------- | ------------------------------------------- | ---- | ------------------------------------------------------ |
2076| type     | string                                      | Yes  | Event type, which is **'sizeChange'**.|
2077| callback | [SizeChangeCallback](#sizechangecallback15) | Yes  | Callback used to return the size of the soft keyboard panel, including the width and height.|
2078
2079**Example**
2080
2081```ts
2082import { window } from '@kit.ArkUI';
2083try {
2084  panel.on('sizeChange', (windowSize: window.Size) => {
2085    console.info(`panel size changed, width: ${windowSize.width}, height: ${windowSize.height}`);
2086  });
2087} catch(err) {
2088  console.error(`Failed to subscribe sizeChange: ${JSON.stringify(err)}`);
2089}
2090try {
2091  panel.on('sizeChange', (windowSize: window.Size, keyboardArea: inputMethodEngine.KeyboardArea) => {
2092    console.info(`panel size changed, windowSize: ${JSON.stringify(windowSize)}, keyboardArea: ${JSON.stringify(keyboardArea)}`);
2093  });
2094} catch(err) {
2095  console.error(`Failed to subscribe sizeChange: ${JSON.stringify(err)}`);
2096}
2097```
2098
2099### off('show')<sup>10+</sup>
2100
2101off(type: 'show', callback?: () => void): void
2102
2103Disables listening for the show event of this panel. This API uses an asynchronous callback to return the result.
2104
2105**System capability**: SystemCapability.MiscServices.InputMethodFramework
2106
2107**Parameters**
2108
2109| Name  | Type                  | Mandatory| Description    |
2110| -------- | ---------------------- | ---- | -------- |
2111| type | string | Yes| Event type, which is **'show'**.|
2112| callback | () => void | No  | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified type.|
2113
2114**Error codes**
2115
2116For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2117
2118| ID| Error Message                                               |
2119| -------- | ------------------------------------------------------- |
2120| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2121
2122**Example**
2123
2124```ts
2125try {
2126  panel.off('show');
2127} catch(err) {
2128    console.error(`Failed to show: ${JSON.stringify(err)}`);
2129}
2130```
2131
2132### off('hide')<sup>10+</sup>
2133
2134off(type: 'hide', callback?: () => void): void
2135
2136Disables listening for the hide event of this panel. This API uses an asynchronous callback to return the result.
2137
2138**System capability**: SystemCapability.MiscServices.InputMethodFramework
2139
2140**Parameters**
2141
2142| Name  | Type                  | Mandatory| Description    |
2143| -------- | ---------------------- | ---- | -------- |
2144| type | string | Yes| Event type, which is **'hide'**.|
2145| callback | () => void | No  | Callback to unregister. If this parameter is not specified, this API unregisters all callbacks for the specified type.|
2146
2147**Error codes**
2148
2149For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2150
2151| ID| Error Message                                               |
2152| -------- | ------------------------------------------------------- |
2153| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2154
2155**Example**
2156
2157```ts
2158try {
2159  panel.off('hide');
2160} catch(err) {
2161    console.error(`Failed to hide: ${JSON.stringify(err)}`);
2162}
2163```
2164
2165### off('sizeChange')<sup>12+</sup>
2166
2167off(type: 'sizeChange', callback?: SizeChangeCallback): void
2168
2169Disables listening for the panel size change. This API uses an asynchronous callback to return the result.
2170
2171> **NOTE**
2172>
2173> 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.
2174>
2175>-  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.
2176>-  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.
2177
2178**System capability**: SystemCapability.MiscServices.InputMethodFramework
2179
2180**Parameters**
2181
2182| Name  | Type                                       | Mandatory| Description                                                    |
2183| -------- | ------------------------------------------- | ---- | -------------------------------------------------------- |
2184| type     | string                                      | Yes  | Event type, which is **'sizeChange'**.|
2185| callback | [SizeChangeCallback](#sizechangecallback15) | No  | Callback used to return the size of the soft keyboard panel, including the width and height.  |
2186
2187**Example**
2188
2189```ts
2190import { window } from '@kit.ArkUI';
2191try {
2192  panel.off('sizeChange', (windowSize: window.Size) => {
2193    console.info(`panel size changed, width: ${windowSize.width}, height: ${windowSize.height}`);
2194  });
2195} catch(err) {
2196    console.error(`Failed to subscribe sizeChange: ${JSON.stringify(err)}`);
2197}
2198```
2199
2200### changeFlag<sup>10+</sup>
2201
2202changeFlag(flag: PanelFlag): void
2203
2204Changes the state type of this input method panel. This API only works for [SOFT_KEYBOARD](#paneltype10) panels.
2205
2206**System capability**: SystemCapability.MiscServices.InputMethodFramework
2207
2208**Parameters**
2209
2210| Name  | Type                  | Mandatory| Description    |
2211| -------- | ---------------------- | ---- | -------- |
2212| flag | [PanelFlag](#panelflag10) | Yes| Type of the state of the target panel.|
2213
2214**Error codes**
2215
2216For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2217
2218| ID| Error Message                                               |
2219| -------- | ------------------------------------------------------- |
2220| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2221
2222**Example**
2223
2224```ts
2225try {
2226  let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED;
2227  panel.changeFlag(panelFlag);
2228} catch(err) {
2229    console.error(`Failed to panelFlag: ${JSON.stringify(err)}`);
2230}
2231```
2232
2233### setPrivacyMode<sup>11+</sup>
2234
2235setPrivacyMode(isPrivacyMode: boolean): void
2236
2237Sets the input method panel to privacy mode. In privacy mode, screenshot and screen recording are blocked.
2238
2239**Required permissions**: ohos.permission.PRIVACY_WINDOW
2240
2241**System capability**: SystemCapability.MiscServices.InputMethodFramework
2242
2243**Parameters**
2244
2245| Name       | Type   | Mandatory| Description              |
2246| ------------- | ------- | ---- | ------------------ |
2247| isPrivacyMode | boolean | Yes  | Whether to set the input method panel to privacy mode.|
2248
2249**Error codes**
2250
2251For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2252
2253| ID| Error Message                                               |
2254| -------- | ------------------------------------------------------- |
2255| 201      | permissions check fails.  |
2256| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2257
2258**Example**
2259
2260```ts
2261try {
2262    let isPrivacyMode = true;
2263    panel.setPrivacyMode(isPrivacyMode);
2264} catch(err) {
2265    console.error(`Failed to set privacy mode: ${JSON.stringify(err)}`);
2266}
2267```
2268
2269### setImmersiveMode<sup>15+</sup>
2270
2271setImmersiveMode(mode: ImmersiveMode): void
2272
2273Sets 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.
2274
2275**System capability**: SystemCapability.MiscServices.InputMethodFramework
2276
2277**Parameters**
2278
2279| Name  | Type                  | Mandatory| Description    |
2280| -------- | ---------------------- | ---- | -------- |
2281| mode | [ImmersiveMode](#immersivemode15) | Yes  | Immersive mode.|
2282
2283**Error codes**
2284
2285For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
2286
2287| ID| Error Message                                               |
2288| -------- | ------------------------------------------------------- |
2289| 401      | parameter error. Possible causes: 1.Incorrect parameter types; 2.Parameter verification failed.           |
2290| 12800002  | input method engine error.                                |
2291| 12800013  | window manager service error.                          |
2292
2293**Example**
2294
2295```ts
2296try {
2297  panel.setImmersiveMode(inputMethodEngine.ImmersiveMode.LIGHT_IMMERSIVE);
2298} catch (err) {
2299  console.error(`Failed to setImmersiveMode: ${JSON.stringify(err)}`);
2300}
2301```
2302
2303### getImmersiveMode<sup>15+</sup>
2304
2305getImmersiveMode(): ImmersiveMode
2306
2307Obtains the immersive mode of the input method application.
2308
2309**System capability**: SystemCapability.MiscServices.InputMethodFramework
2310
2311**Return value**
2312
2313| Type                           | Description      |
2314| ------------------------------- | ---------- |
2315| [ImmersiveMode](#immersivemode15) | Immersive mode.|
2316
2317**Example**
2318
2319```ts
2320try {
2321  let mode = panel.getImmersiveMode();
2322} catch (err) {
2323  console.error(`Failed to getImmersiveMode: ${JSON.stringify(err)}`);
2324}
2325```
2326
2327
2328## KeyboardController
2329
2330In 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.
2331
2332### hide<sup>9+</sup>
2333
2334hide(callback: AsyncCallback&lt;void&gt;): void
2335
2336Hides the keyboard. This API uses an asynchronous callback to return the result.
2337
2338**System capability**: SystemCapability.MiscServices.InputMethodFramework
2339
2340**Parameters**
2341
2342| Name  | Type                  | Mandatory| Description    |
2343| -------- | ---------------------- | ---- | -------- |
2344| 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.|
2345
2346**Error codes**
2347
2348For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
2349
2350| ID| Error Message                |
2351| -------- | -------------------------- |
2352| 12800003 | input method client error. |
2353
2354**Example**
2355
2356```ts
2357import { BusinessError } from '@kit.BasicServicesKit';
2358
2359keyboardController.hide((err: BusinessError) => {
2360  if (err) {
2361    console.error(`Failed to hide: ${JSON.stringify(err)}`);
2362    return;
2363  }
2364  console.log('Succeeded in hiding keyboard.');
2365});
2366```
2367
2368### hide<sup>9+</sup>
2369
2370hide(): Promise&lt;void&gt;
2371
2372Hides the keyboard. This API uses a promise to return the result.
2373
2374**System capability**: SystemCapability.MiscServices.InputMethodFramework
2375
2376**Return value**
2377
2378| Type            | Description                     |
2379| ---------------- | ------------------------- |
2380| Promise&lt;void> | Promise that returns no value.|
2381
2382**Error codes**
2383
2384For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
2385
2386| ID| Error Message                |
2387| -------- | -------------------------- |
2388| 12800003 | input method client error. |
2389
2390**Example**
2391
2392```ts
2393import { BusinessError } from '@kit.BasicServicesKit';
2394
2395keyboardController.hide().then(() => {
2396  console.log('Succeeded in hiding keyboard.');
2397}).catch((err: BusinessError) => {
2398  console.log(`Failed to hide: ${JSON.stringify(err)}`);
2399});
2400```
2401
2402### hideKeyboard<sup>(deprecated)</sup>
2403
2404hideKeyboard(callback: AsyncCallback&lt;void&gt;): void
2405
2406Hides the keyboard. This API uses an asynchronous callback to return the result.
2407
2408> **NOTE**
2409>
2410> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9) instead.
2411
2412**System capability**: SystemCapability.MiscServices.InputMethodFramework
2413
2414**Parameters**
2415
2416| Name  | Type                  | Mandatory| Description    |
2417| -------- | ---------------------- | ---- | -------- |
2418| 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.|
2419
2420**Example**
2421
2422```ts
2423import { BusinessError } from '@kit.BasicServicesKit';
2424
2425keyboardController.hideKeyboard((err: BusinessError) => {
2426  if (err) {
2427    console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`);
2428    return;
2429  }
2430  console.log('Succeeded in hiding keyboard.');
2431});
2432```
2433
2434### hideKeyboard<sup>(deprecated)</sup>
2435
2436hideKeyboard(): Promise&lt;void&gt;
2437
2438Hides the keyboard. This API uses a promise to return the result.
2439
2440> **NOTE**
2441>
2442> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9-1) instead.
2443
2444**System capability**: SystemCapability.MiscServices.InputMethodFramework
2445
2446**Return value**
2447
2448| Type            | Description                     |
2449| ---------------- | ------------------------- |
2450| Promise&lt;void> | Promise that returns no value.|
2451
2452**Example**
2453
2454```ts
2455import { BusinessError } from '@kit.BasicServicesKit';
2456
2457keyboardController.hideKeyboard().then(() => {
2458  console.log('Succeeded in hiding keyboard.');
2459}).catch((err: BusinessError) => {
2460  console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`);
2461});
2462```
2463
2464### exitCurrentInputType<sup>11+</sup>
2465
2466exitCurrentInputType(callback: AsyncCallback&lt;void&gt;): void
2467
2468Exits 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.
2469
2470**System capability**: SystemCapability.MiscServices.InputMethodFramework
2471
2472**Parameters**
2473
2474| Name  | Type                  | Mandatory| Description                                                        |
2475| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
2476| 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.|
2477
2478**Error codes**
2479
2480For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
2481
2482| ID| Error Message                                      |
2483| -------- | ---------------------------------------------- |
2484| 12800008 | input method manager service error.            |
2485| 12800010 | not the preconfigured default input method. |
2486
2487**Example**
2488
2489```ts
2490import { BusinessError } from '@kit.BasicServicesKit';
2491
2492keyboardController.exitCurrentInputType((err: BusinessError) => {
2493  if (err) {
2494    console.error(`Failed to exitCurrentInputType: ${JSON.stringify(err)}`);
2495    return;
2496  }
2497  console.log('Succeeded in exiting current input type.');
2498});
2499```
2500
2501### exitCurrentInputType<sup>11+</sup>
2502
2503exitCurrentInputType(): Promise&lt;void&gt;
2504
2505Exits this input type. This API can be called only by the preconfigured default input method. This API uses a promise to return the result.
2506
2507**System capability**: SystemCapability.MiscServices.InputMethodFramework
2508
2509**Return value**
2510
2511| Type            | Description                     |
2512| ---------------- | ------------------------- |
2513| Promise&lt;void> | Promise that returns no value.|
2514
2515**Error codes**
2516
2517For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
2518
2519| ID| Error Message                                      |
2520| -------- | ---------------------------------------------- |
2521| 12800008 | input method manager service error.            |
2522| 12800010 | not the preconfigured default input method. |
2523
2524**Example**
2525
2526```ts
2527import { BusinessError } from '@kit.BasicServicesKit';
2528
2529keyboardController.exitCurrentInputType().then(() => {
2530  console.log('Succeeded in exiting current input type.');
2531}).catch((err: BusinessError) => {
2532  console.log(`Failed to exit current input type: ${JSON.stringify(err)}`);
2533});
2534```
2535
2536## SecurityMode<sup>11+</sup>
2537
2538Describes the security mode.
2539
2540**System capability**: SystemCapability.MiscServices.InputMethodFramework
2541
2542| Name | Value  | Description                                        |
2543| ----- | ---- | -------------------------------------------- |
2544| BASIC | 0    | Basic access mode, where network access is restricted.|
2545| FULL  | 1    | Full access mode, where network access is not restricted.      |
2546
2547## ExtendAction<sup>10+</sup>
2548
2549Describes the type of the extended edit action on the text box.
2550
2551**System capability**: SystemCapability.MiscServices.InputMethodFramework
2552
2553| Name| Value|Description|
2554| -------- | -------- |-------- |
2555| SELECT_ALL  | 0 |Select all.|
2556| CUT  | 3 |Cut.|
2557| COPY  | 4 |Copy.|
2558| PASTE  | 5 |Paste.|
2559
2560## Direction<sup>10+</sup>
2561
2562Enumerates the directions of cursor movement of the input method.
2563
2564**System capability**: SystemCapability.MiscServices.InputMethodFramework
2565
2566| Name| Value|Description|
2567| -------- | -------- |-------- |
2568| CURSOR_UP  | 1 |Upward.|
2569| CURSOR_DOWN  | 2 |Downward.|
2570| CURSOR_LEFT  | 3 |Leftward.|
2571| CURSOR_RIGHT  | 4 |Rightward.|
2572
2573## Range<sup>10+</sup>
2574
2575Describes the range of the selected text.
2576
2577**System capability**: SystemCapability.MiscServices.InputMethodFramework
2578
2579| Name| Type| Read-Only| Optional| Description|
2580| -------- | -------- | -------- | -------- | -------- |
2581| start  | number | No| No| Index of the first selected character in the text box.|
2582| end  | number | No| No| Index of the last selected character in the text box.|
2583
2584## Movement<sup>10+</sup>
2585
2586Describes the direction in which the cursor moves when the text is selected.
2587
2588**System capability**: SystemCapability.MiscServices.InputMethodFramework
2589
2590| Name| Type| Read-Only| Optional| Description|
2591| -------- | -------- | -------- | -------- | -------- |
2592| direction  | [Direction](#direction10) | No| No| Direction in which the cursor moves when the text is selected.|
2593
2594## MessageHandler<sup>15+</sup>
2595
2596Represents a custom communication object.
2597
2598> **NOTE**
2599>
2600> 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.
2601>
2602> This object is globally unique. After multiple registrations, only the last registered object is valid and retained, and the [onTerminated](#onterminated15) callback of the penultimate registered object is triggered.
2603>
2604> If this object is unregistered, its [onTerminated](#onterminated15) callback will be triggered.
2605
2606### onMessage<sup>15+</sup>
2607
2608onMessage(msgId: string, msgParam?: ArrayBuffer): void
2609
2610Receives the custom data callback sent by the edit box application attached to the input method application.
2611
2612> **NOTE**
2613>
2614> This callback is triggered when the registered [MessageHandler](#messagehandler15) receives custom communication data sent by the edit box application attached to the input method application.
2615>
2616> 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.
2617
2618**System capability**: SystemCapability.MiscServices.InputMethodFramework
2619
2620**Parameters**
2621
2622| Name  | Type       | Optional| Description                            |
2623| -------- | ----------- | ---- | -------------------------------- |
2624| msgId    | string      | No  | Identifier of the received custom communication data.|
2625| msgParam | ArrayBuffer | Yes  | Message body of the received custom communication data.|
2626
2627**Example**
2628
2629```ts
2630import { BusinessError } from '@kit.BasicServicesKit';
2631
2632try {
2633  inputMethodEngine.getInputMethodAbility()
2634    .on('inputStart', (kbController: inputMethodEngine.KeyboardController, client: inputMethodEngine.InputClient) => {
2635      let keyboardController = kbController;
2636      let inputClient = client;
2637      try {
2638        let messageHandler: inputMethodEngine.MessageHandler = {
2639          onTerminated(): void {
2640            console.log('OnTerminated.');
2641          },
2642          onMessage(msgId: string, msgParam?:ArrayBuffer): void {
2643            console.log('recv message.');
2644          }
2645        }
2646        inputClient.recvMessage(messageHandler);
2647      } catch(err) {
2648        console.error(`Failed to recvMessage: ${JSON.stringify(err)}`);
2649      }
2650  });
2651} catch(err) {
2652    console.error(`Failed to InputMethodAbility: ${JSON.stringify(err)}`);
2653}
2654```
2655
2656### onTerminated<sup>15+</sup>
2657
2658onTerminated(): void
2659
2660Listens for MessageHandler termination.
2661
2662> **NOTE**
2663>
2664> When an application registers a new [MessageHandler](#messagehandler15) object, the [onTerminated](#onterminated15) callback of the penultimate registered [MessageHandler](#messagehandler15) object is triggered.
2665>
2666> When an application unregisters a new [MessageHandler](#messagehandler15) object, the [onTerminated](#onterminated15) callback of the registered [MessageHandler](#messagehandler15) object is triggered.
2667
2668**System capability**: SystemCapability.MiscServices.InputMethodFramework
2669
2670**Example**
2671
2672```ts
2673import { BusinessError } from '@kit.BasicServicesKit';
2674
2675try {
2676  inputMethodEngine.getInputMethodAbility()
2677    .on('inputStart', (kbController: inputMethodEngine.KeyboardController, client: inputMethodEngine.InputClient) => {
2678      let keyboardController = kbController;
2679      let inputClient = client;
2680      try {
2681        let messageHandler: inputMethodEngine.MessageHandler = {
2682          onTerminated(): void {
2683            console.log('OnTerminated.');
2684          },
2685          onMessage(msgId: string, msgParam?:ArrayBuffer): void {
2686            console.log('recv message.');
2687          }
2688        }
2689        inputClient.recvMessage(messageHandler);
2690      } catch(err) {
2691        console.error(`Failed to recvMessage: ${JSON.stringify(err)}`);
2692      }
2693  });
2694} catch(err) {
2695    console.error(`Failed to InputMethodAbility: ${JSON.stringify(err)}`);
2696}
2697```
2698
2699## InputClient<sup>9+</sup>
2700
2701In 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.
2702
2703### sendKeyFunction<sup>9+</sup>
2704
2705sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
2706
2707Sends the function key. This API uses an asynchronous callback to return the result.
2708
2709**System capability**: SystemCapability.MiscServices.InputMethodFramework
2710
2711  **Parameters**
2712
2713| Name| Type| Mandatory| Description|
2714| -------- | -------- | -------- | -------- |
2715| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).|
2716| 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.|
2717
2718**Error codes**
2719
2720For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2721
2722| ID| Error Message                |
2723| -------- | -------------------------- |
2724| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2725| 12800003 | input method client error. |
2726
2727 **Example**
2728
2729```ts
2730import { BusinessError } from '@kit.BasicServicesKit';
2731
2732let action = 1;
2733try {
2734  inputClient.sendKeyFunction(action, (err: BusinessError, result: boolean) => {
2735    if (err) {
2736      console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
2737      return;
2738    }
2739    if (result) {
2740      console.log('Succeeded in sending key function.');
2741    } else {
2742      console.error('Failed to sendKeyFunction.');
2743    }
2744  });
2745} catch (err) {
2746  console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
2747}
2748```
2749
2750### sendKeyFunction<sup>9+</sup>
2751
2752sendKeyFunction(action: number): Promise&lt;boolean&gt;
2753
2754Sends the function key. This API uses a promise to return the result.
2755
2756**System capability**: SystemCapability.MiscServices.InputMethodFramework
2757
2758**Parameters**
2759
2760| Name| Type| Mandatory| Description|
2761| -------- | -------- | -------- | -------- |
2762| action | number | Yes| Action of the function key.<br>**0**: invalid key.<br>**1**: confirm key (Enter key).|
2763
2764**Return value**
2765
2766| Type                           | Description                                                        |
2767| ------------------------------- | ------------------------------------------------------------ |
2768| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.|
2769
2770**Error codes**
2771
2772For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2773
2774| ID| Error Message                |
2775| -------- | -------------------------- |
2776| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2777| 12800003 | input method client error. |
2778
2779**Example**
2780
2781```ts
2782import { BusinessError } from '@kit.BasicServicesKit';
2783
2784let action = 1;
2785try {
2786  inputClient.sendKeyFunction(action).then((result: boolean) => {
2787    if (result) {
2788      console.log('Succeeded in sending key function.');
2789    } else {
2790      console.error('Failed to sendKeyFunction.');
2791    }
2792  }).catch((err: BusinessError) => {
2793    console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
2794  });
2795} catch (err) {
2796  console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
2797}
2798```
2799
2800### getForward<sup>9+</sup>
2801
2802getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
2803
2804Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result.
2805
2806**System capability**: SystemCapability.MiscServices.InputMethodFramework
2807
2808**Parameters**
2809
2810| Name| Type| Mandatory| Description|
2811| -------- | -------- | -------- | -------- |
2812| length | number | Yes| Text length, which cannot be less than 0.|
2813| 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.|
2814
2815**Error codes**
2816
2817For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2818
2819| ID| Error Message                    |
2820| -------- | ------------------------------ |
2821| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2822| 12800003 | input method client error.     |
2823| 12800006 | Input method controller error. |
2824
2825**Example**
2826
2827```ts
2828import { BusinessError } from '@kit.BasicServicesKit';
2829
2830let length = 1;
2831try {
2832  inputClient.getForward(length, (err: BusinessError, text: string) => {
2833    if (err) {
2834      console.error(`Failed to getForward: ${JSON.stringify(err)}`);
2835      return;
2836    }
2837    console.log('Succeeded in getting forward, text: ' + text);
2838  });
2839} catch (err) {
2840  console.error(`Failed to getForward: ${JSON.stringify(err)}`);
2841}
2842```
2843
2844### getForward<sup>9+</sup>
2845
2846getForward(length:number): Promise&lt;string&gt;
2847
2848Obtains the specific-length text before the cursor. This API uses a promise to return the result.
2849
2850**System capability**: SystemCapability.MiscServices.InputMethodFramework
2851
2852**Parameters**
2853
2854| Name| Type| Mandatory| Description|
2855| -------- | -------- | -------- | -------- |
2856| length | number | Yes| Text length, which cannot be less than 0.|
2857
2858**Return value**
2859
2860| Type                           | Description                                                        |
2861| ------------------------------- | ------------------------------------------------------------ |
2862| Promise&lt;string&gt;           |  Promise used to return the specific-length text before the cursor.                    |
2863
2864**Error codes**
2865
2866For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2867
2868| ID| Error Message                    |
2869| -------- | ------------------------------ |
2870| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2871| 12800003 | input method client error.     |
2872| 12800006 | Input method controller error. |
2873
2874**Example**
2875
2876```ts
2877import { BusinessError } from '@kit.BasicServicesKit';
2878
2879let length = 1;
2880try {
2881  inputClient.getForward(length).then((text: string) => {
2882    console.log('Succeeded in getting forward, text: ' + text);
2883  }).catch((err: BusinessError) => {
2884    console.error(`Failed to getForward: ${JSON.stringify(err)}`);
2885  });
2886} catch (err) {
2887  console.error(`Failed to getForward: ${JSON.stringify(err)}`);
2888}
2889```
2890
2891### getForwardSync<sup>10+</sup>
2892
2893getForwardSync(length:number): string
2894
2895Obtains the specific-length text before the cursor.
2896
2897**System capability**: SystemCapability.MiscServices.InputMethodFramework
2898
2899**Parameters**
2900
2901| Name| Type  | Mandatory| Description      |
2902| ------ | ------ | ---- | ---------- |
2903| length | number | Yes  | Text length, which cannot be less than 0.|
2904
2905**Return value**
2906
2907| Type  | Description                      |
2908| ------ | -------------------------- |
2909| string | Specific-length text before the cursor.|
2910
2911**Error codes**
2912
2913For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2914
2915| ID| Error Message                      |
2916| -------- | ------------------------------ |
2917| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2918| 12800003 | input method client error.     |
2919| 12800006 | input method controller error. |
2920
2921**Example**
2922
2923```ts
2924let length = 1;
2925try {
2926  let text: string = inputClient.getForwardSync(length);
2927  console.log(`Succeeded in getting forward, text: ${text}`);
2928} catch (err) {
2929  console.error(`Failed to getForwardSync: ${JSON.stringify(err)}`);
2930}
2931```
2932
2933### getBackward<sup>9+</sup>
2934
2935getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
2936
2937Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result.
2938
2939**System capability**: SystemCapability.MiscServices.InputMethodFramework
2940
2941**Parameters**
2942
2943| Name| Type| Mandatory| Description|
2944| -------- | -------- | -------- | -------- |
2945| length | number | Yes| Text length, which cannot be less than 0.|
2946| 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.|
2947
2948**Error codes**
2949
2950For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2951
2952| ID| Error Message                    |
2953| -------- | ------------------------------ |
2954| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2955| 12800003 | input method client error.     |
2956| 12800006 | Input method controller error. |
2957
2958**Example**
2959
2960```ts
2961import { BusinessError } from '@kit.BasicServicesKit';
2962
2963let length = 1;
2964try {
2965  inputClient.getBackward(length, (err: BusinessError, text: string) => {
2966    if (err) {
2967      console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
2968      return;
2969    }
2970    console.log('Succeeded in getting backward, text: ' + text);
2971  });
2972} catch (err) {
2973  console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
2974}
2975```
2976
2977### getBackward<sup>9+</sup>
2978
2979getBackward(length:number): Promise&lt;string&gt;
2980
2981Obtains the specific-length text after the cursor. This API uses a promise to return the result.
2982
2983**System capability**: SystemCapability.MiscServices.InputMethodFramework
2984
2985**Parameters**
2986
2987| Name| Type| Mandatory| Description|
2988| -------- | -------- | -------- | -------- |
2989| length | number | Yes| Text length, which cannot be less than 0.|
2990
2991**Return value**
2992
2993| Type                           | Description                                                        |
2994| ------------------------------- | ------------------------------------------------------------ |
2995| Promise&lt;string&gt;           |  Promise used to return the specific-length text after the cursor.                    |
2996
2997**Error codes**
2998
2999For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3000
3001| ID| Error Message                    |
3002| -------- | ------------------------------ |
3003| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3004| 12800003 | input method client error.     |
3005| 12800006 | Input method controller error. |
3006
3007**Example**
3008
3009```ts
3010import { BusinessError } from '@kit.BasicServicesKit';
3011
3012let length = 1;
3013try {
3014  inputClient.getBackward(length).then((text: string) => {
3015    console.log('Succeeded in getting backward, text: ' + text);
3016  }).catch((err: BusinessError) => {
3017    console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
3018  });
3019} catch (err) {
3020  console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
3021}
3022```
3023
3024### getBackwardSync<sup>10+</sup>
3025
3026getBackwardSync(length:number): string
3027
3028Obtains the specific-length text after the cursor.
3029
3030**System capability**: SystemCapability.MiscServices.InputMethodFramework
3031
3032**Parameters**
3033
3034| Name| Type  | Mandatory| Description      |
3035| ------ | ------ | ---- | ---------- |
3036| length | number | Yes  | Text length, which cannot be less than 0.|
3037
3038**Return value**
3039
3040| Type  | Description                      |
3041| ------ | -------------------------- |
3042| string | Specific-length text after the cursor.|
3043
3044**Error codes**
3045
3046For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3047
3048| ID| Error Message                      |
3049| -------- | ------------------------------ |
3050| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3051| 12800003 | input method client error.     |
3052| 12800006 | input method controller error. |
3053
3054**Example**
3055
3056```ts
3057let length = 1;
3058try {
3059  let text: string = inputClient.getBackwardSync(length);
3060  console.log(`Succeeded in getting backward, text: ${text}`);
3061} catch (err) {
3062  console.error(`Failed to getBackwardSync: ${JSON.stringify(err)}`);
3063}
3064```
3065
3066### deleteForward<sup>9+</sup>
3067
3068deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
3069
3070Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result.
3071
3072**System capability**: SystemCapability.MiscServices.InputMethodFramework
3073
3074**Parameters**
3075
3076| Name| Type| Mandatory| Description|
3077| -------- | -------- | -------- | -------- |
3078| length | number | Yes| Text length, which cannot be less than 0.|
3079| 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.|
3080
3081**Error codes**
3082
3083For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3084
3085| ID| Error Message                |
3086| -------- | -------------------------- |
3087| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3088| 12800002 | Input method engine error. |
3089| 12800003 | input method client error. |
3090
3091**Example**
3092
3093```ts
3094import { BusinessError } from '@kit.BasicServicesKit';
3095
3096let length = 1;
3097try {
3098  inputClient.deleteForward(length, (err: BusinessError, result: boolean) => {
3099    if (err) {
3100      console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
3101      return;
3102    }
3103    if (result) {
3104      console.log('Succeeded in deleting forward.');
3105    } else {
3106      console.error(`Failed to deleteForward.`);
3107    }
3108  });
3109} catch (err) {
3110  console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
3111}
3112```
3113
3114### deleteForward<sup>9+</sup>
3115
3116deleteForward(length:number): Promise&lt;boolean&gt;
3117
3118Deletes the fixed-length text before the cursor. This API uses a promise to return the result.
3119
3120**System capability**: SystemCapability.MiscServices.InputMethodFramework
3121
3122**Parameters**
3123
3124| Name| Type  | Mandatory| Description      |
3125| ------ | ------ | ---- | ---------- |
3126| length | number | Yes  | Text length, which cannot be less than 0.|
3127
3128**Return value**
3129
3130| Type                  | Description          |
3131| ---------------------- | -------------- |
3132| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.|
3133
3134**Error codes**
3135
3136For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3137
3138| ID| Error Message                |
3139| -------- | -------------------------- |
3140| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3141| 12800002 | Input method engine error. |
3142| 12800003 | input method client error. |
3143
3144**Example**
3145
3146```ts
3147import { BusinessError } from '@kit.BasicServicesKit';
3148
3149let length = 1;
3150try {
3151  inputClient.deleteForward(length).then((result: boolean) => {
3152    if (result) {
3153      console.log('Succeeded in deleting forward.');
3154    } else {
3155      console.error('Failed to delete Forward.');
3156    }
3157  }).catch((err: BusinessError) => {
3158    console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
3159  });
3160} catch (err) {
3161  console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
3162}
3163```
3164
3165### deleteForwardSync<sup>10+</sup>
3166
3167deleteForwardSync(length:number): void
3168
3169Deletes the fixed-length text before the cursor.
3170
3171**System capability**: SystemCapability.MiscServices.InputMethodFramework
3172
3173**Parameters**
3174
3175| Name| Type  | Mandatory| Description      |
3176| ------ | ------ | ---- | ---------- |
3177| length | number | Yes  | Text length, which cannot be less than 0.|
3178
3179**Error codes**
3180
3181For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3182
3183| ID| Error Message                  |
3184| -------- | -------------------------- |
3185| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3186| 12800002 | input method engine error. |
3187| 12800003 | input method client error. |
3188
3189**Example**
3190
3191```ts
3192let length = 1;
3193try {
3194  inputClient.deleteForwardSync(length);
3195  console.log('Succeeded in deleting forward.');
3196} catch (err) {
3197  console.error('deleteForwardSync err: ' + JSON.stringify(err));
3198}
3199```
3200
3201### deleteBackward<sup>9+</sup>
3202
3203deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
3204
3205Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result.
3206
3207**System capability**: SystemCapability.MiscServices.InputMethodFramework
3208
3209**Parameters**
3210
3211| Name  | Type                        | Mandatory| Description          |
3212| -------- | ---------------------------- | ---- | -------------- |
3213| length   | number                       | Yes  | Text length, which cannot be less than 0.    |
3214| 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.|
3215
3216**Error codes**
3217
3218For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3219
3220| ID| Error Message                |
3221| -------- | -------------------------- |
3222| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3223| 12800002 | Input method engine error. |
3224| 12800003 | input method client error. |
3225
3226**Example**
3227
3228```ts
3229import { BusinessError } from '@kit.BasicServicesKit';
3230
3231let length = 1;
3232try {
3233  inputClient.deleteBackward(length, (err: BusinessError, result: boolean) => {
3234    if (err) {
3235      console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
3236      return;
3237    }
3238    if (result) {
3239      console.log('Succeeded in deleting backward.');
3240    } else {
3241      console.error(`Failed to deleteBackward.`);
3242    }
3243  });
3244} catch (err) {
3245  console.error('deleteBackward err: ' + JSON.stringify(err));
3246}
3247```
3248
3249### deleteBackward<sup>9+</sup>
3250
3251deleteBackward(length:number): Promise&lt;boolean&gt;
3252
3253Deletes the fixed-length text after the cursor. This API uses a promise to return the result.
3254
3255**System capability**: SystemCapability.MiscServices.InputMethodFramework
3256
3257**Parameters**
3258
3259| Name| Type| Mandatory| Description|
3260| -------- | -------- | -------- | -------- |
3261| length | number | Yes| Text length, which cannot be less than 0.   |
3262
3263**Return value**
3264
3265| Type                           | Description                                                        |
3266| ------------------------------- | ------------------------------------------------------------ |
3267| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.|
3268
3269**Error codes**
3270
3271For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3272
3273| ID| Error Message                |
3274| -------- | -------------------------- |
3275| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3276| 12800002 | Input method engine error. |
3277| 12800003 | input method client error. |
3278
3279**Example**
3280
3281```ts
3282import { BusinessError } from '@kit.BasicServicesKit';
3283
3284let length = 1;
3285inputClient.deleteBackward(length).then((result: boolean) => {
3286  if (result) {
3287    console.log('Succeeded in deleting backward.');
3288  } else {
3289    console.error('Failed to deleteBackward.');
3290  }
3291}).catch((err: BusinessError) => {
3292  console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
3293});
3294```
3295
3296### deleteBackwardSync<sup>10+</sup>
3297
3298deleteBackwardSync(length:number): void
3299
3300Deletes the fixed-length text after the cursor.
3301
3302**System capability**: SystemCapability.MiscServices.InputMethodFramework
3303
3304**Parameters**
3305
3306| Name| Type  | Mandatory| Description      |
3307| ------ | ------ | ---- | ---------- |
3308| length | number | Yes  | Text length, which cannot be less than 0. |
3309
3310**Error codes**
3311
3312For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3313
3314| ID| Error Message                  |
3315| -------- | -------------------------- |
3316| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3317| 12800002 | input method engine error. |
3318| 12800003 | input method client error. |
3319
3320**Example**
3321
3322```ts
3323let length = 1;
3324try {
3325  inputClient.deleteBackwardSync(length);
3326  console.log('Succeeded in deleting backward.');
3327} catch (err) {
3328  console.error('deleteBackwardSync err: ' + JSON.stringify(err));
3329}
3330```
3331
3332### insertText<sup>9+</sup>
3333
3334insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
3335
3336Inserts text. This API uses an asynchronous callback to return the result.
3337
3338**System capability**: SystemCapability.MiscServices.InputMethodFramework
3339
3340**Parameters**
3341
3342| Name| Type| Mandatory| Description|
3343| -------- | -------- | -------- | -------- |
3344| text | string | Yes| Text to insert.|
3345| 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.|
3346
3347**Error codes**
3348
3349For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3350
3351| ID| Error Message                |
3352| -------- | -------------------------- |
3353| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3354| 12800002 | Input method engine error. |
3355| 12800003 | input method client error. |
3356
3357**Example**
3358
3359```ts
3360import { BusinessError } from '@kit.BasicServicesKit';
3361
3362inputClient.insertText('test', (err: BusinessError, result: boolean) => {
3363  if (err) {
3364    console.error(`Failed to insertText: ${JSON.stringify(err)}`);
3365    return;
3366  }
3367  if (result) {
3368    console.log('Succeeded in inserting text.');
3369  } else {
3370    console.error('Failed to insertText.');
3371  }
3372});
3373```
3374
3375### insertText<sup>9+</sup>
3376
3377insertText(text:string): Promise&lt;boolean&gt;
3378
3379Inserts text. This API uses a promise to return the result.
3380
3381**System capability**: SystemCapability.MiscServices.InputMethodFramework
3382
3383**Parameters**
3384
3385| Name| Type| Mandatory| Description|
3386| -------- | -------- | -------- | -------- |
3387| text | string | Yes| Text to insert.|
3388
3389**Return value**
3390
3391| Type                           | Description                                                        |
3392| ------------------------------- | ------------------------------------------------------------ |
3393| Promise&lt;boolean&gt;  |  Promise used to return the result. The value **true** means that the insertion is successful, and **false** means the opposite. |
3394
3395**Error codes**
3396
3397For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3398
3399| ID| Error Message                |
3400| -------- | -------------------------- |
3401| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3402| 12800002 | Input method engine error. |
3403| 12800003 | input method client error. |
3404
3405**Example**
3406
3407```ts
3408import { BusinessError } from '@kit.BasicServicesKit';
3409
3410try {
3411  inputClient.insertText('test').then((result: boolean) => {
3412    if (result) {
3413      console.log('Succeeded in inserting text.');
3414    } else {
3415      console.error('Failed to insertText.');
3416    }
3417  }).catch((err: BusinessError) => {
3418    console.error(`Failed to insertText: ${JSON.stringify(err)}`);
3419  });
3420} catch (err) {
3421  console.error(`Failed to insertText: ${JSON.stringify(err)}`);
3422}
3423```
3424
3425### insertTextSync<sup>10+</sup>
3426
3427insertTextSync(text: string): void
3428
3429Inserts text.
3430
3431**System capability**: SystemCapability.MiscServices.InputMethodFramework
3432
3433**Parameters**
3434
3435| Name| Type  | Mandatory| Description      |
3436| ------ | ------ | ---- | ---------- |
3437| text   | string | Yes  | Text to insert.|
3438
3439**Error codes**
3440
3441For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3442
3443| ID| Error Message                  |
3444| -------- | -------------------------- |
3445| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3446| 12800002 | input method engine error. |
3447| 12800003 | input method client error. |
3448
3449**Example**
3450
3451```ts
3452try {
3453  inputClient.insertTextSync('test');
3454  console.log('Succeeded in inserting text.');
3455} catch (err) {
3456  console.error(`Failed to insertTextSync: ${JSON.stringify(err)}`);
3457}
3458```
3459
3460### getEditorAttribute<sup>9+</sup>
3461
3462getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
3463
3464Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result.
3465
3466**System capability**: SystemCapability.MiscServices.InputMethodFramework
3467
3468**Parameters**
3469
3470| Name                        | Type                         | Mandatory                           | Description                                                        |
3471| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
3472| 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.|
3473
3474**Error codes**
3475
3476For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
3477
3478| ID| Error Message                |
3479| -------- | -------------------------- |
3480| 12800003 | input method client error. |
3481
3482**Example**
3483
3484```ts
3485import { BusinessError } from '@kit.BasicServicesKit';
3486
3487inputClient.getEditorAttribute((err: BusinessError, editorAttribute: inputMethodEngine.EditorAttribute) => {
3488  if (err) {
3489    console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
3490    return;
3491  }
3492  console.log(`editorAttribute.inputPattern:  ${editorAttribute.inputPattern}`);
3493  console.log(`editorAttribute.enterKeyType:  ${editorAttribute.enterKeyType}`);
3494});
3495```
3496
3497### getEditorAttribute<sup>9+</sup>
3498
3499getEditorAttribute(): Promise&lt;EditorAttribute&gt;
3500
3501Obtains the attribute of the edit box. This API uses a promise to return the result.
3502
3503**System capability**: SystemCapability.MiscServices.InputMethodFramework
3504
3505**Return value**
3506
3507| Type                           | Description                                                        |
3508| ------------------------------- | ------------------------------------------------------------ |
3509| Promise&lt;[EditorAttribute](#editorattribute)&gt; |  Promise used to return the attribute of the edit box.          |
3510
3511**Error codes**
3512
3513For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
3514
3515| ID| Error Message                |
3516| -------- | -------------------------- |
3517| 12800003 | input method client error. |
3518
3519**Example**
3520
3521```ts
3522import { BusinessError } from '@kit.BasicServicesKit';
3523
3524try {
3525  inputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => {
3526    console.log(`editorAttribute.inputPattern:  ${editorAttribute.inputPattern}`);
3527    console.log(`editorAttribute.enterKeyType:  ${editorAttribute.enterKeyType}`);
3528  }).catch((err: BusinessError) => {
3529    console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
3530  });
3531} catch(err) {
3532    console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
3533}
3534```
3535
3536### getEditorAttributeSync<sup>10+</sup>
3537
3538getEditorAttributeSync(): EditorAttribute
3539
3540Obtains the attribute of the edit box.
3541
3542**System capability**: SystemCapability.MiscServices.InputMethodFramework
3543
3544**Return value**
3545
3546| Type                               | Description          |
3547| ----------------------------------- | -------------- |
3548| [EditorAttribute](#editorattribute) | Attribute object of the edit box.|
3549
3550**Error codes**
3551
3552For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
3553
3554| ID| Error Message                  |
3555| -------- | -------------------------- |
3556| 12800003 | input method client error. |
3557
3558**Example**
3559
3560```ts
3561try {
3562  let editorAttribute: inputMethodEngine.EditorAttribute = inputClient.getEditorAttributeSync();
3563    console.log(`editorAttribute.inputPattern:  ${editorAttribute.inputPattern}`);
3564    console.log(`editorAttribute.enterKeyType:  ${editorAttribute.enterKeyType}`);
3565} catch (err) {
3566  console.error(`Failed to getEditorAttributeSync: ${JSON.stringify(err)}`);
3567}
3568```
3569
3570### moveCursor<sup>9+</sup>
3571
3572moveCursor(direction: number, callback: AsyncCallback&lt;void&gt;): void
3573
3574Moves the cursor. This API uses an asynchronous callback to return the result.
3575
3576**System capability**: SystemCapability.MiscServices.InputMethodFramework
3577
3578**Parameters**
3579
3580| Name   | Type                     | Mandatory| Description          |
3581| --------- | ------------------------- | ---- | -------------- |
3582| 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.|
3583| 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.   |
3584
3585**Error codes**
3586
3587For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3588
3589| ID| Error Message                |
3590| -------- | -------------------------- |
3591| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3592| 12800003 | input method client error. |
3593
3594**Example**
3595
3596```ts
3597import { BusinessError } from '@kit.BasicServicesKit';
3598
3599try {
3600  inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP, (err: BusinessError) => {
3601    if (err) {
3602      console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
3603      return;
3604    }
3605    console.log('Succeeded in moving cursor.');
3606  });
3607} catch (err) {
3608  console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
3609}
3610```
3611
3612### moveCursor<sup>9+</sup>
3613
3614moveCursor(direction: number): Promise&lt;void&gt;
3615
3616Moves the cursor. This API uses a promise to return the result.
3617
3618**System capability**: SystemCapability.MiscServices.InputMethodFramework
3619
3620**Parameters**
3621
3622| Name   | Type  | Mandatory| Description                                                        |
3623| --------- | ------ | ---- | ------------------------------------------------------------ |
3624| 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.|
3625
3626**Return value**
3627
3628| Type               | Description                     |
3629| ------------------- | ------------------------- |
3630| Promise&lt;void&gt; | Promise that returns no value.|
3631
3632**Error codes**
3633
3634For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3635
3636| ID| Error Message                |
3637| -------- | -------------------------- |
3638| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3639| 12800003 | input method client error. |
3640
3641**Example**
3642
3643```ts
3644import { BusinessError } from '@kit.BasicServicesKit';
3645
3646try {
3647  inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP).then(() => {
3648    console.log('Succeeded in moving cursor.');
3649  }).catch((err: BusinessError) => {
3650    console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
3651  });
3652} catch (err) {
3653  console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
3654}
3655```
3656
3657### moveCursorSync<sup>10+</sup>
3658
3659moveCursorSync(direction: number): void
3660
3661Moves the cursor.
3662
3663**System capability**: SystemCapability.MiscServices.InputMethodFramework
3664
3665**Parameters**
3666
3667| Name   | Type  | Mandatory| Description                                                        |
3668| --------- | ------ | ---- | ------------------------------------------------------------ |
3669| 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.|
3670
3671**Error codes**
3672
3673For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3674
3675| ID| Error Message                  |
3676| -------- | -------------------------- |
3677| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3678| 12800003 | input method client error. |
3679
3680**Example**
3681
3682```ts
3683try {
3684  inputClient.moveCursorSync(inputMethodEngine.Direction.CURSOR_UP);
3685  console.log('Succeeded in moving cursor.');
3686} catch (err) {
3687  console.error(`Failed to moveCursorSync: ${JSON.stringify(err)}`);
3688}
3689```
3690
3691### selectByRange<sup>10+</sup>
3692
3693selectByRange(range: Range, callback: AsyncCallback&lt;void&gt;): void
3694
3695Selects text based on the specified range. This API uses an asynchronous callback to return the result.
3696
3697**System capability**: SystemCapability.MiscServices.InputMethodFramework
3698
3699**Parameters**
3700
3701| Name  | Type                                                     | Mandatory| Description                                                        |
3702| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
3703| range    | [Range](#range10) | Yes  | Range of the selected text.                                            |
3704| 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.|
3705
3706**Error codes**
3707
3708For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3709
3710| ID| Error Message                  |
3711| -------- | -------------------------- |
3712| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3713| 12800003 | input method client error. |
3714
3715**Example**
3716
3717```ts
3718import { BusinessError } from '@kit.BasicServicesKit';
3719
3720try {
3721  let range: inputMethodEngine.Range = { start: 0, end: 1 };
3722  inputClient.selectByRange(range, (err: BusinessError) => {
3723    if (err) {
3724      console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
3725      return;
3726    }
3727    console.log('Succeeded in selecting by range.');
3728  });
3729} catch (err) {
3730  console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
3731}
3732```
3733
3734### selectByRange<sup>10+</sup>
3735
3736selectByRange(range: Range): Promise&lt;void&gt;
3737
3738Selects text based on the specified range. This API uses a promise to return the result.
3739
3740**System capability**: SystemCapability.MiscServices.InputMethodFramework
3741
3742**Parameters**
3743
3744| Name| Type                                                     | Mandatory| Description            |
3745| ------ | --------------------------------------------------------- | ---- | ---------------- |
3746| range  | [Range](#range10) | Yes  | Range of the selected text.|
3747
3748**Return value**
3749
3750| Type               | Description                     |
3751| ------------------- | ------------------------- |
3752| Promise&lt;void&gt; | Promise that returns no value.|
3753
3754**Error codes**
3755
3756For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3757
3758| ID| Error Message                  |
3759| -------- | -------------------------- |
3760| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3761| 12800003 | input method client error. |
3762
3763**Example**
3764
3765```ts
3766import { BusinessError } from '@kit.BasicServicesKit';
3767
3768try {
3769  let range: inputMethodEngine.Range = { start: 0, end: 1 };
3770  inputClient.selectByRange(range).then(() => {
3771    console.log('Succeeded in selecting by range.');
3772  }).catch((err: BusinessError) => {
3773    console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
3774  });
3775} catch (err) {
3776  console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
3777}
3778```
3779
3780### selectByRangeSync<sup>10+</sup>
3781
3782selectByRangeSync(range: Range): void
3783
3784Selects text based on the specified range.
3785
3786**System capability**: SystemCapability.MiscServices.InputMethodFramework
3787
3788**Parameters**
3789
3790| Name| Type             | Mandatory| Description            |
3791| ------ | ----------------- | ---- | ---------------- |
3792| range  | [Range](#range10) | Yes  | Range of the selected text.|
3793
3794**Error codes**
3795
3796For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3797
3798| ID| Error Message                  |
3799| -------- | -------------------------- |
3800| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3801| 12800003 | input method client error. |
3802
3803**Example**
3804
3805```ts
3806try {
3807  let range: inputMethodEngine.Range = { start: 0, end: 1 };
3808  inputClient.selectByRangeSync(range);
3809  console.log('Succeeded in selecting by range.');
3810} catch (err) {
3811  console.error(`Failed to selectByRangeSync: ${JSON.stringify(err)}`);
3812}
3813```
3814
3815### selectByMovement<sup>10+</sup>
3816
3817selectByMovement(movement: Movement, callback: AsyncCallback&lt;void&gt;): void
3818
3819Selects text based on the cursor movement direction. This API uses an asynchronous callback to return the result.
3820
3821**System capability**: SystemCapability.MiscServices.InputMethodFramework
3822
3823**Parameters**
3824
3825| Name  | Type | Mandatory| Description  |
3826| -------- | ------ | ---- | ------ |
3827| movement | [Movement](#movement10)   | Yes  | Direction in which the cursor moves when the text is selected. |
3828| 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.|
3829
3830**Error codes**
3831
3832For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3833
3834| ID| Error Message                  |
3835| -------- | -------------------------- |
3836| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3837| 12800003 | input method client error. |
3838
3839**Example**
3840
3841```ts
3842import { BusinessError } from '@kit.BasicServicesKit';
3843
3844try {
3845  let movement: inputMethodEngine.Movement = { direction: 1 };
3846  inputClient.selectByMovement(movement, (err: BusinessError) => {
3847    if (err) {
3848      console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
3849      return;
3850    }
3851    console.log('Succeeded in selecting by movement.');
3852  });
3853} catch (err) {
3854  console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
3855}
3856```
3857
3858### selectByMovement<sup>10+</sup>
3859
3860selectByMovement(movement: Movement): Promise&lt;void&gt;
3861
3862Selects text based on the specified range. This API uses a promise to return the result.
3863
3864**System capability**: SystemCapability.MiscServices.InputMethodFramework
3865
3866**Parameters**
3867
3868| Name  | Type                                                        | Mandatory| Description                  |
3869| -------- | ------------------------------------------------------------ | ---- | ---------------------- |
3870| movement | [Movement](#movement10) | Yes  | Direction in which the cursor moves when the text is selected.|
3871
3872**Return value**
3873
3874| Type               | Description                     |
3875| ------------------- | ------------------------- |
3876| Promise&lt;void&gt; | Promise that returns no value.|
3877
3878**Error codes**
3879
3880For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3881
3882| ID| Error Message                  |
3883| -------- | -------------------------- |
3884| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3885| 12800003 | input method client error. |
3886
3887**Example**
3888
3889```ts
3890import { BusinessError } from '@kit.BasicServicesKit';
3891
3892try {
3893  let movement: inputMethodEngine.Movement = { direction: 1 };
3894  inputClient.selectByMovement(movement).then(() => {
3895    console.log('Succeeded in selecting by movement.');
3896  }).catch((err: BusinessError) => {
3897    console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
3898  });
3899} catch (err) {
3900  console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
3901}
3902```
3903
3904### selectByMovementSync<sup>10+</sup>
3905
3906selectByMovementSync(movement: Movement): void
3907
3908Selects text based on the cursor movement direction.
3909
3910**System capability**: SystemCapability.MiscServices.InputMethodFramework
3911
3912**Parameters**
3913
3914| Name  | Type                   | Mandatory| Description                  |
3915| -------- | ----------------------- | ---- | ---------------------- |
3916| movement | [Movement](#movement10) | Yes  | Direction in which the cursor moves when the text is selected.|
3917
3918**Error codes**
3919
3920For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3921
3922| ID| Error Message                  |
3923| -------- | -------------------------- |
3924| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3925| 12800003 | input method client error. |
3926
3927**Example**
3928
3929```ts
3930try {
3931  let movement: inputMethodEngine.Movement = { direction: 1 };
3932  inputClient.selectByMovementSync(movement);
3933  console.log('Succeeded in selecting by movement.');
3934} catch (err) {
3935  console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
3936}
3937```
3938
3939### getTextIndexAtCursor<sup>10+</sup>
3940
3941getTextIndexAtCursor(callback: AsyncCallback&lt;number&gt;): void
3942
3943Obtains the index of the text where the cursor is located. This API uses an asynchronous callback to return the result.
3944
3945**System capability**: SystemCapability.MiscServices.InputMethodFramework
3946
3947**Parameters**
3948
3949| Name  | Type                       | Mandatory| Description                                                        |
3950| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
3951| 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.|
3952
3953**Error codes**
3954
3955For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
3956
3957| ID| Error Message                      |
3958| -------- | ------------------------------ |
3959| 12800003 | input method client error.     |
3960| 12800006 | Input method controller error. |
3961
3962**Example**
3963
3964```ts
3965import { BusinessError } from '@kit.BasicServicesKit';
3966
3967inputClient.getTextIndexAtCursor((err: BusinessError, index: number) => {
3968  if (err) {
3969    console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`);
3970    return;
3971  }
3972  console.log('Succeeded in getTextIndexAtCursor: ' + index);
3973});
3974```
3975
3976### getTextIndexAtCursor<sup>10+</sup>
3977
3978getTextIndexAtCursor(): Promise&lt;number&gt;
3979
3980Obtains the index of the text where the cursor is located. This API uses a promise to return the result.
3981
3982**System capability**: SystemCapability.MiscServices.InputMethodFramework
3983
3984**Return value**
3985
3986| Type                 | Description                                   |
3987| --------------------- | --------------------------------------- |
3988| Promise&lt;number&gt; | Promise used to return the result.|
3989
3990**Error codes**
3991
3992For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
3993
3994| ID| Error Message                      |
3995| -------- | ------------------------------ |
3996| 12800003 | input method client error.     |
3997| 12800006 | Input method controller error. |
3998
3999**Example**
4000
4001```ts
4002import { BusinessError } from '@kit.BasicServicesKit';
4003
4004inputClient.getTextIndexAtCursor().then((index: number) => {
4005  console.log('Succeeded in getTextIndexAtCursor: ' + index);
4006}).catch((err: BusinessError) => {
4007  console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`);
4008});
4009```
4010
4011### getTextIndexAtCursorSync<sup>10+</sup>
4012
4013getTextIndexAtCursorSync(): number
4014
4015Obtains the index of the text where the cursor is located.
4016
4017**System capability**: SystemCapability.MiscServices.InputMethodFramework
4018
4019**Return value**
4020
4021| Type  | Description                      |
4022| ------ | -------------------------- |
4023| number | Index of the text where the cursor is located.|
4024
4025**Error codes**
4026
4027For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
4028
4029| ID| Error Message                      |
4030| -------- | ------------------------------ |
4031| 12800003 | input method client error.     |
4032| 12800006 | Input method controller error. |
4033
4034**Example**
4035
4036```ts
4037try{
4038  let index: number = inputClient.getTextIndexAtCursorSync();
4039  console.log(`Succeeded in getTextIndexAtCursorSync, index: ${index}`);
4040} catch (err) {
4041  console.error(`Failed to getTextIndexAtCursorSync: ${JSON.stringify(err)}`);
4042}
4043```
4044
4045### sendExtendAction<sup>10+</sup>
4046
4047sendExtendAction(action: ExtendAction, callback: AsyncCallback&lt;void&gt;): void
4048
4049Sends an extended edit action. This API uses an asynchronous callback to return the result.
4050
4051> **NOTE**
4052>
4053> 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.
4054
4055**System capability**: SystemCapability.MiscServices.InputMethodFramework
4056
4057**Parameters**
4058
4059| Name  | Type                       | Mandatory| Description                                                        |
4060| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
4061| action | [ExtendAction](#extendaction10) | Yes  | Extended edit action to send.|
4062| 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.|
4063
4064**Error codes**
4065
4066For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
4067
4068| ID| Error Message                      |
4069| -------- | ------------------------------ |
4070| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4071| 12800003 | input method client error.     |
4072| 12800006 | Input method controller error. |
4073
4074**Example**
4075
4076```ts
4077import { BusinessError } from '@kit.BasicServicesKit';
4078
4079try {
4080  inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err: BusinessError) => {
4081    if (err) {
4082      console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
4083      return;
4084    }
4085    console.log('Succeeded in sending extend action.');
4086  });
4087} catch(err) {
4088  console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
4089}
4090```
4091
4092### sendExtendAction<sup>10+</sup>
4093
4094sendExtendAction(action: ExtendAction): Promise&lt;void&gt;
4095
4096Sends an extended edit action. This API uses a promise to return the result.
4097
4098>**NOTE**
4099>
4100> 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.
4101
4102**System capability**: SystemCapability.MiscServices.InputMethodFramework
4103
4104**Parameters**
4105
4106| Name| Type| Mandatory| Description|
4107| -------- | -------- | -------- | -------- |
4108| action | [ExtendAction](#extendaction10) | Yes| Extended edit action to send.|
4109
4110**Return value**
4111
4112| Type                 | Description                                   |
4113| --------------------- | --------------------------------------- |
4114| Promise&lt;void&gt; | Promise that returns no value.|
4115
4116**Error codes**
4117
4118For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
4119
4120| ID| Error Message                      |
4121| -------- | ------------------------------ |
4122| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
4123| 12800003 | input method client error.     |
4124| 12800006 | Input method controller error. |
4125
4126**Example**
4127
4128```ts
4129import { BusinessError } from '@kit.BasicServicesKit';
4130
4131try {
4132  inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => {
4133    console.log('Succeeded in sending extend action.');
4134  }).catch((err: BusinessError) => {
4135    console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
4136  });
4137} catch(err) {
4138  console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
4139}
4140```
4141
4142### sendPrivateCommand<sup>12+</sup>
4143
4144sendPrivateCommand(commandData: Record&lt;string, CommandDataType&gt;): Promise&lt;void&gt;
4145
4146Sends private data to the system component that needs to communicate with the input method application.
4147
4148>**NOTE**
4149>
4150> - 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.
4151> - The total size of the private data is 32 KB, and the maximum number of private data records is 5.
4152
4153**System capability**: SystemCapability.MiscServices.InputMethodFramework
4154
4155**Parameters**
4156
4157| Name     | Type                           | Mandatory| Description      |
4158| ----------- | ------------------------------- | ---- | ---------- |
4159| commandData | Record<string, [CommandDataType](#commanddatatype12)> | Yes  | Private data to send.|
4160
4161**Return value**
4162
4163| Type               | Description                     |
4164| ------------------- | ------------------------- |
4165| Promise&lt;void&gt; | Promise that returns no value.|
4166
4167**Error codes**
4168
4169For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
4170
4171| ID| Error Message                                      |
4172| -------- | ---------------------------------------------- |
4173| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
4174| 12800003 | input method client error.                     |
4175| 12800010 | not the preconfigured default input method. |
4176
4177**Example**
4178
4179```ts
4180import { inputMethodEngine } from '@kit.IMEKit';
4181import { BusinessError } from '@kit.BasicServicesKit';
4182
4183inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, textInputClient) => {
4184  try {
4185    let record: Record<string, inputMethodEngine.CommandDataType> = {
4186      "valueString1": "abcdefg",
4187      "valueString2": true,
4188      "valueString3": 500,
4189    }
4190    textInputClient.sendPrivateCommand(record).then(() => {
4191    }).catch((err: BusinessError) => {
4192      if (err !== undefined) {
4193        let error = err as BusinessError;
4194        console.error(`sendPrivateCommand catch error: ${error.code} ${error.message}`);
4195      }
4196    });
4197  } catch (err) {
4198    let error = err as BusinessError;
4199    console.error(`sendPrivateCommand catch error: ${error.code} ${error.message}`);
4200  }
4201})
4202```
4203
4204### getCallingWindowInfo<sup>12+</sup>
4205
4206getCallingWindowInfo(): Promise&lt;WindowInfo&gt;
4207
4208Obtains 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.
4209
4210>**NOTE**
4211>
4212>This API applies only to the input method applications that use [Panel](#panel10) as the soft keyboard window.
4213
4214**System capability**: SystemCapability.MiscServices.InputMethodFramework
4215
4216**Return value**
4217
4218| Type                                      | Description                                                 |
4219| ------------------------------------------ | ----------------------------------------------------- |
4220| Promise&lt;[WindowInfo](#windowinfo12)&gt; | Promise used to return the information obtained.|
4221
4222**Error codes**
4223
4224For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
4225
4226| ID| Error Message                         |
4227| -------- | --------------------------------- |
4228| 12800003 | input method client error.        |
4229| 12800012 | the input method panel does not exist. |
4230| 12800013 | window manager service error.     |
4231
4232**Example**
4233
4234```ts
4235import { BusinessError } from '@kit.BasicServicesKit';
4236
4237try {
4238  inputClient.getCallingWindowInfo().then((windowInfo: inputMethodEngine.WindowInfo) => {
4239    console.log(`windowInfo.rect: ${JSON.stringify(windowInfo.rect)}`);
4240    console.log('windowInfo.status: ' + JSON.stringify(windowInfo.status));
4241  }).catch((err: BusinessError) => {
4242    console.error(`Failed to getCallingWindowInfo: ${JSON.stringify(err)}`);
4243  });
4244} catch(err) {
4245    console.error(`Failed to getCallingWindowInfo: ${JSON.stringify(err)}`);
4246}
4247```
4248
4249### setPreviewText<sup>12+</sup>
4250
4251setPreviewText(text: string, range: Range): Promise&lt;void&gt;
4252
4253Sets the preview text. This API uses a promise to return the result.
4254
4255**System capability**: SystemCapability.MiscServices.InputMethodFramework
4256
4257**Parameters**
4258
4259| Name| Type             | Mandatory| Description                                                        |
4260| ------ | ----------------- | ---- | ------------------------------------------------------------ |
4261| text   | string            | Yes  | Preview text to set.                                          |
4262| 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.|
4263
4264**Return value**
4265
4266| Type               | Description                     |
4267| ------------------- | ------------------------- |
4268| Promise&lt;void&gt; | Promise that returns no value.|
4269
4270**Error codes**
4271
4272For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
4273
4274| ID| Error Message                                                    |
4275| -------- | ------------------------------------------------------------ |
4276| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
4277| 12800003 | input method client error.                                   |
4278| 12800011 | text preview not supported.                               |
4279
4280**Example**
4281
4282```ts
4283import { BusinessError } from '@kit.BasicServicesKit';
4284
4285try {
4286  let range: inputMethodEngine.Range = { start: 0, end: 1 };
4287  inputClient.setPreviewText('test', range).then(() => {
4288    console.log('Succeeded in setting preview text.');
4289  }).catch((err: BusinessError) => {
4290    console.error(`Failed to setPreviewText: ${JSON.stringify(err)}`);
4291  });
4292} catch(err) {
4293    console.error(`Failed to setPreviewText: ${JSON.stringify(err)}`);
4294}
4295```
4296
4297### setPreviewTextSync<sup>12+</sup>
4298
4299setPreviewTextSync(text: string, range: Range): void
4300
4301Sets the preview text.
4302
4303**System capability**: SystemCapability.MiscServices.InputMethodFramework
4304
4305**Parameters**
4306
4307| Name| Type             | Mandatory| Description                                                        |
4308| ------ | ----------------- | ---- | ------------------------------------------------------------ |
4309| text   | string            | Yes  | Preview text to set.                                          |
4310| 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.|
4311
4312**Error codes**
4313
4314For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
4315
4316| ID| Error Message                                                    |
4317| -------- | ------------------------------------------------------------ |
4318| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
4319| 12800003 | input method client error.                                   |
4320| 12800011 | text preview not supported.                               |
4321
4322**Example**
4323
4324```ts
4325try {
4326  let range: inputMethodEngine.Range = { start: 0, end: 1 };
4327  inputClient.setPreviewTextSync('test', range);
4328  console.log('Succeeded in setting preview text with synchronized method.');
4329} catch (err) {
4330  console.error(`Failed to setPreviewTextSync: ${JSON.stringify(err)}`);
4331}
4332```
4333
4334### finishTextPreview<sup>12+</sup>
4335
4336finishTextPreview(): Promise&lt;void&gt;
4337
4338Finishes the text preview. This API uses a promise to return the result.
4339
4340>**NOTE**
4341>
4342>If there is preview text in the current text box, calling this API will display the preview text on the screen.
4343
4344**System capability**: SystemCapability.MiscServices.InputMethodFramework
4345
4346**Return value**
4347
4348| Type               | Description                     |
4349| ------------------- | ------------------------- |
4350| Promise&lt;void&gt; | Promise that returns no value.|
4351
4352**Error codes**
4353
4354For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
4355
4356| ID| Error Message                      |
4357| -------- | ------------------------------ |
4358| 12800003 | input method client error.     |
4359| 12800011 | text preview not supported. |
4360
4361**Example**
4362
4363```ts
4364import { BusinessError } from '@kit.BasicServicesKit';
4365
4366try {
4367  inputClient.finishTextPreview().then(() => {
4368    console.log('Succeeded in finishing text preview.');
4369  }).catch((err: BusinessError) => {
4370    console.error(`Failed to finishTextPreview: ${JSON.stringify(err)}`);
4371  });
4372} catch(err) {
4373    console.error(`Failed to finishTextPreview: ${JSON.stringify(err)}`);
4374}
4375```
4376
4377### finishTextPreviewSync<sup>12+</sup>
4378
4379finishTextPreviewSync(): void
4380
4381Finishes the text preview.
4382
4383>**NOTE**
4384>
4385>If there is preview text in the current text box, calling this API will display the preview text on the screen.
4386
4387**System capability**: SystemCapability.MiscServices.InputMethodFramework
4388
4389**Error codes**
4390
4391For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
4392
4393| ID| Error Message                      |
4394| -------- | ------------------------------ |
4395| 12800003 | input method client error.     |
4396| 12800011 | text preview not supported. |
4397
4398**Example**
4399
4400```ts
4401try {
4402  inputClient.finishTextPreviewSync();
4403  console.log('Succeeded in finishing text preview with synchronized method.');
4404} catch (err) {
4405  console.error(`Failed to finishTextPreviewSync: ${JSON.stringify(err)}`);
4406}
4407```
4408
4409### sendMessage<sup>15+</sup>
4410
4411sendMessage(msgId: string, msgParam?: ArrayBuffer): Promise<void&gt;
4412
4413Sends the custom communication to the edit box application attached to the input method application. This API uses a promise to return the result.
4414
4415> **NOTE**
4416>
4417> 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.
4418>
4419> The maximum length of **msgId** is 256 B, and the maximum length of **msgParam** is 128 KB.
4420
4421**System capability**: SystemCapability.MiscServices.InputMethodFramework
4422
4423**Parameters**
4424
4425| Name  | Type       | Optional| Description                                                        |
4426| -------- | ----------- | ---- | ------------------------------------------------------------ |
4427| msgId    | string      | No  | Identifier of the custom data to be sent to the edit box application attached to the input method application.|
4428| msgParam | ArrayBuffer | Yes  | Message body of the custom data to be sent to the edit box application attached to the input method application.|
4429
4430**Return value**
4431
4432| Type               | Description                     |
4433| ------------------- | ------------------------- |
4434| Promise&lt;void&gt; | Promise that returns no value.|
4435
4436**Error codes**
4437
4438For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
4439
4440| ID| Error Message                                   |
4441| -------- | ------------------------------------------- |
4442| 401      | parameter error.                            |
4443| 12800003 | input method client error.                  |
4444| 12800009 | input method client detached.               |
4445| 12800014 | the input method is in basic mode.          |
4446| 12800015 | the other side does not accept the request. |
4447| 12800016 | input method client is not editable.        |
4448
4449**Example**
4450
4451```ts
4452import { BusinessError } from '@kit.BasicServicesKit';
4453
4454let msgId: string = "testMsgId";
4455let msgParam: ArrayBuffer = new ArrayBuffer(128);
4456inputMethodController.sendMessage(msgId, msgParam).then(() => {
4457  console.log('Succeeded send message.');
4458}).catch((err: BusinessError) => {
4459  console.error(`Failed to send message: ${JSON.stringify(err)}`);
4460});
4461```
4462
4463### recvMessage<sup>15+</sup>
4464
4465recvMessage(msgHandler?: MessageHandler): void;
4466
4467Registers or unregisters MessageHandler.
4468
4469> **NOTE**
4470>
4471> 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.
4472>
4473> If no parameter is set, unregister [MessageHandler](#messagehandler15). Its [onTerminated](#onterminated15) callback will be triggered.
4474
4475**System capability**: SystemCapability.MiscServices.InputMethodFramework
4476
4477**Parameters**
4478
4479| Name    | Type                               | Mandatory| Description                                                        |
4480| ---------- | ----------------------------------- | ---- | ------------------------------------------------------------ |
4481| msgHandler | [MessageHandler](#messagehandler15) | No  | This object receives custom communication data from the edit box application attached to the input method application through [onMessage](#onmessage15) and receives a message for terminating the subscription to this object through [onTerminated](#onterminated15).<br>If no parameter is set, unregister [MessageHandler](#messagehandler15). Its [onTerminated](#onterminated15) callback will be triggered.|
4482
4483**Return value**
4484
4485| Type| Description        |
4486| ---- | ------------ |
4487| void | No value is returned.|
4488
4489**Error codes**
4490
4491For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
4492
4493| ID| Error Message        |
4494| -------- | ---------------- |
4495| 401      | parameter error. |
4496
4497**Example**
4498
4499```ts
4500import { BusinessError } from '@kit.BasicServicesKit';
4501
4502try {
4503  inputMethodEngine.getInputMethodAbility()
4504    .on('inputStart', (kbController: inputMethodEngine.KeyboardController, client: inputMethodEngine.InputClient) => {
4505      let keyboardController = kbController;
4506      let inputClient = client;
4507      try {
4508        let messageHandler: inputMethodEngine.MessageHandler = {
4509          onTerminated(): void {
4510            console.log('OnTerminated.');
4511          },
4512          onMessage(msgId: string, msgParam?:ArrayBuffer): void {
4513            console.log('recv message.');
4514          }
4515        }
4516        inputClient.recvMessage(messageHandler);
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> | number | Yes  | Yes  | Immersive mode of the input method.|
4539| windowId<sup>18+</sup> | number | Yes| Yes| ID of the window where the edit box is located.|
4540| displayId<sup>18+</sup> | number | Yes  | Yes  | Screen ID of the window corresponding to the edit box. If window ID is not set, the screen ID of the focused window is used.|
4541
4542## KeyEvent
4543
4544Represents the attributes of a key.
4545
4546**System capability**: SystemCapability.MiscServices.InputMethodFramework
4547
4548| Name     | Type| Read-Only| Optional| Description        |
4549| --------- | -------- | ---- | ---- | ------------ |
4550| keyCode   | number   | Yes  | No  | Key value. For details, see [KeyCode](../apis-input-kit/js-apis-keycode.md#keycode).|
4551| keyAction | number   | Yes  | No  | Key event type.<br>- **2**: keydown event.<br>- **3**: keyup event.|
4552
4553## PanelFlag<sup>10+</sup>
4554
4555Enumerates the state types of the input method panel.
4556
4557**System capability**: SystemCapability.MiscServices.InputMethodFramework
4558
4559| Name        | Value| Description              |
4560| ------------ | -- | ------------------ |
4561| FLG_FIXED  | 0 | Fixed state type.|
4562| FLG_FLOATING | 1 | Floating state type.|
4563| FLAG_CANDIDATE<sup>15+</sup> | 2 | Candidate state type.|
4564
4565## PanelType<sup>10+</sup>
4566
4567Enumerates the types of the input method panel.
4568
4569**System capability**: SystemCapability.MiscServices.InputMethodFramework
4570
4571| Name        | Value| Description              |
4572| ------------ | -- | ------------------ |
4573| SOFT_KEYBOARD | 0 | Soft keyboard type.|
4574| STATUS_BAR   | 1 | Status bar type.|
4575
4576## PanelInfo<sup>10+</sup>
4577
4578Describes the attributes of the input method panel.
4579
4580**System capability**: SystemCapability.MiscServices.InputMethodFramework
4581
4582| Name     | Type| Read-Only| Optional| Description        |
4583| --------- | -------- | ---- | ---- | ------------ |
4584| type   	| [PanelType](#paneltype10)   | No  | No  | Type of the panel.|
4585| flag	    | [PanelFlag](#panelflag10)   | No  | Yes  | State type of the panel.|
4586
4587## PanelRect<sup>12+</sup>
4588
4589Represents the size of the input method panel.
4590
4591**System capability**: SystemCapability.MiscServices.InputMethodFramework
4592
4593| Name        | Type| Read-Only| Optional| Description              |
4594| ------------ | -------- | ---- | ---- | ------------------ |
4595| landscapeRect | [window.Rect](../apis-arkui/js-apis-window.md#rect7)   | No  | No  | Size of the input method panel window in landscape mode.|
4596| portraitRect | [window.Rect](../apis-arkui/js-apis-window.md#rect7)   | No  | No  | Size of the input method panel window in portrait mode.|
4597
4598## EnhancedPanelRect<sup>15+</sup>
4599
4600Indicates the size of the enhanced input method panel, including the custom avoid area and touch area.
4601
4602**System capability**: SystemCapability.MiscServices.InputMethodFramework
4603
4604| Name                | Type                                                        | Read-Only| Optional| Description                                                        |
4605| -------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
4606| 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**.|
4607| 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**.|
4608| 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.|
4609| 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.|
4610| 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.|
4611| 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.|
4612| 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.|
4613
4614## KeyboardArea<sup>15+</sup>
4615
4616Keyboard area on the panel.
4617
4618**System capability**: SystemCapability.MiscServices.InputMethodFramework
4619
4620| Name  | Type  | Read-Only| Optional| Description                                                        |
4621| ------ | ------ | ---- | ---- | ------------------------------------------------------------ |
4622| 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.|
4623| 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.|
4624| 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.|
4625| 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.|
4626
4627## WindowInfo<sup>12+</sup>
4628
4629Represents window information.
4630
4631**System capability**: SystemCapability.MiscServices.InputMethodFramework
4632
4633| Name  | Type                                                        | Read-Only| Optional| Description          |
4634| ------ | ------------------------------------------------------------ | ---- | ---- | -------------- |
4635| rect   | [window.Rect](../apis-arkui/js-apis-window.md#rect7)         | No  | No  | Rectangular area of the window.|
4636| status | [window.WindowStatusType](../apis-arkui/js-apis-window.md#windowstatustype11) | No  | No  | Window status type.|
4637
4638## ImmersiveMode<sup>15+</sup>
4639
4640Enumerates the immersive modes of the input method.
4641
4642**System capability**: SystemCapability.MiscServices.InputMethodFramework
4643
4644| Name        | Value| Description              |
4645| ------------ | -- | ------------------ |
4646| NONE_IMMERSIVE | 0 | The immersive mode is not used.|
4647| IMMERSIVE      | 1 | The immersive mode is used. Its style is determined by the input method application.|
4648| LIGHT_IMMERSIVE  | 2 | Immersive style in light mode.|
4649| DARK_IMMERSIVE   | 3 | Immersive style in dark mode.|
4650
4651## TextInputClient<sup>(deprecated)</sup>
4652
4653> **NOTE**
4654>
4655> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [InputClient](#inputclient9) instead.
4656
4657In 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.
4658
4659### getForward<sup>(deprecated)</sup>
4660
4661getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
4662
4663Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result.
4664
4665> **NOTE**
4666>
4667> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9) instead.
4668
4669**System capability**: SystemCapability.MiscServices.InputMethodFramework
4670
4671**Parameters**
4672
4673| Name| Type| Mandatory| Description|
4674| -------- | -------- | -------- | -------- |
4675| length | number | Yes| Text length, which cannot be less than 0.|
4676| 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.|
4677
4678**Example**
4679
4680```ts
4681import { BusinessError } from '@kit.BasicServicesKit';
4682
4683let length = 1;
4684textInputClient.getForward(length, (err: BusinessError, text: string) => {
4685  if (err) {
4686    console.error(`Failed to getForward: ${JSON.stringify(err)}`);
4687    return;
4688  }
4689  console.log('Succeeded in getting forward, text: ' + text);
4690});
4691```
4692
4693### getForward<sup>(deprecated)</sup>
4694
4695getForward(length:number): Promise&lt;string&gt;
4696
4697Obtains the specific-length text before the cursor. This API uses a promise to return the result.
4698
4699> **NOTE**
4700>
4701> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9) instead.
4702
4703**System capability**: SystemCapability.MiscServices.InputMethodFramework
4704
4705**Parameters**
4706
4707| Name| Type| Mandatory| Description|
4708| -------- | -------- | -------- | -------- |
4709| length | number | Yes| Text length, which cannot be less than 0.|
4710
4711**Return value**
4712
4713| Type                           | Description                                                        |
4714| ------------------------------- | ------------------------------------------------------------ |
4715| Promise&lt;string&gt; |  Promise used to return the specific-length text before the cursor.               |
4716
4717**Example**
4718
4719```ts
4720import { BusinessError } from '@kit.BasicServicesKit';
4721
4722let length = 1;
4723textInputClient.getForward(length).then((text: string) => {
4724  console.log('Succeeded in getting forward, text: ' + text);
4725}).catch((err: BusinessError) => {
4726  console.error(`Failed to getForward: ${JSON.stringify(err)}`);
4727});
4728```
4729
4730### getBackward<sup>(deprecated)</sup>
4731
4732getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
4733
4734Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result.
4735
4736> **NOTE**
4737>
4738> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9) instead.
4739
4740**System capability**: SystemCapability.MiscServices.InputMethodFramework
4741
4742**Parameters**
4743
4744| Name| Type| Mandatory| Description|
4745| -------- | -------- | -------- | -------- |
4746| length | number | Yes| Text length, which cannot be less than 0.|
4747| 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.|
4748
4749**Example**
4750
4751```ts
4752import { BusinessError } from '@kit.BasicServicesKit';
4753
4754let length = 1;
4755textInputClient.getBackward(length, (err: BusinessError, text: string) => {
4756  if (err) {
4757    console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
4758    return;
4759  }
4760  console.log('Succeeded in getting borward, text: ' + text);
4761});
4762```
4763
4764### getBackward<sup>(deprecated)</sup>
4765
4766getBackward(length:number): Promise&lt;string&gt;
4767
4768Obtains the specific-length text after the cursor. This API uses a promise to return the result.
4769
4770> **NOTE**
4771>
4772> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9) instead.
4773
4774**System capability**: SystemCapability.MiscServices.InputMethodFramework
4775
4776**Parameters**
4777
4778| Name| Type| Mandatory| Description|
4779| -------- | -------- | -------- | -------- |
4780| length | number | Yes| Text length, which cannot be less than 0.|
4781
4782**Return value**
4783
4784| Type                           | Description                                                        |
4785| ------------------------------- | ------------------------------------------------------------ |
4786| Promise&lt;string&gt; |  Promise used to return the specific-length text after the cursor.               |
4787
4788**Example**
4789
4790```ts
4791import { BusinessError } from '@kit.BasicServicesKit';
4792
4793let length = 1;
4794textInputClient.getBackward(length).then((text: string) => {
4795  console.log('Succeeded in getting backward: ' + JSON.stringify(text));
4796}).catch((err: BusinessError) => {
4797  console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
4798});
4799```
4800
4801### deleteForward<sup>(deprecated)</sup>
4802
4803deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
4804
4805Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result.
4806
4807> **NOTE**
4808>
4809> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9) instead.
4810
4811**System capability**: SystemCapability.MiscServices.InputMethodFramework
4812
4813**Parameters**
4814
4815| Name| Type| Mandatory| Description|
4816| -------- | -------- | -------- | -------- |
4817| length | number | Yes| Text length, which cannot be less than 0.|
4818| 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.|
4819
4820**Example**
4821
4822```ts
4823import { BusinessError } from '@kit.BasicServicesKit';
4824
4825let length = 1;
4826textInputClient.deleteForward(length, (err: BusinessError, result: boolean) => {
4827  if (err) {
4828    console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
4829    return;
4830  }
4831  if (result) {
4832    console.log('Succeeded in deleting forward.');
4833  } else {
4834    console.error('Failed to deleteForward.');
4835  }
4836});
4837```
4838
4839### deleteForward<sup>(deprecated)</sup>
4840
4841deleteForward(length:number): Promise&lt;boolean&gt;
4842
4843Deletes the fixed-length text before the cursor. This API uses a promise to return the result.
4844
4845> **NOTE**
4846>
4847> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9) instead.
4848
4849**System capability**: SystemCapability.MiscServices.InputMethodFramework
4850
4851**Parameters**
4852
4853| Name| Type  | Mandatory| Description      |
4854| ------ | ------ | ---- | ---------- |
4855| length | number | Yes  | Text length, which cannot be less than 0.|
4856
4857**Return value**
4858
4859| Type                  | Description          |
4860| ---------------------- | -------------- |
4861| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.|
4862
4863**Example**
4864
4865```ts
4866import { BusinessError } from '@kit.BasicServicesKit';
4867
4868let length = 1;
4869textInputClient.deleteForward(length).then((result: boolean) => {
4870  if (result) {
4871    console.log('Succeeded in deleting forward.');
4872  } else {
4873    console.error('Failed to delete forward.');
4874  }
4875}).catch((err: BusinessError) => {
4876  console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
4877});
4878```
4879
4880### deleteBackward<sup>(deprecated)</sup>
4881
4882deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
4883
4884Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result.
4885
4886> **NOTE**
4887>
4888> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9) instead.
4889
4890**System capability**: SystemCapability.MiscServices.InputMethodFramework
4891
4892**Parameters**
4893
4894| Name  | Type                        | Mandatory| Description          |
4895| -------- | ---------------------------- | ---- | -------------- |
4896| length   | number                       | Yes  | Text length, which cannot be less than 0.     |
4897| 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.|
4898
4899**Example**
4900
4901```ts
4902import { BusinessError } from '@kit.BasicServicesKit';
4903
4904let length = 1;
4905textInputClient.deleteBackward(length, (err: BusinessError, result: boolean) => {
4906  if (err) {
4907    console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
4908    return;
4909  }
4910  if (result) {
4911    console.log('Succeeded in deleting backward.');
4912  } else {
4913    console.error('Failed to deleteBackward.');
4914  }
4915});
4916```
4917
4918### deleteBackward<sup>(deprecated)</sup>
4919
4920deleteBackward(length:number): Promise&lt;boolean&gt;
4921
4922Deletes the fixed-length text after the cursor. This API uses a promise to return the result.
4923
4924> **NOTE**
4925>
4926> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9) instead.
4927
4928**System capability**: SystemCapability.MiscServices.InputMethodFramework
4929
4930**Parameters**
4931
4932| Name| Type| Mandatory| Description|
4933| -------- | -------- | -------- | -------- |
4934| length | number | Yes| Text length, which cannot be less than 0. |
4935
4936**Return value**
4937
4938| Type                           | Description                                                        |
4939| ------------------------------- | ------------------------------------------------------------ |
4940| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.|
4941
4942**Example**
4943
4944```ts
4945import { BusinessError } from '@kit.BasicServicesKit';
4946
4947let length = 1;
4948textInputClient.deleteBackward(length).then((result: boolean) => {
4949  if (result) {
4950    console.log('Succeeded in deleting backward.');
4951  } else {
4952    console.error('Failed to deleteBackward.');
4953  }
4954}).catch((err: BusinessError) => {
4955  console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
4956});
4957```
4958### sendKeyFunction<sup>(deprecated)</sup>
4959
4960sendKeyFunction(action: number, callback: AsyncCallback&lt;boolean&gt;): void
4961
4962Sends the function key. This API uses an asynchronous callback to return the result.
4963
4964> **NOTE**
4965>
4966> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9) instead.
4967
4968**System capability**: SystemCapability.MiscServices.InputMethodFramework
4969
4970**Parameters**
4971
4972| Name| Type| Mandatory| Description|
4973| -------- | -------- | -------- | -------- |
4974| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).|
4975| 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.|
4976
4977**Example**
4978
4979```ts
4980import { BusinessError } from '@kit.BasicServicesKit';
4981
4982let action = 1;
4983textInputClient.sendKeyFunction(action, (err: BusinessError, result: boolean) => {
4984  if (err) {
4985    console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
4986    return;
4987  }
4988  if (result) {
4989    console.log('Succeeded in sending key function.');
4990  } else {
4991    console.error('Failed to sendKeyFunction.');
4992  }
4993});
4994```
4995
4996### sendKeyFunction<sup>(deprecated)</sup>
4997
4998sendKeyFunction(action: number): Promise&lt;boolean&gt;
4999
5000Sends the function key. This API uses a promise to return the result.
5001
5002> **NOTE**
5003>
5004> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9) instead.
5005
5006**System capability**: SystemCapability.MiscServices.InputMethodFramework
5007
5008**Parameters**
5009
5010| Name| Type| Mandatory| Description|
5011| -------- | -------- | -------- | -------- |
5012| action | number | Yes| Action of the function key.<br>**0**: invalid key.<br>**1**: confirm key (Enter key).|
5013
5014**Return value**
5015
5016| Type                           | Description                                                        |
5017| ------------------------------- | ------------------------------------------------------------ |
5018| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the setting is successful, and **false** means the opposite.|
5019
5020**Example**
5021
5022```ts
5023import { BusinessError } from '@kit.BasicServicesKit';
5024
5025let action = 1;
5026textInputClient.sendKeyFunction(action).then((result: boolean) => {
5027  if (result) {
5028    console.log('Succeeded in sending key function.');
5029  } else {
5030    console.error('Failed to sendKeyFunction.');
5031  }
5032}).catch((err: BusinessError) => {
5033  console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
5034});
5035```
5036
5037### insertText<sup>(deprecated)</sup>
5038
5039insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
5040
5041Inserts text. This API uses an asynchronous callback to return the result.
5042
5043> **NOTE**
5044>
5045> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9) instead.
5046
5047**System capability**: SystemCapability.MiscServices.InputMethodFramework
5048
5049**Parameters**
5050
5051| Name| Type| Mandatory| Description|
5052| -------- | -------- | -------- | -------- |
5053| text | string | Yes| Text to insert.|
5054| 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.|
5055
5056**Example**
5057
5058```ts
5059import { BusinessError } from '@kit.BasicServicesKit';
5060
5061textInputClient.insertText('test', (err: BusinessError, result: boolean) => {
5062  if (err) {
5063    console.error(`Failed to insertText: ${JSON.stringify(err)}`);
5064    return;
5065  }
5066  if (result) {
5067    console.log('Succeeded in inserting text.');
5068  } else {
5069    console.error('Failed to insertText.');
5070  }
5071});
5072```
5073
5074### insertText<sup>(deprecated)</sup>
5075
5076insertText(text:string): Promise&lt;boolean&gt;
5077
5078Inserts text. This API uses a promise to return the result.
5079
5080> **NOTE**
5081>
5082> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9) instead.
5083
5084**System capability**: SystemCapability.MiscServices.InputMethodFramework
5085
5086**Parameters**
5087
5088| Name| Type| Mandatory| Description|
5089| -------- | -------- | -------- | -------- |
5090| text | string | Yes| Text to insert.|
5091
5092**Return value**
5093
5094| Type                           | Description                                                        |
5095| ------------------------------- | ------------------------------------------------------------ |
5096| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the insertion is successful, and **false** means the opposite.|
5097
5098**Example**
5099
5100```ts
5101import { BusinessError } from '@kit.BasicServicesKit';
5102
5103textInputClient.insertText('test').then((result: boolean) => {
5104  if (result) {
5105    console.log('Succeeded in inserting text.');
5106  } else {
5107    console.error('Failed to insertText.');
5108  }
5109}).catch((err: BusinessError) => {
5110  console.error(`Failed to insertText: ${JSON.stringify(err)}`);
5111});
5112```
5113
5114### getEditorAttribute<sup>(deprecated)</sup>
5115
5116getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
5117
5118Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result.
5119
5120> **NOTE**
5121>
5122> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9) instead.
5123
5124**System capability**: SystemCapability.MiscServices.InputMethodFramework
5125
5126**Parameters**
5127
5128| Name   | Type  | Mandatory | Description  |
5129| -------- | ----- | ----- | ----- |
5130| 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.|
5131
5132**Example**
5133
5134```ts
5135import { BusinessError } from '@kit.BasicServicesKit';
5136
5137textInputClient.getEditorAttribute((err: BusinessError, editorAttribute: inputMethodEngine.EditorAttribute) => {
5138  if (err) {
5139    console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
5140    return;
5141  }
5142  console.log(`editorAttribute.inputPattern: ${editorAttribute.inputPattern}`;
5143  console.log(`editorAttribute.enterKeyType: ${editorAttribute.enterKeyType}`);
5144});
5145```
5146
5147### getEditorAttribute<sup>(deprecated)</sup>
5148
5149getEditorAttribute(): Promise&lt;EditorAttribute&gt;
5150
5151Obtains the attribute of the edit box. This API uses a promise to return the result.
5152
5153> **NOTE**
5154>
5155> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9) instead.
5156
5157**System capability**: SystemCapability.MiscServices.InputMethodFramework
5158
5159**Return value**
5160
5161| Type                           | Description                                                        |
5162| ------------------------------- | ------------------------------------------------------------ |
5163| Promise&lt;[EditorAttribute](#editorattribute)&gt; |  Promise used to return the attribute of the edit box.          |
5164
5165**Example**
5166
5167```ts
5168import { BusinessError } from '@kit.BasicServicesKit';
5169
5170textInputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => {
5171  console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
5172  console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
5173}).catch((err: BusinessError) => {
5174  console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
5175});
5176```
5177<!--no_check-->
5178