• 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```
12import inputMethodEngine from '@ohos.inputMethodEngine';
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 Enter key.|
24| ENTER_KEY_TYPE_GO | number | 2 | The Enter key takes the user to the target.|
25| ENTER_KEY_TYPE_SEARCH | number | 3 | The Enter key takes the user to the results of their searching.|
26| ENTER_KEY_TYPE_SEND | number | 4 | The Enter key sends the text to its target.|
27| ENTER_KEY_TYPE_NEXT | number | 5 | The Enter key takes the user to the next field.|
28| ENTER_KEY_TYPE_DONE | number | 6 | The Enter key takes the user to the next line.|
29| ENTER_KEY_TYPE_PREVIOUS | number | 7 | The Enter key takes the user to the previous field.|
30| PATTERN_NULL | number | -1 | Any type of edit box.|
31| PATTERN_TEXT | number | 0 | Text edit box.|
32| PATTERN_NUMBER | number | 2 | Number edit box.|
33| PATTERN_PHONE | number | 3 | Phone number edit box.|
34| PATTERN_DATETIME | number | 4 | Date edit box.|
35| PATTERN_EMAIL | number | 5 | Email edit box.|
36| PATTERN_URI | number | 6 | URI edit box.|
37| PATTERN_PASSWORD | number | 7 | Password edit box.|
38| OPTION_ASCII | number | 20 | ASCII values are allowed.|
39| OPTION_NONE | number | 0 | No input attribute is specified.|
40| OPTION_AUTO_CAP_CHARACTERS | number | 2 | Characters are allowed.|
41| OPTION_AUTO_CAP_SENTENCES | number | 8 | Sentences are allowed.|
42| OPTION_AUTO_WORDS | number | 4 | Words are allowed.|
43| OPTION_MULTI_LINE | number | 1 | Multiple lines are allowed.|
44| OPTION_NO_FULLSCREEN | number | 10 | Half-screen style.|
45| FLAG_SELECTING | number | 2 | The edit box is being selected.|
46| FLAG_SINGLE_LINE | number | 1 | The edit box allows only single-line input.|
47| DISPLAY_MODE_PART | number | 0 | The edit box is displayed in half-screen mode.|
48| DISPLAY_MODE_FULL | number | 1 | The edit box is displayed in full screen.|
49| CURSOR_UP<sup>9+</sup> | number | 1 | The caret moves upward.|
50| CURSOR_DOWN<sup>9+</sup> | number | 2 | The caret moves downward.|
51| CURSOR_LEFT<sup>9+</sup> | number | 3 | The caret moves leftward.|
52| CURSOR_RIGHT<sup>9+</sup> | number | 4 | The caret moves rightward.|
53| WINDOW_TYPE_INPUT_METHOD_FLOAT<sup>9+</sup> | number | 2105 | The input method is displayed in a floating window.|
54
55## inputMethodEngine.getInputMethodAbility<sup>9+</sup>
56
57getInputMethodAbility(): InputMethodAbility
58
59Obtains an [InputMethodAbility](#inputmethodability) instance for the input method.
60
61This API can be called only by an input method.
62
63The 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.
64
65**System capability**: SystemCapability.MiscServices.InputMethodFramework
66
67**Return value**
68
69| Type                                     | Description              |
70| ----------------------------------------- | ------------------ |
71| [InputMethodAbility](#inputmethodability) | **InputMethodAbility** instance.|
72
73**Example**
74
75```js
76let InputMethodAbility = inputMethodEngine.getInputMethodAbility();
77```
78
79## inputMethodEngine.getKeyboardDelegate<sup>9+</sup>
80
81getKeyboardDelegate(): KeyboardDelegate
82
83Obtains 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.
84
85**System capability**: SystemCapability.MiscServices.InputMethodFramework
86
87**Return value**
88
89| Type                                 | Description                    |
90| ------------------------------------- | ------------------------ |
91| [KeyboardDelegate](#keyboarddelegate) | **KeyboardDelegate** instance.|
92
93**Example**
94
95```js
96let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate();
97```
98
99## inputMethodEngine.getInputMethodEngine<sup>(deprecated)</sup>
100
101getInputMethodEngine(): InputMethodEngine
102
103Obtains an [InputMethodEngine](#inputmethodengine) instance for the input method. The input method can use the obtained instance to subscribe to a soft keyboard display/hide request event.
104
105> **NOTE**
106>
107> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethodAbility()](#inputmethodenginegetinputmethodability9) instead.
108
109**System capability**: SystemCapability.MiscServices.InputMethodFramework
110
111**Return value**
112
113| Type                                     | Description              |
114| ----------------------------------------- | ------------------ |
115| [InputMethodEngine](#inputmethodengine) | **InputMethodAbility** instance.|
116
117**Example**
118
119```js
120let InputMethodEngine = inputMethodEngine.getInputMethodEngine();
121```
122
123## inputMethodEngine.createKeyboardDelegate<sup>(deprecated)</sup>
124
125createKeyboardDelegate(): KeyboardDelegate
126
127Obtains 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.
128
129> **NOTE**
130>
131>This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getKeyboardDelegate()](#inputmethodenginegetkeyboarddelegate9) instead.
132
133**System capability**: SystemCapability.MiscServices.InputMethodFramework
134
135**Return value**
136
137| Type                                 | Description                    |
138| ------------------------------------- | ------------------------ |
139| [KeyboardDelegate](#keyboarddelegate) | **KeyboardDelegate** instance.|
140
141**Example**
142
143```js
144let keyboardDelegate = inputMethodEngine.createKeyboardDelegate();
145```
146
147## InputMethodEngine
148
149In the following API examples, you must first use **[getInputMethodEngine](#inputmethodenginegetinputmethodenginedeprecated)** to obtain an **InputMethodEngine** instance, and then call the APIs using the obtained instance.
150
151### on('inputStart')
152
153on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
154
155Enables listening for the input method binding event. This API uses an asynchronous callback to return the result.
156
157**System capability**: SystemCapability.MiscServices.InputMethodFramework
158
159**Parameters**
160
161| Name  | Type                           | Mandatory| Description                                                        |
162| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
163| type     | string                        | Yes  | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
164| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclientdeprecated)) => void | Yes| Callback used to return the **KeyboardController** and **TextInputClient** instances.|
165
166**Example**
167
168```js
169inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => {
170  let keyboardController = kbController;
171  let textInputClient = textClient;
172});
173```
174
175### off('inputStart')
176
177off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
178
179Cancels listening for the input method binding event.
180
181**System capability**: SystemCapability.MiscServices.InputMethodFramework
182
183**Parameters**
184
185| Name  | Type                | Mandatory| Description                    |
186| -------- | -------------------- | ---- | ------------------------ |
187| type | string                                                       | Yes  | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
188| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclientdeprecated)) => void | No| Callback used to return the **KeyboardController** and **TextInputClient** instances.|
189
190**Example**
191
192```js
193inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textInputClient) => {
194  console.log('delete inputStart notification.');
195});
196```
197
198### on('keyboardShow'|'keyboardHide')
199
200on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
201
202Enables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result.
203
204**System capability**: SystemCapability.MiscServices.InputMethodFramework
205
206**Parameters**
207
208| Name  | Type  | Mandatory| Description                                                        |
209| -------- | ------ | ---- | ------------------------------------------------------------ |
210| type     | string | Yes  | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.|
211| callback | () => void   | Yes  | Callback used to return the result.                                                  |
212
213**Example**
214
215```js
216inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => {
217  console.log('inputMethodEngine keyboardShow.');
218});
219inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => {
220  console.log('inputMethodEngine keyboardHide.');
221});
222```
223
224### off('keyboardShow'|'keyboardHide')
225
226off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
227
228Disables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result.
229
230**System capability**: SystemCapability.MiscServices.InputMethodFramework
231
232**Parameters**
233
234| Name  | Type  | Mandatory| Description                                                        |
235| -------- | ------ | ---- | ------------------------------------------------------------ |
236| type     | string | Yes  | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.|
237| callback | () => void   | No  | Callback used to return the result.|
238
239**Example**
240
241```js
242inputMethodEngine.getInputMethodEngine().off('keyboardShow');
243inputMethodEngine.getInputMethodEngine().off('keyboardHide');
244```
245
246## InputMethodAbility
247
248In the following API examples, you must first use **[getInputMethodAbility](#inputmethodenginegetinputmethodability9)** to obtain an **InputMethodAbility** instance, and then call the APIs using the obtained instance.
249
250### on('inputStart')<sup>9+</sup>
251
252on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: InputClient) => void): void
253
254Enables listening for the input method binding event. This API uses an asynchronous callback to return the result.
255
256**System capability**: SystemCapability.MiscServices.InputMethodFramework
257
258**Parameters**
259
260| Name  | Type                           | Mandatory| Description                                                        |
261| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
262| type     | string                        | Yes  | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
263| callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | Yes| Callback used to return the result.|
264
265**Example**
266
267```js
268inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => {
269  let keyboardController = kbController;
270  let inputClient = client;
271});
272```
273
274### off('inputStart')<sup>9+</sup>
275
276off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClient: InputClient) => void): void
277
278Cancels listening for the input method binding event. This API uses an asynchronous callback to return the result.
279
280**System capability**: SystemCapability.MiscServices.InputMethodFramework
281
282**Parameters**
283
284| Name  | Type                | Mandatory| Description                    |
285| -------- | -------------------- | ---- | ------------------------ |
286| type | string                                                       | Yes  | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
287| callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | No| Callback used to return the result.|
288
289**Example**
290
291```js
292inputMethodEngine.getInputMethodAbility().off('inputStart');
293```
294
295### on('inputStop')<sup>9+</sup>
296
297on(type: 'inputStop', callback: () => void): void
298
299Enables listening for the input method unbinding event. This API uses an asynchronous callback to return the result.
300
301**System capability**: SystemCapability.MiscServices.InputMethodFramework
302
303**Parameters**
304
305| Name  | Type  | Mandatory| Description                                                        |
306| -------- | ------ | ---- | ------------------------------------------------------------ |
307| type     | string | Yes  | Listening type.<br>The value **'inputStop'** indicates the input method unbinding event.|
308| callback | () => void   | Yes  | Callback used to return the result.                                                  |
309
310**Example**
311
312```js
313inputMethodEngine.getInputMethodAbility().on('inputStop', () => {
314  console.log('inputMethodAbility inputStop');
315});
316```
317
318### off('inputStop')<sup>9+</sup>
319
320off(type: 'inputStop', callback: () => void): void
321
322Cancels listening for the input method stop event. This API uses an asynchronous callback to return the result.
323
324**System capability**: SystemCapability.MiscServices.InputMethodFramework
325
326**Parameters**
327
328| Name  | Type  | Mandatory| Description                                                        |
329| -------- | ------ | ---- | ------------------------------------------------------------ |
330| type     | string | Yes  | Listening type.<br>The value **'inputStop'** indicates the input method unbinding event.|
331| callback | () => void   | Yes  | Callback used to return the result.                                                  |
332
333**Example**
334
335```js
336inputMethodEngine.getInputMethodAbility().off('inputStop', () => {
337  console.log('inputMethodAbility delete inputStop notification.');
338});
339```
340
341### on('setCallingWindow')<sup>9+</sup>
342
343on(type: 'setCallingWindow', callback: (wid: number) => void): void
344
345Enables listening for the window invocation setting 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  | Listening type.<br>The value **'setCallingWindow'** indicates the window invocation setting event.|
354| callback | (wid: number) => void | Yes  | Callback used to return the window ID of the caller.                                           |
355
356**Example**
357
358```js
359inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid) => {
360  console.log('inputMethodAbility setCallingWindow');
361});
362```
363
364### off('setCallingWindow')<sup>9+</sup>
365
366off(type: 'setCallingWindow', callback: (wid:number) => void): void
367
368Disables listening for the window invocation setting event. This API uses an asynchronous callback to return the result.
369
370**System capability**: SystemCapability.MiscServices.InputMethodFramework
371
372**Parameters**
373
374| Name  | Type  | Mandatory| Description                                                        |
375| -------- | ------ | ---- | ------------------------------------------------------------ |
376| type     | string | Yes  | Listening type.<br>The value **'setCallingWindow'** indicates the window invocation setting event.|
377| callback | (wid:number) => void | Yes  | Callback used to return the window ID of the caller.                                |
378
379**Example**
380
381```js
382inputMethodEngine.getInputMethodAbility().off('setCallingWindow', (wid) => {
383  console.log('inputMethodAbility delete setCallingWindow notification.');
384});
385```
386
387### on('keyboardShow'|'keyboardHide')<sup>9+</sup>
388
389on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
390
391Enables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result.
392
393**System capability**: SystemCapability.MiscServices.InputMethodFramework
394
395**Parameters**
396
397| Name  | Type  | Mandatory| Description                                                        |
398| -------- | ------ | ---- | ------------------------------------------------------------ |
399| type     | string | Yes  | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.|
400| callback | () => void   | Yes  | Callback used to return the result.                                                  |
401
402**Example**
403
404```js
405inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => {
406  console.log('InputMethodAbility keyboardShow.');
407});
408inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => {
409  console.log('InputMethodAbility keyboardHide.');
410});
411```
412
413### off('keyboardShow'|'keyboardHide')<sup>9+</sup>
414
415off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
416
417Disables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result.
418
419**System capability**: SystemCapability.MiscServices.InputMethodFramework
420
421**Parameters**
422
423| Name  | Type  | Mandatory| Description                                                        |
424| -------- | ------ | ---- | ------------------------------------------------------------ |
425| type     | string | Yes  | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.|
426| callback | () => void   | No  | Callback used to return the result.    |
427
428**Example**
429
430```js
431inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => {
432  console.log('InputMethodAbility delete keyboardShow notification.');
433});
434inputMethodEngine.getInputMethodAbility().off('keyboardHide', () => {
435  console.log('InputMethodAbility delete keyboardHide notification.');
436});
437```
438
439### on('setSubtype')<sup>9+</sup>
440
441on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => void): void
442
443Enables listening for the input method subtype setting event. This API uses an asynchronous callback to return the result.
444
445**System capability**: SystemCapability.MiscServices.InputMethodFramework
446
447**Parameters**
448
449| Name   | Type| Mandatory | Description|
450| -------- | --- | ---- | --- |
451| type     | string | Yes  | Listening type.<br>The value **'setSubtype'** indicates the input method subtype setting event.|
452| callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | Yes  | Callback used to return the input method subtype.                          |
453
454**Example**
455
456```js
457inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype) => {
458  console.log('InputMethodAbility setSubtype.');
459});
460```
461
462### off('setSubtype')<sup>9+</sup>
463
464off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void
465
466Disables listening for the input method subtype setting event. This API uses an asynchronous callback to return the result.
467
468**System capability**: SystemCapability.MiscServices.InputMethodFramework
469
470**Parameters**
471
472| Name  | Type | Mandatory| Description  |
473| ------- | ----- | ---- | ---- |
474| type     | string | Yes  | Listening type.<br>The value **'setSubtype'** indicates the input method subtype setting event.|
475| callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | No  | Callback used to return the input method subtype. |
476
477**Example**
478
479```js
480inputMethodEngine.getInputMethodAbility().off('setSubtype', () => {
481  console.log('InputMethodAbility delete setSubtype notification.');
482});
483```
484
485### createPanel<sup>10+</sup>
486
487createPanel(ctx: BaseContext, info: PanelInfo, callback: AsyncCallback\<Panel>): void
488
489Creates an input method panel. This API uses an asynchronous callback to return the result.
490
491This API can be called only by an input method. Only one SOFT_KEYBOARD panel and one STATUS_BAR panel can be created for a single input method application.
492
493**System capability**: SystemCapability.MiscServices.InputMethodFramework
494
495**Parameters**
496
497| Name  | Type       | Mandatory| Description                    |
498| ------- | ----------- | ---- | ------------------------ |
499| ctx     | [BaseContext](js-apis-inner-application-baseContext.md) | Yes  | Context of the current input method.|
500| info    | [PanelInfo](#panelinfo10)   | Yes  | Information about the input method panel.|
501| callback | AsyncCallback\<[Panel](#panel10)> | Yes  | Callback used to return the result. If the operation is successful, the created input method panel is returned. |
502
503**Error codes**
504
505| Error Code ID  | Error Message                      |
506| ---------- | ----------------------------- |
507| 12800004   | not an input method extension. |
508
509**Example**
510
511```js
512let panelInfo: inputMethodEngine.PanelInfo = {
513  panelType: inputMethodEngine.PanelType.SOFT_KEYBOARD,
514  panelFlag: inputMethodEngine.PanelFlag.FLG_FIXED
515}
516try {
517  inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => {
518    if (err) {
519      console.error(`Failed to createPanel: ${JSON.stringify(err)}`);
520      return;
521    }
522    console.log('Succeed in creating panel.');
523  })
524} catch(err) {
525  console.error(`Failed to createPanel: ${JSON.stringify(err)}`);
526}
527```
528
529### createPanel<sup>10+</sup>
530
531createPanel(ctx: BaseContext, info: PanelInfo): Promise\<Panel>
532
533Creates an input method panel. This API uses a promise to return the result.
534
535This API can be called only by an input method. Only one SOFT_KEYBOARD panel and one STATUS_BAR panel can be created for a single input method application.
536
537**System capability**: SystemCapability.MiscServices.InputMethodFramework
538
539**Parameters**
540
541| Name  | Type       | Mandatory| Description                    |
542| ------- | ----------- | ---- | ------------------------ |
543| ctx     | [BaseContext](js-apis-inner-application-baseContext.md) | Yes  | Context of the current input method.|
544| info    | [PanelInfo](#panelinfo10)   | Yes  | Information about the input method panel.|
545
546**Return value**
547| Type  | Description                                                                |
548| ------- | ------------------------------------------------------------------ |
549| Promise\<[Panel](#panel10)> | Promise used to return the result. If the operation is successful, the created input method panel is returned. |
550
551**Error codes**
552
553| Error Code ID  | Error Message                      |
554| ---------- | ----------------------------- |
555| 12800004   | not an input method extension. |
556
557**Example**
558
559```js
560let panelInfo: inputMethodEngine.PanelInfo = {
561  panelType: inputMethodEngine.PanelType.SOFT_KEYBOARD,
562  panelFlag: inputMethodEngine.PanelFlag.FLG_FIXED
563}
564inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo).then((panel) => {
565  console.log('Succeed in creating panel.');
566}).catch((err) => {
567  console.error(`Failed to create panel: ${JSON.stringify(err)}`);
568})
569```
570
571### destroyPanel<sup>10+</sup>
572
573destroyPanel(panel: Panel, callback: AsyncCallback\<void>): void;
574
575Destroys an input method panel. This API uses an asynchronous callback to return the result.
576
577**System capability**: SystemCapability.MiscServices.InputMethodFramework
578
579**Parameters**
580
581| Name  | Type       | Mandatory| Description                    |
582| ------- | ----------- | ---- | ------------------------ |
583| panel     | [Panel](#panel10) | Yes  | Input method panel to destroy.|
584| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object. |
585
586**Example**
587
588```js
589let panelInfo: inputMethodEngine.PanelInfo = {
590  panelType: inputMethodEngine.PanelType.SOFT_KEYBOARD,
591  panelFlag: inputMethodEngine.PanelFlag.FLG_FIXED
592}
593try {
594  inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => {
595    if (err) {
596      console.error(`Failed to create panel: ${JSON.stringify(err)}`);
597      return;
598    }
599	globalThis.inputMethodPanel = panel;
600    console.log('Succeed in creating panel.');
601  })
602} catch(err) {
603  console.error(`Failed to create panel: ${JSON.stringify(err)}`);
604}
605
606try {
607  inputMethodEngine.getInputMethodAbility().destroyPanel(globalThis.inputMethodPanel, (err) => {
608    if(err !== undefined) {
609      console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
610      return;
611    }
612    console.log('Succeed in destroying panel.');
613  })
614} catch(err) {
615  console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
616}
617```
618
619### destroyPanel<sup>10+</sup>
620
621destroyPanel(panel: Panel): Promise\<void>;
622
623Destroys an input method panel. This API uses a promise to return the result.
624
625**System capability**: SystemCapability.MiscServices.InputMethodFramework
626
627**Parameters**
628
629| Name  | Type       | Mandatory| Description                    |
630| ---------| ----------- | ---- | ------------------------ |
631| panel    | [Panel](#panel10)       | Yes  | Input method panel to destroy.     |
632
633**Return value**
634| Type   | Description                                                                |
635| ------- | -------------------------------------------------------------------- |
636| Promise\<void> | Promise that returns no value.|
637
638**Example**
639
640```js
641let panelInfo: inputMethodEngine.PanelInfo = {
642  panelType: inputMethodEngine.PanelType.SOFT_KEYBOARD,
643  panelFlag: inputMethodEngine.PanelFlag.FLG_FIXED
644}
645try {
646  inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo, (err, panel) => {
647    if (err) {
648      console.error(`Failed to create panel: ${JSON.stringify(err)}`);
649      return;
650    }
651	globalThis.inputMethodPanel = panel;
652    console.log('Succeed in creating panel.');
653  })
654} catch(err) {
655  console.error(`Failed to create panel: ${JSON.stringify(err)}`);
656}
657
658try {
659  inputMethodEngine.getInputMethodAbility().destroyPanel(globalThis.inputMethodPanel).then(() => {
660    console.log('Succeed in destroying panel.');
661  }).catch((err) => {
662    console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
663  });
664} catch (err) {
665  console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
666}
667```
668
669## KeyboardDelegate
670
671In the following API examples, you must first use **[getKeyboardDelegate](#inputmethodenginegetkeyboarddelegate9)** to obtain a **KeyboardDelegate** instance, and then call the APIs using the obtained instance.
672
673### on('keyDown'|'keyUp')
674
675on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
676
677Enables listening for a keyboard event. This API uses an asynchronous callback to return the result.
678
679**System capability**: SystemCapability.MiscServices.InputMethodFramework
680
681**Parameters**
682
683| Name  | Type                           | Mandatory| Description                                                        |
684| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
685| type   | string         | Yes  | Listening type.<br>The value **'keyDown'** indicates the keydown event.<br>The value **'keyUp'** indicates the keyup event.|
686| callback | (event: [KeyEvent](#keyevent)) => boolean | Yes| Callback used to return the key information.|
687
688**Example**
689
690```js
691inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent) => {
692  console.log('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode));
693  console.log('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction));
694  return true;
695});
696inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent) => {
697  console.log('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode));
698  console.log('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction));
699  return true;
700});
701```
702
703### off('keyDown'|'keyUp')
704
705off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
706
707Disables listening for a keyboard event. This API uses an asynchronous callback to return the result.
708
709**System capability**: SystemCapability.MiscServices.InputMethodFramework
710
711**Parameters**
712
713| Name   | Type    | Mandatory | Description |
714| -------- | ------- | ---- | ----- |
715| type     | string  | Yes  | Listening type.<br>The value **'keyDown'** indicates the keydown event.<br>The value **'keyUp'** indicates the keyup event.|
716| callback | (event: [KeyEvent](#keyevent)) => boolean | No  | Callback used to return the key information. |
717
718**Example**
719
720```js
721inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent) => {
722  console.log('delete keyUp notification.');
723  return true;
724});
725inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => {
726  console.log('delete keyDown notification.');
727  return true;
728});
729```
730
731### on('keyEvent')<sup>10+</sup>
732
733on(type: 'keyEvent', callback: (event: InputKeyEvent) => boolean): void
734
735Enables listening for a keyboard event. This API uses an asynchronous callback to return the result.
736
737**System capability**: SystemCapability.MiscServices.InputMethodFramework
738
739**Parameters**
740
741| Name  | Type    | Mandatory| Description                                                        |
742| -------- | -------- | ---- | ------------------------------------------------------------ |
743| type     | string   | Yes  | Listening type.<br>The value **'keyEvent'** indicates the keyboard event.|
744| callback | function | Yes  | Callback used to return the result.<br>- The input parameter, of the [InputKeyEvent](js-apis-keyevent.md#KeyEvent) type, indicates the key event information.<br>- If the event is consumed by the event subscriber, **true** is returned. Otherwise, **false** is returned.|
745
746**Example**
747
748```js
749inputMethodEngine.getKeyboardDelegate().on('keyEvent', (keyEvent) => {
750  console.log('inputMethodEngine keyEvent.action:' + JSON.stringify(keyEvent.action));
751  console.log('inputMethodEngine keyEvent.key.code:' + JSON.stringify(keyEvent.key.code));
752  console.log('inputMethodEngine keyEvent.ctrlKey:' + JSON.stringify(keyEvent.ctrlKey));
753  return true;
754});
755```
756
757### off('keyEvent')<sup>10+</sup>
758
759off(type: 'keyEvent', callback?: (event: InputKeyEvent) => boolean): void
760
761Disables listening for a keyboard event. This API uses an asynchronous callback to return the result.
762
763**System capability**: SystemCapability.MiscServices.InputMethodFramework
764
765**Parameters**
766
767| Name  | Type    | Mandatory| Description                                                        |
768| -------- | -------- | ---- | ------------------------------------------------------------ |
769| type     | string   | Yes  | Listening type.<br>The value **'keyEvent'** indicates the keyboard event.|
770| callback | function | No  | Callback to be unregistered.<br>- The input parameter, of the [InputKeyEvent](js-apis-keyevent.md#KeyEvent) type, indicates the key event information.<br>- If the event is consumed by the event subscriber, **true** is returned. Otherwise, **false** is returned.<br>- This parameter is optional. If this parameter is not specified, all callbacks registered for the event will be unregistered.|
771
772**Example**
773
774```js
775inputMethodEngine.getKeyboardDelegate().off('keyEvent', (keyEvent) => {
776  console.log('This is a callback function which will be deregistered.');
777  return true;
778});
779inputMethodEngine.getKeyboardDelegate().off('keyEvent');
780```
781
782### on('cursorContextChange')
783
784on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void
785
786Enables listening for the cursor change event. This API uses an asynchronous callback to return the result.
787
788**System capability**: SystemCapability.MiscServices.InputMethodFramework
789
790**Parameters**
791
792| Name   | Type | Mandatory | Description |
793| -------- | ---- | ---- | ----- |
794| type     | string | Yes  | Listening type.<br>The value **'cursorContextChange'** indicates the cursor change event.|
795| 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**: x coordinate of the bottom of the cursor.<br>- **height**: height of the cursor.|
796
797**Example**
798
799```js
800inputMethodEngine.getKeyboardDelegate().on('cursorContextChange', (x, y, height) => {
801  console.log('inputMethodEngine cursorContextChange x:' + x);
802  console.log('inputMethodEngine cursorContextChange y:' + y);
803  console.log('inputMethodEngine cursorContextChange height:' + height);
804});
805```
806
807### off('cursorContextChange')
808
809off(type: 'cursorContextChange', callback?: (x: number, y: number, height: number) => void): void
810
811Cancels listening for cursor context changes. This API uses an asynchronous callback to return the result.
812
813**System capability**: SystemCapability.MiscServices.InputMethodFramework
814
815  **Parameters**
816
817| Name   | Type | Mandatory | Description  |
818| -------- | ---- | ---- | ------ |
819| type     | string  | Yes  | Listening type.<br>The value **'cursorContextChange'** indicates the cursor change event.|
820| callback | (x: number, y:number, height:number) => void | No  | Callback used to return the cursor information.<br>- **x**: x coordinate of the top of the cursor.<br>- **y**: x coordinate of the bottom of the cursor.<br>- **height**: height of the cursor.<br>|
821
822
823  **Example**
824
825```js
826inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x, y, height) => {
827  console.log('delete cursorContextChange notification.');
828});
829```
830### on('selectionChange')
831
832on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
833
834Enables listening for the text selection change event. This API uses an asynchronous callback to return the result.
835
836**System capability**: SystemCapability.MiscServices.InputMethodFramework
837
838**Parameters**
839
840| Name   | Type  | Mandatory| Description  |
841| -------- | ----- | ---- | ---- |
842| type     | string  | Yes  | Listening type.<br>The value **'selectionChange'** indicates the text selection change event.|
843| 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.|
844
845**Example**
846
847```js
848inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
849  console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin);
850  console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd);
851  console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin);
852  console.log('inputMethodEngine beforeEach selectionChange newEnd:' + newEnd);
853});
854```
855
856### off('selectionChange')
857
858off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
859
860Cancels listening for text selection changes. This API uses an asynchronous callback to return the result.
861
862**System capability**: SystemCapability.MiscServices.InputMethodFramework
863
864**Parameters**
865
866| Name  | Type | Mandatory| Description    |
867| -------- | ------- | ---- | ------- |
868| type     | string  | Yes  | Listening type.<br>The value **'selectionChange'** indicates the text selection change event.|
869| callback | (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void | No  | 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.<br>|
870
871**Example**
872
873```js
874inputMethodEngine.getKeyboardDelegate().off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
875  console.log('delete selectionChange notification.');
876});
877```
878
879
880### on('textChange')
881
882on(type: 'textChange', callback: (text: string) => void): void
883
884Enables listening for the text change event. This API uses an asynchronous callback to return the result.
885
886**System capability**: SystemCapability.MiscServices.InputMethodFramework
887
888**Parameters**
889
890| Name  | Type  | Mandatory| Description                                                        |
891| -------- | ------ | ---- | ------------------------------------------------------------ |
892| type     | string | Yes  | Listening type.<br>The value **'textChange'** indicates the text change event.|
893| callback | (text: string) => void | Yes  | Callback used to return the text content.|
894
895**Example**
896
897```js
898inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => {
899  console.log('inputMethodEngine textChange. text:' + text);
900});
901```
902
903### off('textChange')
904
905off(type: 'textChange', callback?: (text: string) => void): void
906
907Cancels listening for text changes. This API uses an asynchronous callback to return the result.
908
909**System capability**: SystemCapability.MiscServices.InputMethodFramework
910
911**Parameters**
912
913| Name  | Type  | Mandatory| Description                                                        |
914| -------- | ------ | ---- | ------------------------------------------------------------ |
915| type     | string | Yes  | Listening type.<br>The value **'textChange'** indicates the text change event.|
916| callback | (text: string) => void | No  | Callback used to return the text content.|
917
918**Example**
919
920```js
921inputMethodEngine.getKeyboardDelegate().off('textChange', (text) => {
922  console.log('delete textChange notification. text:' + text);
923});
924```
925
926### on('editorAttributeChanged')<sup>10+</sup>
927
928on(type: 'editorAttributeChanged', callback: (attr: EditorAttribute) => void): void
929
930Enables listening for the edit box attribute change event. This API uses an asynchronous callback to return the result.
931
932**System capability**: SystemCapability.MiscServices.InputMethodFramework
933
934**Parameters**
935
936| Name  | Type  | Mandatory| Description                                                        |
937| -------- | ------ | ---- | ------------------------------------------------------------ |
938| type     | string | Yes  | Listening type.<br>The value **'editorAttributeChanged'** indicates the edit box attribute change event.|
939| callback | (attr: EditorAttribute) => void | Yes  | Callback used to return the edit box attribute change.|
940
941**Example**
942
943```js
944inputMethodEngine.getKeyboardDelegate().on('editorAttributeChanged', (attr) => {
945  console.log(`Succeeded in receiving attribute of editor, inputPattern = ${attr.inputPattern}, enterKeyType = ${attr.enterKeyType}`);
946});
947```
948
949### off('editorAttributeChanged')<sup>10+</sup>
950
951off(type: 'editorAttributeChanged', callback?: (attr: EditorAttribute) => void): void
952
953Cancels listening for the edit box attribute change event.
954
955**System capability**: SystemCapability.MiscServices.InputMethodFramework
956
957**Parameters**
958
959| Name  | Type  | Mandatory| Description                                                        |
960| -------- | ------ | ---- | ------------------------------------------------------------ |
961| type     | string | Yes  | Listening type.<br>The value **'editorAttributeChanged'** indicates the edit box attribute change event.|
962| callback | (attr: EditorAttribute) => void | No  | Callback for the edit box attribute change event. It must correspond to the one in the **on** API.|
963
964**Example**
965
966```js
967inputMethodEngine.getKeyboardDelegate().off('editorAttributeChanged');
968```
969
970## Panel<sup>10+</sup>
971
972In the following API examples, you must first use **[createPanel](#createpanel10)** to obtain a **Panel** instance, and then call the APIs using the obtained instance.
973
974### setUiContent<sup>10+</sup>
975
976setUiContent(path: string, callback: AsyncCallback\<void>): void
977
978Loads content from a page to this panel. This API uses an asynchronous callback to return the result.
979
980**System capability**: SystemCapability.MiscServices.InputMethodFramework
981
982**Parameters**
983
984| Name  | Type                  | Mandatory| Description    |
985| -------- | ---------------------- | ---- | -------- |
986| path | string | Yes  | Path of the page from which the content will be loaded.|
987| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
988
989**Example**
990
991```js
992try {
993  panel.setUiContent('pages/page2/page2', (err) => {
994    if (err) {
995      console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
996      return;
997    }
998    console.log('Succeeded in setting the content.');
999  });
1000} catch (err) {
1001  console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1002}
1003```
1004
1005### setUiContent<sup>10+</sup>
1006
1007setUiContent(path: string): Promise\<void>
1008
1009Loads content from a page to this panel. This API uses a promise to return the result.
1010
1011**System capability**: SystemCapability.MiscServices.InputMethodFramework
1012
1013**Parameters**
1014
1015| Name  | Type                  | Mandatory| Description    |
1016| -------- | ---------------------- | ---- | -------- |
1017| path | string | Yes  | Path of the page from which the content will be loaded.|
1018
1019**Return value**
1020
1021| Type  | Description                            |
1022| ------- | ------------------------------ |
1023| Promise\<void> | Promise that returns no value. |
1024
1025**Example**
1026
1027```js
1028try {
1029  let promise = panel.setUiContent('pages/page2/page2');
1030  promise.then(() => {
1031    console.log('Succeeded in setting the content.');
1032  }).catch((err) =>{
1033    console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1034  });
1035} catch (err) {
1036  console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1037}
1038```
1039
1040### setUiContent<sup>10+</sup>
1041
1042setUiContent(path: string, storage: LocalStorage, callback: AsyncCallback\<void>): void
1043
1044Loads content from a page linked to LocalStorage to this panel. This API uses an asynchronous callback to return the result.
1045
1046**System capability**: SystemCapability.MiscServices.InputMethodFramework
1047
1048**Parameters**
1049
1050| Name  | Type                  | Mandatory| Description    |
1051| -------- | ---------------------- | ---- | -------- |
1052| path | string | Yes  | Path of the page from which the content will be loaded.|
1053| storage | [LocalStorage](../arkui-ts/ts-state-management.md#localstorage9) | Yes  | Storage unit that provides storage for mutable and immutable state variables in the application.|
1054| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1055
1056**Example**
1057
1058```js
1059let storage = new LocalStorage();
1060storage.setOrCreate('storageSimpleProp',121);
1061try {
1062  panel.setUiContent('pages/page2/page2', storage, (err) => {
1063    if (err) {
1064      console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1065      return;
1066    }
1067    console.log('Succeeded in setting the content.');
1068  });
1069} catch (err) {
1070  console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1071}
1072```
1073
1074### setUiContent<sup>10+</sup>
1075
1076setUiContent(path: string, storage: LocalStorage): Promise\<void>
1077
1078Loads content from a page linked to LocalStorage to this panel. This API uses a promise to return the result.
1079
1080**System capability**: SystemCapability.MiscServices.InputMethodFramework
1081
1082**Parameters**
1083
1084| Name  | Type                  | Mandatory| Description    |
1085| -------- | ---------------------- | ---- | -------- |
1086| path | string | Yes  | Path of the page from which the content will be loaded.|
1087| storage | [LocalStorage](../arkui-ts/ts-state-management.md#localstorage9) | Yes  | Storage unit that provides storage for mutable and immutable state variables in the application.|
1088
1089**Return value**
1090
1091| Type  | Description                            |
1092| ------- | ------------------------------ |
1093| Promise\<void> | Promise that returns no value. |
1094
1095**Example**
1096
1097```js
1098let storage = new LocalStorage();
1099storage.setOrCreate('storageSimpleProp',121);
1100try {
1101  let promise = panel.setUiContent('pages/page2/page2');
1102  promise.then(() => {
1103    console.log('Succeeded in setting the content.');
1104  }).catch((err) =>{
1105    console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1106  });
1107} catch (err) {
1108  console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
1109}
1110```
1111
1112### resize<sup>10+</sup>
1113
1114resize(width: number, height: number, callback: AsyncCallback\<void>): void
1115
1116Resizes this panel. This API uses an asynchronous callback to return the result.
1117
1118The panel width cannot exceed the screen width, and the panel height cannot be higher than half of the screen height.
1119
1120**System capability**: SystemCapability.MiscServices.InputMethodFramework
1121
1122**Parameters**
1123
1124| Name  | Type                  | Mandatory| Description    |
1125| -------- | ---------------------- | ---- | -------- |
1126| width | number | Yes  | Target width of the panel, in px.|
1127| height | number | Yes  | Target height of the panel, in px.|
1128| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1129
1130**Example**
1131
1132```js
1133try {
1134  panel.resize(500, 1000, (err) => {
1135    if (err) {
1136      console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
1137      return;
1138    }
1139    console.log('Succeeded in changing the panel size.');
1140  });
1141} catch (err) {
1142  console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
1143}
1144```
1145
1146### resize<sup>10+</sup>
1147
1148resize(width: number, height: number): Promise\<void>;
1149
1150Resizes this panel. This API uses a promise to return the result.
1151
1152The panel width cannot exceed the screen width, and the panel height cannot be higher than half of the screen height.
1153
1154**System capability**: SystemCapability.MiscServices.InputMethodFramework
1155
1156**Parameters**
1157
1158| Name  | Type                  | Mandatory| Description    |
1159| -------- | ---------------------- | ---- | -------- |
1160| width | number | Yes  | Target width of the panel, in px.|
1161| height | number | Yes  | Target height of the panel, in px.|
1162
1163**Return value**
1164
1165| Type  | Description                            |
1166| ------- | ------------------------------ |
1167| Promise\<void> | Promise that returns no value. |
1168
1169**Example**
1170
1171```js
1172try {
1173  let promise = panel.resize(500, 1000);
1174  promise.then(() => {
1175    console.log('Succeeded in changing the panel size.');
1176  }).catch((err) =>{
1177    console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
1178  });
1179} catch (err) {
1180  console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
1181}
1182```
1183
1184### moveTo<sup>10+</sup>
1185
1186moveTo(x: number, y: number, callback: AsyncCallback\<void>): void
1187
1188Moves this panel to the specified position. This API uses an asynchronous callback to return the result.
1189
1190This API does not work on panels in the FLG_FIXED state.
1191
1192**System capability**: SystemCapability.MiscServices.InputMethodFramework
1193
1194**Parameters**
1195
1196| Name  | Type                  | Mandatory| Description    |
1197| -------- | ---------------------- | ---- | -------- |
1198| x | number | Yes  | Distance to move along the x-axis, in px. A positive value indicates moving rightwards.|
1199| y | number | Yes  | Distance to move along the y-axis, in px. A positive value indicates moving downwards.|
1200| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1201
1202**Example**
1203
1204```js
1205try {
1206  panel.moveTo(300, 300, (err) =>{
1207    if (err) {
1208      console.error(`Failed to move panel: ${JSON.stringify(err)}`);
1209      return;
1210    }
1211    console.log('Succeeded in moving the panel.');
1212  });
1213} catch (err) {
1214    console.error(`Failed to move panel: ${JSON.stringify(err)}`);
1215}
1216```
1217
1218### moveTo<sup>10+</sup>
1219
1220moveTo(x: number, y: number): Promise\<void>
1221
1222Moves this panel to the specified position. This API uses a promise to return the result.
1223
1224This API does not work on panels in the FLG_FIXED state.
1225
1226**System capability**: SystemCapability.MiscServices.InputMethodFramework
1227
1228**Parameters**
1229
1230| Name  | Type                  | Mandatory| Description    |
1231| -------- | ---------------------- | ---- | -------- |
1232| x | number | Yes  | Distance to move along the x-axis, in px. A positive value indicates moving rightwards.|
1233| y | number | Yes  | Distance to move along the y-axis, in px. A positive value indicates moving downwards.|
1234
1235**Return value**
1236
1237| Type  | Description                            |
1238| ------- | ------------------------------ |
1239| Promise\<void> | Promise that returns no value. |
1240
1241**Example**
1242
1243```js
1244try {
1245  let promise = panel.moveTo(300, 300);
1246  promise.then(() => {
1247    console.log('Succeeded in moving the panel.');
1248  }).catch((err) =>{
1249    console.error(`Failed to move panel: ${JSON.stringify(err)}`);
1250  });
1251} catch (err) {
1252  console.error(`Failed to move panel: ${JSON.stringify(err)}`);
1253}
1254```
1255
1256### show<sup>10+</sup>
1257
1258show(callback: AsyncCallback\<void>): void
1259
1260Shows this panel. This API uses an asynchronous callback to return the result.
1261
1262**System capability**: SystemCapability.MiscServices.InputMethodFramework
1263
1264**Parameters**
1265
1266| Name  | Type                  | Mandatory| Description    |
1267| -------- | ---------------------- | ---- | -------- |
1268| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1269
1270**Example**
1271
1272```js
1273panel.show((err) => {
1274  if (err) {
1275    console.error(`Failed to show panel: ${JSON.stringify(err)}`);
1276    return;
1277  }
1278  console.log('Succeeded in showing the panel.');
1279});
1280```
1281
1282### show<sup>10+</sup>
1283
1284show(): Promise\<void>
1285
1286Shows this panel. This API uses a promise to return the result.
1287
1288**System capability**: SystemCapability.MiscServices.InputMethodFramework
1289
1290**Return value**
1291
1292| Type  | Description                            |
1293| ------- | ------------------------------ |
1294| Promise\<void> | Promise that returns no value. |
1295
1296**Example**
1297
1298```js
1299let promise = panel.show();
1300promise.then(() => {
1301  console.log('Succeeded in showing the panel.');
1302}).catch((err) =>{
1303  console.error(`Failed to show panel: ${JSON.stringify(err)}`);
1304});
1305```
1306
1307### hide<sup>10+</sup>
1308
1309hide(callback: AsyncCallback\<void>): void
1310
1311Hides this panel. This API uses an asynchronous callback to return the result.
1312
1313**System capability**: SystemCapability.MiscServices.InputMethodFramework
1314
1315**Parameters**
1316
1317| Name  | Type                  | Mandatory| Description    |
1318| -------- | ---------------------- | ---- | -------- |
1319| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
1320
1321**Example**
1322
1323```js
1324panel.hide((err) => {
1325  if (err) {
1326    console.error(`Failed to hide panel: ${JSON.stringify(err)}`);
1327    return;
1328  }
1329  console.log('Succeeded in hiding the panel.');
1330});
1331```
1332
1333### hide<sup>10+</sup>
1334
1335hide(): Promise\<void>
1336
1337Hides this panel. This API uses a promise to return the result.
1338
1339**System capability**: SystemCapability.MiscServices.InputMethodFramework
1340
1341**Return value**
1342
1343| Type  | Description                            |
1344| ------- | ------------------------------ |
1345| Promise\<void> | Promise that returns no value. |
1346
1347**Example**
1348
1349```js
1350let promise = panel.hide();
1351promise.then(() => {
1352  console.log('Succeeded in hiding the panel.');
1353}).catch((err) =>{
1354  console.error(`Failed to hide panel: ${JSON.stringify(err)}`);
1355});
1356```
1357
1358### on('show')<sup>10+</sup>
1359
1360on(type: 'show', callback: () => void): void
1361
1362Enables listening for the show event of this panel. This API uses an asynchronous callback to return the result.
1363
1364**System capability**: SystemCapability.MiscServices.InputMethodFramework
1365
1366**Parameters**
1367
1368| Name  | Type                  | Mandatory| Description    |
1369| -------- | ---------------------- | ---- | -------- |
1370| type | string | Yes| Listening type.<br>The value **'show'** indicates the show event.|
1371| callback | () => void | Yes  | Callback used to return the result.|
1372
1373**Example**
1374
1375```js
1376panel.on('show', () => {
1377  console.log('Panel is showing.');
1378});
1379```
1380
1381### on('hide')<sup>10+</sup>
1382
1383on(type: 'hide', callback: () => void): void
1384
1385Enables listening for the hide event of this panel. This API uses an asynchronous callback to return the result.
1386
1387**System capability**: SystemCapability.MiscServices.InputMethodFramework
1388
1389**Parameters**
1390
1391| Name  | Type                  | Mandatory| Description    |
1392| -------- | ---------------------- | ---- | -------- |
1393| type | string | Yes| Listening type.<br>The value **'hide'** indicates the hide event.|
1394| callback | () => void | Yes  | Callback used to return the result.|
1395
1396**Example**
1397
1398```js
1399panel.on('hide', () => {
1400  console.log('Panel is hiding.');
1401});
1402```
1403
1404### off('show')<sup>10+</sup>
1405
1406off(type: 'show', callback?: () => void): void
1407
1408Disables listening for the show event of this panel. This API uses an asynchronous callback to return the result.
1409
1410**System capability**: SystemCapability.MiscServices.InputMethodFramework
1411
1412**Parameters**
1413
1414| Name  | Type                  | Mandatory| Description    |
1415| -------- | ---------------------- | ---- | -------- |
1416| type | string | Yes| Listening type.<br>The value **'show'** indicates the show event.|
1417| callback | () => void | No  | Callback used to return the result.|
1418
1419**Example**
1420
1421```js
1422panel.off('show');
1423```
1424
1425### off('hide')<sup>10+</sup>
1426
1427off(type: 'hide', callback?: () => void): void
1428
1429Disables listening for the hide event of this panel. This API uses an asynchronous callback to return the result.
1430
1431**System capability**: SystemCapability.MiscServices.InputMethodFramework
1432
1433**Parameters**
1434
1435| Name  | Type                  | Mandatory| Description    |
1436| -------- | ---------------------- | ---- | -------- |
1437| type | string | Yes| Listening type.<br>The value **'hide'** indicates the hide event.|
1438| callback | () => void | No  | Callback used to return the result.|
1439
1440**Example**
1441
1442```js
1443panel.off('hide');
1444```
1445
1446### changeFlag<sup>10+</sup>
1447
1448changeFlag(flag: PanelFlag): void
1449
1450Changes the panel state type. This API only works for SOFT_KEYBOARD panels.
1451
1452**System capability**: SystemCapability.MiscServices.InputMethodFramework
1453
1454**Parameters**
1455
1456| Name  | Type                  | Mandatory| Description    |
1457| -------- | ---------------------- | ---- | -------- |
1458| flag | [PanelFlag](#panelflag10) | Yes| State type of the panel to switch to.|
1459
1460**Example**
1461
1462```js
1463let panelFlag = inputMethodEngine.PanelFlag.FLG_FIXED;
1464panel.changeFlag(panelFlag);
1465```
1466
1467## KeyboardController
1468
1469In 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.
1470
1471### hide<sup>9+</sup>
1472
1473hide(callback: AsyncCallback&lt;void&gt;): void
1474
1475Hides the keyboard. This API uses an asynchronous callback to return the result.
1476
1477**System capability**: SystemCapability.MiscServices.InputMethodFramework
1478
1479**Parameters**
1480
1481| Name  | Type                  | Mandatory| Description    |
1482| -------- | ---------------------- | ---- | -------- |
1483| 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.|
1484
1485**Error codes**
1486
1487For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1488
1489| Error Code ID| Error Message                |
1490| -------- | -------------------------- |
1491| 12800003 | input method client error. |
1492
1493**Example**
1494
1495```js
1496keyboardController.hide((err) => {
1497  if (err) {
1498    console.error(`Failed to hide: ${JSON.stringify(err)}`);
1499    return;
1500  }
1501  console.log('Succeeded in hiding keyboard.');
1502});
1503```
1504
1505### hide<sup>9+</sup>
1506
1507hide(): Promise&lt;void&gt;
1508
1509Hides the keyboard. This API uses a promise to return the result.
1510
1511**System capability**: SystemCapability.MiscServices.InputMethodFramework
1512
1513**Return value**
1514
1515| Type            | Description                     |
1516| ---------------- | ------------------------- |
1517| Promise&lt;void> | Promise that returns no value.|
1518
1519**Error codes**
1520
1521For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1522
1523| Error Code ID| Error Message                |
1524| -------- | -------------------------- |
1525| 12800003 | input method client error. |
1526
1527**Example**
1528
1529```js
1530keyboardController.hide().then(() => {
1531  console.log('Succeeded in hiding keyboard.');
1532}).catch((err) => {
1533  console.log(`Failed to hide: ${JSON.stringify(err)}`);
1534});
1535```
1536
1537### hideKeyboard<sup>(deprecated)</sup>
1538
1539hideKeyboard(callback: AsyncCallback&lt;void&gt;): void
1540
1541Hides the keyboard. This API uses an asynchronous callback to return the result.
1542
1543> **NOTE**
1544>
1545> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9) instead.
1546
1547**System capability**: SystemCapability.MiscServices.InputMethodFramework
1548
1549**Parameters**
1550
1551| Name  | Type                  | Mandatory| Description    |
1552| -------- | ---------------------- | ---- | -------- |
1553| 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.|
1554
1555**Example**
1556
1557```js
1558keyboardController.hideKeyboard((err) => {
1559  if (err) {
1560    console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`);
1561    return;
1562  }
1563  console.log('Succeeded in hiding keyboard.');
1564});
1565```
1566
1567### hideKeyboard<sup>(deprecated)</sup>
1568
1569hideKeyboard(): Promise&lt;void&gt;
1570
1571Hides the keyboard. This API uses a promise to return the result.
1572
1573> **NOTE**
1574>
1575> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9-1) instead.
1576
1577**System capability**: SystemCapability.MiscServices.InputMethodFramework
1578
1579**Return value**
1580
1581| Type            | Description                     |
1582| ---------------- | ------------------------- |
1583| Promise&lt;void> | Promise that returns no value.|
1584
1585**Example**
1586
1587```js
1588keyboardController.hideKeyboard().then(() => {
1589  console.log('Succeeded in hiding keyboard.');
1590}).catch((err) => {
1591  console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`);
1592});
1593```
1594
1595## ExtendAction<sup>10+</sup>
1596
1597Describes the type of the extended edit action on the text box.
1598
1599**System capability**: SystemCapability.MiscServices.InputMethodFramework
1600
1601| Name| Value|Description|
1602| -------- | -------- |-------- |
1603| SELECT_ALL  | 0 |Select all.|
1604| CUT  | 3 |Cut.|
1605| COPY  | 4 |Copy.|
1606| PASTE  | 5 |Paste.|
1607
1608## Direction<sup>10+</sup>
1609
1610Enumerates the directions of cursor movement of the input method.
1611
1612**System capability**: SystemCapability.MiscServices.InputMethodFramework
1613
1614| Name| Value|Description|
1615| -------- | -------- |-------- |
1616| CURSOR_UP  | 1 |Upward.|
1617| CURSOR_DOWN  | 2 |Downward.|
1618| CURSOR_LEFT  | 3 |Leftward.|
1619| CURSOR_RIGHT  | 4 |Rightward.|
1620
1621## Range<sup>10+</sup>
1622
1623Describes the range of the selected text.
1624
1625**System capability**: SystemCapability.MiscServices.InputMethodFramework
1626
1627| Name| Type| Readable| Writable| Description|
1628| -------- | -------- | -------- | -------- | -------- |
1629| start  | number | Yes| Yes| Index of the first selected character in the text box.|
1630| end  | number | Yes| Yes| Index of the last selected character in the text box.|
1631
1632## Movement<sup>10+</sup>
1633
1634Describes the direction in which the cursor moves when the text is selected.
1635
1636**System capability**: SystemCapability.MiscServices.InputMethodFramework
1637
1638| Name| Type| Readable| Writable| Description|
1639| -------- | -------- | -------- | -------- | -------- |
1640| direction  | [Direction](#direction10) | Yes| Yes| Direction in which the cursor moves when the text is selected.|
1641
1642## InputClient<sup>9+</sup>
1643
1644In 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.
1645
1646### sendKeyFunction<sup>9+</sup>
1647
1648sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
1649
1650Sends the function key. This API uses an asynchronous callback to return the result.
1651
1652**System capability**: SystemCapability.MiscServices.InputMethodFramework
1653
1654  **Parameters**
1655
1656| Name| Type| Mandatory| Description|
1657| -------- | -------- | -------- | -------- |
1658| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).|
1659| 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.|
1660
1661**Error codes**
1662
1663For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1664
1665| Error Code ID| Error Message                |
1666| -------- | -------------------------- |
1667| 12800003 | input method client error. |
1668
1669 **Example**
1670
1671```js
1672let action = 1;
1673try {
1674  inputClient.sendKeyFunction(action, (err, result) => {
1675    if (err) {
1676      console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
1677      return;
1678    }
1679    if (result) {
1680      console.log('Succeeded in sending key function.');
1681    } else {
1682      console.error('Failed to sendKeyFunction.');
1683    }
1684  });
1685} catch (err) {
1686  console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
1687}
1688```
1689
1690### sendKeyFunction<sup>9+</sup>
1691
1692sendKeyFunction(action: number): Promise&lt;boolean&gt;
1693
1694Sends the function key. This API uses a promise to return the result.
1695
1696**System capability**: SystemCapability.MiscServices.InputMethodFramework
1697
1698**Parameters**
1699
1700| Name| Type| Mandatory| Description|
1701| -------- | -------- | -------- | -------- |
1702| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).|
1703
1704**Return value**
1705
1706| Type                           | Description                                                        |
1707| ------------------------------- | ------------------------------------------------------------ |
1708| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.|
1709
1710**Error codes**
1711
1712For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1713
1714| Error Code ID| Error Message                |
1715| -------- | -------------------------- |
1716| 12800003 | input method client error. |
1717
1718**Example**
1719
1720```js
1721let action = 1;
1722try {
1723  inputClient.sendKeyFunction(action).then((result) => {
1724    if (result) {
1725      console.log('Succeeded in sending key function.');
1726    } else {
1727      console.error('Failed to sendKeyFunction.');
1728    }
1729  }).catch((err) => {
1730    console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
1731  });
1732} catch (err) {
1733  console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
1734}
1735```
1736
1737### getForward<sup>9+</sup>
1738
1739getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
1740
1741Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result.
1742
1743**System capability**: SystemCapability.MiscServices.InputMethodFramework
1744
1745**Parameters**
1746
1747| Name| Type| Mandatory| Description|
1748| -------- | -------- | -------- | -------- |
1749| length | number | Yes| Text length.|
1750| 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.|
1751
1752**Error codes**
1753
1754For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1755
1756| Error Code ID| Error Message                    |
1757| -------- | ------------------------------ |
1758| 12800003 | input method client error.     |
1759| 12800006 | Input method controller error. |
1760
1761**Example**
1762
1763```js
1764let length = 1;
1765try {
1766  inputClient.getForward(length, (err, text) => {
1767    if (err) {
1768      console.error(`Failed to getForward: ${JSON.stringify(err)}`);
1769      return;
1770    }
1771    console.log('Succeeded in getting forward, text: ' + text);
1772  });
1773} catch (err) {
1774  console.error(`Failed to getForward: ${JSON.stringify(err)}`);
1775}
1776```
1777
1778### getForward<sup>9+</sup>
1779
1780getForward(length:number): Promise&lt;string&gt;
1781
1782Obtains the specific-length text before the cursor. This API uses a promise to return the result.
1783
1784**System capability**: SystemCapability.MiscServices.InputMethodFramework
1785
1786**Parameters**
1787
1788| Name| Type| Mandatory| Description|
1789| -------- | -------- | -------- | -------- |
1790| length | number | Yes| Text length.|
1791
1792**Return value**
1793
1794| Type                           | Description                                                        |
1795| ------------------------------- | ------------------------------------------------------------ |
1796| Promise&lt;string&gt;           |  Promise used to return the specific-length text before the cursor.                    |
1797
1798**Error codes**
1799
1800For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1801
1802| Error Code ID| Error Message                    |
1803| -------- | ------------------------------ |
1804| 12800003 | input method client error.     |
1805| 12800006 | Input method controller error. |
1806
1807**Example**
1808
1809```js
1810let length = 1;
1811try {
1812  inputClient.getForward(length).then((text) => {
1813    console.log('Succeeded in getting forward, text: ' + text);
1814  }).catch((err) => {
1815    console.error(`Failed to getForward: ${JSON.stringify(err)}`);
1816  });
1817} catch (err) {
1818  console.error(`Failed to getForward: ${JSON.stringify(err)}`);
1819}
1820```
1821
1822### getBackward<sup>9+</sup>
1823
1824getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
1825
1826Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result.
1827
1828**System capability**: SystemCapability.MiscServices.InputMethodFramework
1829
1830**Parameters**
1831
1832| Name| Type| Mandatory| Description|
1833| -------- | -------- | -------- | -------- |
1834| length | number | Yes| Text length.|
1835| 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.|
1836
1837**Error codes**
1838
1839For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1840
1841| Error Code ID| Error Message                    |
1842| -------- | ------------------------------ |
1843| 12800003 | input method client error.     |
1844| 12800006 | Input method controller error. |
1845
1846**Example**
1847
1848```js
1849let length = 1;
1850try {
1851  inputClient.getBackward(length, (err, text) => {
1852    if (err) {
1853      console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
1854      return;
1855    }
1856    console.log('Succeeded in getting backward, text: ' + text);
1857  });
1858} catch (err) {
1859  console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
1860}
1861```
1862
1863### getBackward<sup>9+</sup>
1864
1865getBackward(length:number): Promise&lt;string&gt;
1866
1867Obtains the specific-length text after the cursor. This API uses a promise to return the result.
1868
1869**System capability**: SystemCapability.MiscServices.InputMethodFramework
1870
1871**Parameters**
1872
1873| Name| Type| Mandatory| Description|
1874| -------- | -------- | -------- | -------- |
1875| length | number | Yes| Text length.|
1876
1877**Return value**
1878
1879| Type                           | Description                                                        |
1880| ------------------------------- | ------------------------------------------------------------ |
1881| Promise&lt;string&gt;           |  Promise used to return the specific-length text after the cursor.                    |
1882
1883**Error codes**
1884
1885For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1886
1887| Error Code ID| Error Message                    |
1888| -------- | ------------------------------ |
1889| 12800003 | input method client error.     |
1890| 12800006 | Input method controller error. |
1891
1892**Example**
1893
1894```js
1895let length = 1;
1896try {
1897  inputClient.getBackward(length).then((text) => {
1898    console.log('Succeeded in getting backward, text: ' + text);
1899  }).catch((err) => {
1900    console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
1901  });
1902} catch (err) {
1903  console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
1904}
1905```
1906
1907### deleteForward<sup>9+</sup>
1908
1909deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
1910
1911Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result.
1912
1913**System capability**: SystemCapability.MiscServices.InputMethodFramework
1914
1915**Parameters**
1916
1917| Name| Type| Mandatory| Description|
1918| -------- | -------- | -------- | -------- |
1919| length | number | Yes| Text length.|
1920| 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.|
1921
1922**Error codes**
1923
1924For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1925
1926| Error Code ID| Error Message                |
1927| -------- | -------------------------- |
1928| 12800002 | Input method engine error. |
1929| 12800003 | input method client error. |
1930
1931**Example**
1932
1933```js
1934let length = 1;
1935try {
1936  inputClient.deleteForward(length, (err, result) => {
1937    if (err) {
1938      console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
1939      return;
1940    }
1941    if (result) {
1942      console.log('Succeeded in deleting forward.');
1943    } else {
1944      console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
1945    }
1946  });
1947} catch (err) {
1948  console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
1949}
1950```
1951
1952### deleteForward<sup>9+</sup>
1953
1954deleteForward(length:number): Promise&lt;boolean&gt;
1955
1956Deletes the fixed-length text before the cursor. This API uses a promise to return the result.
1957
1958**System capability**: SystemCapability.MiscServices.InputMethodFramework
1959
1960**Parameters**
1961
1962| Name| Type  | Mandatory| Description      |
1963| ------ | ------ | ---- | ---------- |
1964| length | number | Yes  | Text length.|
1965
1966**Return value**
1967
1968| Type                  | Description          |
1969| ---------------------- | -------------- |
1970| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.|
1971
1972**Error codes**
1973
1974For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1975
1976| Error Code ID| Error Message                |
1977| -------- | -------------------------- |
1978| 12800002 | Input method engine error. |
1979| 12800003 | input method client error. |
1980
1981**Example**
1982
1983```js
1984let length = 1;
1985try {
1986  inputClient.deleteForward(length).then((result) => {
1987    if (result) {
1988      console.log('Succeeded in deleting forward.');
1989    } else {
1990      console.error('Failed to delete Forward.');
1991    }
1992  }).catch((err) => {
1993    console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
1994  });
1995} catch (err) {
1996  console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
1997}
1998```
1999
2000### deleteBackward<sup>9+</sup>
2001
2002deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
2003
2004Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result.
2005
2006**System capability**: SystemCapability.MiscServices.InputMethodFramework
2007
2008**Parameters**
2009
2010| Name  | Type                        | Mandatory| Description          |
2011| -------- | ---------------------------- | ---- | -------------- |
2012| length   | number                       | Yes  | Text length.    |
2013| 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.|
2014
2015**Error codes**
2016
2017For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2018
2019| Error Code ID| Error Message                |
2020| -------- | -------------------------- |
2021| 12800002 | Input method engine error. |
2022| 12800003 | input method client error. |
2023
2024**Example**
2025
2026```js
2027let length = 1;
2028try {
2029  inputClient.deleteBackward(length, (err, result) => {
2030    if (err) {
2031      console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
2032      return;
2033    }
2034    if (result) {
2035      console.log('Succeeded in deleting backward.');
2036    } else {
2037      console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
2038    }
2039  });
2040} catch (err) {
2041  console.error('deleteBackward err: ' + JSON.stringify(err));
2042}
2043```
2044
2045### deleteBackward<sup>9+</sup>
2046
2047deleteBackward(length:number): Promise&lt;boolean&gt;
2048
2049Deletes the fixed-length text after the cursor. This API uses a promise to return the result.
2050
2051**System capability**: SystemCapability.MiscServices.InputMethodFramework
2052
2053**Parameters**
2054
2055| Name| Type| Mandatory| Description|
2056| -------- | -------- | -------- | -------- |
2057| length | number | Yes| Text length.|
2058
2059**Return value**
2060
2061| Type                           | Description                                                        |
2062| ------------------------------- | ------------------------------------------------------------ |
2063| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.|
2064
2065**Error codes**
2066
2067For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2068
2069| Error Code ID| Error Message                |
2070| -------- | -------------------------- |
2071| 12800002 | Input method engine error. |
2072| 12800003 | input method client error. |
2073
2074**Example**
2075
2076```js
2077let length = 1;
2078inputClient.deleteBackward(length).then((result) => {
2079  if (result) {
2080    console.log('Succeeded in deleting backward.');
2081  } else {
2082    console.error('Failed to deleteBackward.');
2083  }
2084}).catch((err) => {
2085  console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
2086});
2087```
2088
2089### insertText<sup>9+</sup>
2090
2091insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
2092
2093Inserts text. This API uses an asynchronous callback to return the result.
2094
2095**System capability**: SystemCapability.MiscServices.InputMethodFramework
2096
2097**Parameters**
2098
2099| Name| Type| Mandatory| Description|
2100| -------- | -------- | -------- | -------- |
2101| text | string | Yes| Text to insert.|
2102| 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.|
2103
2104**Error codes**
2105
2106For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2107
2108| Error Code ID| Error Message                |
2109| -------- | -------------------------- |
2110| 12800002 | Input method engine error. |
2111| 12800003 | input method client error. |
2112
2113**Example**
2114
2115```js
2116inputClient.insertText('test', (err, result) => {
2117  if (err) {
2118    console.error(`Failed to insertText: ${JSON.stringify(err)}`);
2119    return;
2120  }
2121  if (result) {
2122    console.log('Succeeded in inserting text.');
2123  } else {
2124    console.error('Failed to insertText.');
2125  }
2126});
2127```
2128
2129### insertText<sup>9+</sup>
2130
2131insertText(text:string): Promise&lt;boolean&gt;
2132
2133Inserts text. This API uses a promise to return the result.
2134
2135**System capability**: SystemCapability.MiscServices.InputMethodFramework
2136
2137**Parameters**
2138
2139| Name| Type| Mandatory| Description|
2140| -------- | -------- | -------- | -------- |
2141| text | string | Yes| Text to insert.|
2142
2143**Return value**
2144
2145| Type                           | Description                                                        |
2146| ------------------------------- | ------------------------------------------------------------ |
2147| Promise&lt;boolean&gt;  |  Promise used to return the result. The value **true** means that the insertion is successful, and **false** means the opposite. |
2148
2149**Error codes**
2150
2151For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2152
2153| Error Code ID| Error Message                |
2154| -------- | -------------------------- |
2155| 12800002 | Input method engine error. |
2156| 12800003 | input method client error. |
2157
2158**Example**
2159
2160```js
2161try {
2162  inputClient.insertText('test').then((result) => {
2163    if (result) {
2164      console.log('Succeeded in inserting text.');
2165    } else {
2166      console.error('Failed to insertText.');
2167    }
2168  }).catch((err) => {
2169    console.error(`Failed to insertText: ${JSON.stringify(err)}`);
2170  });
2171} catch (err) {
2172  console.error(`Failed to insertText: ${JSON.stringify(err)}`);
2173}
2174```
2175
2176### getEditorAttribute<sup>9+</sup>
2177
2178getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
2179
2180Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result.
2181
2182**System capability**: SystemCapability.MiscServices.InputMethodFramework
2183
2184**Parameters**
2185
2186| Name                        | Type                         | Mandatory                           | Description                                                        |
2187| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
2188| 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.|
2189
2190**Error codes**
2191
2192For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2193
2194| Error Code ID| Error Message                |
2195| -------- | -------------------------- |
2196| 12800003 | input method client error. |
2197
2198**Example**
2199
2200```js
2201inputClient.getEditorAttribute((err, editorAttribute) => {
2202  if (err) {
2203    console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
2204    return;
2205  }
2206  console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
2207  console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
2208});
2209```
2210
2211### getEditorAttribute<sup>9+</sup>
2212
2213getEditorAttribute(): Promise&lt;EditorAttribute&gt;
2214
2215Obtains the attribute of the edit box. This API uses a promise to return the result.
2216
2217**System capability**: SystemCapability.MiscServices.InputMethodFramework
2218
2219**Return value**
2220
2221| Type                           | Description                                                        |
2222| ------------------------------- | ------------------------------------------------------------ |
2223| Promise&lt;[EditorAttribute](#editorattribute)&gt; |  Promise used to return the attribute of the edit box.          |
2224
2225**Error codes**
2226
2227For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2228
2229| Error Code ID| Error Message                |
2230| -------- | -------------------------- |
2231| 12800003 | input method client error. |
2232
2233**Example**
2234
2235```js
2236inputClient.getEditorAttribute().then((editorAttribute) => {
2237  console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
2238  console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
2239}).catch((err) => {
2240  console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
2241});
2242```
2243
2244### moveCursor<sup>9+</sup>
2245
2246moveCursor(direction: number, callback: AsyncCallback&lt;void&gt;): void
2247
2248Moves the cursor. This API uses an asynchronous callback to return the result.
2249
2250**System capability**: SystemCapability.MiscServices.InputMethodFramework
2251
2252**Parameters**
2253
2254| Name   | Type                     | Mandatory| Description          |
2255| --------- | ------------------------- | ---- | -------------- |
2256| direction | number                    | Yes  | Direction in which the cursor moves.|
2257| 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.   |
2258
2259**Error codes**
2260
2261For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2262
2263| Error Code ID| Error Message                |
2264| -------- | -------------------------- |
2265| 12800003 | input method client error. |
2266
2267**Example**
2268
2269```js
2270try {
2271  inputClient.moveCursor(inputMethodEngine.CURSOR_UP, (err) => {
2272    if (err) {
2273      console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
2274      return;
2275    }
2276    console.log('Succeeded in moving cursor.');
2277  });
2278} catch (err) {
2279  console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
2280}
2281```
2282
2283### moveCursor<sup>9+</sup>
2284
2285moveCursor(direction: number): Promise&lt;void&gt;
2286
2287Moves the cursor. This API uses a promise to return the result.
2288
2289**System capability**: SystemCapability.MiscServices.InputMethodFramework
2290
2291**Parameters**
2292
2293| Name   | Type  | Mandatory| Description          |
2294| --------- | ------ | ---- | -------------- |
2295| direction | number | Yes  | Direction in which the cursor moves.|
2296
2297**Return value**
2298
2299| Type               | Description                     |
2300| ------------------- | ------------------------- |
2301| Promise&lt;void&gt; | Promise that returns no value.|
2302
2303**Error codes**
2304
2305For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2306
2307| Error Code ID| Error Message                |
2308| -------- | -------------------------- |
2309| 12800003 | input method client error. |
2310
2311**Example**
2312
2313```js
2314try {
2315  inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => {
2316    console.log('Succeeded in moving cursor.');
2317  }).catch((err) => {
2318    console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
2319  });
2320} catch (err) {
2321  console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
2322}
2323```
2324
2325### selectByRange<sup>10+</sup>
2326
2327selectByRange(range: Range, callback: AsyncCallback&lt;void&gt;): void
2328
2329Selects text based on the specified range. This API uses an asynchronous callback to return the result.
2330
2331**System capability**: SystemCapability.MiscServices.InputMethodFramework
2332
2333**Parameters**
2334
2335| Name  | Type                                                     | Mandatory| Description                                                        |
2336| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2337| range    | [Range](#range10) | Yes  | Range of the selected text.                                            |
2338| 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.|
2339
2340**Error codes**
2341
2342For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2343
2344| Error Code ID| Error Message                  |
2345| -------- | -------------------------- |
2346| 401      | parameter error.           |
2347| 12800003 | input method client error. |
2348
2349**Example**
2350
2351```js
2352try {
2353  inputClient.selectByRange({start: 0, end: 1}, (err) => {
2354    if (err) {
2355      console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
2356      return;
2357    }
2358    console.log('Succeeded in selecting by range.');
2359  });
2360} catch (err) {
2361  console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
2362}
2363```
2364
2365### selectByRange<sup>10+</sup>
2366
2367selectByRange(range: Range): Promise&lt;void&gt;
2368
2369Selects text based on the specified range. This API uses a promise to return the result.
2370
2371**System capability**: SystemCapability.MiscServices.InputMethodFramework
2372
2373**Parameters**
2374
2375| Name| Type                                                     | Mandatory| Description            |
2376| ------ | --------------------------------------------------------- | ---- | ---------------- |
2377| range  | [Range](#range10) | Yes  | Range of the selected text.|
2378
2379**Return value**
2380
2381| Type               | Description                     |
2382| ------------------- | ------------------------- |
2383| Promise&lt;void&gt; | Promise that returns no value.|
2384
2385**Error codes**
2386
2387For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2388
2389| Error Code ID| Error Message                  |
2390| -------- | -------------------------- |
2391| 401      | parameter error.           |
2392| 12800003 | input method client error. |
2393
2394**Example**
2395
2396```js
2397try {
2398  inputClient.selectByRange({start: 0, end:1}).then(() => {
2399    console.log('Succeeded in selecting by range.');
2400  }).catch((err) => {
2401    console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
2402  });
2403} catch (err) {
2404  console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
2405}
2406```
2407
2408### selectByMovement<sup>10+</sup>
2409
2410selectByMovement(movement: Movement, callback: AsyncCallback&lt;void&gt;): void
2411
2412Selects text based on the cursor movement direction. This API uses an asynchronous callback to return the result.
2413
2414**System capability**: SystemCapability.MiscServices.InputMethodFramework
2415
2416**Parameters**
2417
2418| Name  | Type | Mandatory| Description  |
2419| -------- | ------ | ---- | ------ |
2420| movement | [Movement](#movement10)   | Yes  | Direction in which the cursor moves when the text is selected. |
2421| 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.|
2422
2423**Error codes**
2424
2425For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2426
2427| Error Code ID| Error Message                  |
2428| -------- | -------------------------- |
2429| 401      | parameter error.           |
2430| 12800003 | input method client error. |
2431
2432**Example**
2433
2434```js
2435try {
2436  inputClient.selectByMovement({direction: 1}, (err) => {
2437    if (err) {
2438      console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
2439      return;
2440    }
2441    console.log('Succeeded in selecting by movement.');
2442  });
2443} catch (err) {
2444  console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
2445}
2446```
2447
2448### selectByMovement<sup>10+</sup>
2449
2450selectByMovement(movement: Movement): Promise&lt;void&gt;
2451
2452Selects text based on the specified range. This API uses a promise to return the result.
2453
2454**System capability**: SystemCapability.MiscServices.InputMethodFramework
2455
2456**Parameters**
2457
2458| Name  | Type                                                        | Mandatory| Description                  |
2459| -------- | ------------------------------------------------------------ | ---- | ---------------------- |
2460| movement | [Movement](#movement10) | Yes  | Direction in which the cursor moves when the text is selected.|
2461
2462**Return value**
2463
2464| Type               | Description                     |
2465| ------------------- | ------------------------- |
2466| Promise&lt;void&gt; | Promise that returns no value.|
2467
2468**Error codes**
2469
2470For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2471
2472| Error Code ID| Error Message                  |
2473| -------- | -------------------------- |
2474| 401      | parameter error.           |
2475| 12800003 | input method client error. |
2476
2477**Example**
2478
2479```js
2480try {
2481  inputClient.selectByMovement({direction: 1}).then(() => {
2482    console.log('Succeeded in selecting by movement.');
2483  }).catch((err) => {
2484    console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
2485  });
2486} catch (err) {
2487  console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
2488}
2489```
2490
2491### getTextIndexAtCursor<sup>10+</sup>
2492
2493getTextIndexAtCursor(callback: AsyncCallback&lt;number&gt;): void
2494
2495Obtains the index of the text where the cursor is located. This API uses an asynchronous callback to return the result.
2496
2497**System capability**: SystemCapability.MiscServices.InputMethodFramework
2498
2499**Parameters**
2500
2501| Name  | Type                       | Mandatory| Description                                                        |
2502| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
2503| 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.|
2504
2505**Error codes**
2506
2507For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2508
2509| Error Code ID| Error Message                      |
2510| -------- | ------------------------------ |
2511| 12800003 | input method client error.     |
2512| 12800006 | Input method controller error. |
2513
2514**Example**
2515
2516```js
2517inputClient.getTextIndexAtCursor((err, index) => {
2518  if (err) {
2519    console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`);
2520    return;
2521  }
2522  console.log('Succeeded in getTextIndexAtCursor: ' + index);
2523});
2524```
2525
2526### getTextIndexAtCursor<sup>10+</sup>
2527
2528getTextIndexAtCursor(): Promise&lt;number&gt;
2529
2530Obtains the index of the text where the cursor is located. This API uses a promise to return the result.
2531
2532**System capability**: SystemCapability.MiscServices.InputMethodFramework
2533
2534**Return value**
2535
2536| Type                 | Description                                   |
2537| --------------------- | --------------------------------------- |
2538| Promise&lt;number&gt; | Promise used to return the result.|
2539
2540**Error codes**
2541
2542For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2543
2544| Error Code ID| Error Message                      |
2545| -------- | ------------------------------ |
2546| 12800003 | input method client error.     |
2547| 12800006 | Input method controller error. |
2548
2549**Example**
2550
2551```js
2552inputClient.getTextIndexAtCursor().then((index) => {
2553  console.log('Succeeded in getTextIndexAtCursor: ' + index);
2554}).catch((err) => {
2555  console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`);
2556});
2557```
2558
2559### sendExtendAction<sup>10+</sup>
2560
2561sendExtendAction(action: ExtendAction, callback: AsyncCallback&lt;void&gt;): void
2562
2563Sends an extended edit action. This API uses an asynchronous callback to return the result.
2564
2565The input method calls this API to send an extended edit action to an editor component (for example, a text box), which in turn listens for the corresponding event [on(handleExtendAction)](./js-apis-inputmethod.md#onhandleextendaction10) for further processing.
2566
2567**System capability**: SystemCapability.MiscServices.InputMethodFramework
2568
2569**Parameters**
2570
2571| Name  | Type                       | Mandatory| Description                                                        |
2572| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
2573| action | [ExtendAction](#extendaction10) | Yes  | Extended edit action to send.|
2574| 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.|
2575
2576**Error codes**
2577
2578For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2579
2580| Error Code ID| Error Message                      |
2581| -------- | ------------------------------ |
2582| 12800003 | input method client error.     |
2583| 12800006 | Input method controller error. |
2584
2585**Example**
2586
2587```js
2588try {
2589  inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err) => {
2590    if (err) {
2591      console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
2592      return;
2593    }
2594    console.log('Succeeded in sending extend action.');
2595  });
2596} catch(err) {
2597  console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
2598}
2599```
2600
2601### sendExtendAction<sup>10+</sup>
2602
2603sendExtendAction(action: ExtendAction): Promise&lt;void&gt;
2604
2605Sends an extended edit action. This API uses a promise to return the result.
2606
2607The input method calls this API to send an extended edit action to an editor component (for example, a text box), which in turn listens for the corresponding event [on(handleExtendAction)](./js-apis-inputmethod.md#onhandleextendaction10) for further processing.
2608
2609**System capability**: SystemCapability.MiscServices.InputMethodFramework
2610
2611**Parameters**
2612
2613| Name| Type| Mandatory| Description|
2614| -------- | -------- | -------- | -------- |
2615| action | [ExtendAction](#extendaction10) | Yes| Extended edit action to send.|
2616
2617**Return value**
2618
2619| Type                 | Description                                   |
2620| --------------------- | --------------------------------------- |
2621| Promise&lt;void&gt; | Promise that returns no value.|
2622
2623**Error codes**
2624
2625For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
2626
2627| Error Code ID| Error Message                      |
2628| -------- | ------------------------------ |
2629| 12800003 | input method client error.     |
2630| 12800006 | Input method controller error. |
2631
2632**Example**
2633
2634```js
2635try {
2636  inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => {
2637    console.log('Succeeded in sending extend action.');
2638  }).catch((err) => {
2639    console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
2640  });
2641} catch(err) {
2642  console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
2643}
2644```
2645
2646## EditorAttribute
2647
2648Attribute of the edit box.
2649
2650**System capability**: SystemCapability.MiscServices.InputMethodFramework
2651
2652| Name        | Type| Readable| Writable| Description              |
2653| ------------ | -------- | ---- | ---- | ------------------ |
2654| enterKeyType | number   | Yes  | No  | Function attribute of the edit box.|
2655| inputPattern | number   | Yes  | No  | Text attribute of the edit box.|
2656
2657## KeyEvent
2658
2659Describes the attribute of a key.
2660
2661**System capability**: SystemCapability.MiscServices.InputMethodFramework
2662
2663| Name     | Type| Readable| Writable| Description        |
2664| --------- | -------- | ---- | ---- | ------------ |
2665| keyCode   | number   | Yes  | No  | Key value. For details, see [KeyCode](js-apis-keycode.md#keycode).|
2666| keyAction | number   | Yes  | No  | Key event type.<br>- **2**: keydown event.<br>- **3**: keyup event.|
2667
2668## PanelFlag<sup>10+</sup>
2669
2670Enumerates the state types of the input method panel.
2671
2672**System capability**: SystemCapability.MiscServices.InputMethodFramework
2673
2674| Name        | Value| Description              |
2675| ------------ | -- | ------------------ |
2676| FLG_FIXED  | 0 | Fixed state type.|
2677| FLG_FLOATING | 1 | Floating state type.|
2678
2679## PanelType<sup>10+</sup>
2680
2681Enumerates the types of the input method panel.
2682
2683**System capability**: SystemCapability.MiscServices.InputMethodFramework
2684
2685| Name        | Value| Description              |
2686| ------------ | -- | ------------------ |
2687| SOFT_KEYBOARD | 0 | Soft keyboard type.|
2688| STATUS_BAR   | 1 | Status bar type.|
2689
2690## PanelInfo<sup>10+</sup>
2691
2692**System capability**: SystemCapability.MiscServices.InputMethodFramework
2693
2694Describes the attributes of the input method panel.
2695
2696| Name     | Type| Readable| Writable| Description        |
2697| --------- | -------- | ---- | ---- | ------------ |
2698| type   	| number   | Yes  | Yes  | Type of the panel.|
2699| flag	    | number   | Yes  | Yes  | State type of the panel.|
2700
2701## TextInputClient<sup>(deprecated)</sup>
2702
2703> **NOTE**
2704>
2705> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [InputClient](#inputclient9) instead.
2706
2707In 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.
2708
2709### getForward<sup>(deprecated)</sup>
2710
2711getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
2712
2713Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result.
2714
2715> **NOTE**
2716>
2717> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9) instead.
2718
2719**System capability**: SystemCapability.MiscServices.InputMethodFramework
2720
2721**Parameters**
2722
2723| Name| Type| Mandatory| Description|
2724| -------- | -------- | -------- | -------- |
2725| length | number | Yes| Text length.|
2726| 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.|
2727
2728**Example**
2729
2730```js
2731let length = 1;
2732textInputClient.getForward(length, (err, text) => {
2733  if (err) {
2734    console.error(`Failed to getForward: ${JSON.stringify(err)}`);
2735    return;
2736  }
2737  console.log('Succeeded in getting forward, text: ' + text);
2738});
2739```
2740
2741### getForward<sup>(deprecated)</sup>
2742
2743getForward(length:number): Promise&lt;string&gt;
2744
2745Obtains the specific-length text before the cursor. This API uses a promise to return the result.
2746
2747> **NOTE**
2748>
2749> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9) instead.
2750
2751**System capability**: SystemCapability.MiscServices.InputMethodFramework
2752
2753**Parameters**
2754
2755| Name| Type| Mandatory| Description|
2756| -------- | -------- | -------- | -------- |
2757| length | number | Yes| Text length.|
2758
2759**Return value**
2760
2761| Type                           | Description                                                        |
2762| ------------------------------- | ------------------------------------------------------------ |
2763| Promise&lt;string&gt; |  Promise used to return the specific-length text before the cursor.               |
2764
2765**Example**
2766
2767```js
2768let length = 1;
2769textInputClient.getForward(length).then((text) => {
2770  console.log('Succeeded in getting forward, text: ' + text);
2771}).catch((err) => {
2772  console.error(`Failed to getForward: ${JSON.stringify(err)}`);
2773});
2774```
2775
2776### getBackward<sup>(deprecated)</sup>
2777
2778getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
2779
2780Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result.
2781
2782> **NOTE**
2783>
2784> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9) instead.
2785
2786**System capability**: SystemCapability.MiscServices.InputMethodFramework
2787
2788**Parameters**
2789
2790| Name| Type| Mandatory| Description|
2791| -------- | -------- | -------- | -------- |
2792| length | number | Yes| Text length.|
2793| 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.|
2794
2795**Example**
2796
2797```js
2798let length = 1;
2799textInputClient.getBackward(length, (err, text) => {
2800  if (err) {
2801    console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
2802    return;
2803  }
2804  console.log('Succeeded in getting borward, text: ' + text);
2805});
2806```
2807
2808### getBackward<sup>(deprecated)</sup>
2809
2810getBackward(length:number): Promise&lt;string&gt;
2811
2812Obtains the specific-length text after the cursor. This API uses a promise to return the result.
2813
2814> **NOTE**
2815>
2816> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9) instead.
2817
2818**System capability**: SystemCapability.MiscServices.InputMethodFramework
2819
2820**Parameters**
2821
2822| Name| Type| Mandatory| Description|
2823| -------- | -------- | -------- | -------- |
2824| length | number | Yes| Text length.|
2825
2826**Return value**
2827
2828| Type                           | Description                                                        |
2829| ------------------------------- | ------------------------------------------------------------ |
2830| Promise&lt;string&gt; |  Promise used to return the specific-length text after the cursor.               |
2831
2832**Example**
2833
2834```js
2835let length = 1;
2836textInputClient.getBackward(length).then((text) => {
2837  console.log('Succeeded in getting backward: ' + JSON.stringify(text));
2838}).catch((err) => {
2839  console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
2840});
2841```
2842
2843### deleteForward<sup>(deprecated)</sup>
2844
2845deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
2846
2847Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result.
2848
2849> **NOTE**
2850>
2851> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9) instead.
2852
2853**System capability**: SystemCapability.MiscServices.InputMethodFramework
2854
2855**Parameters**
2856
2857| Name| Type| Mandatory| Description|
2858| -------- | -------- | -------- | -------- |
2859| length | number | Yes| Text length.|
2860| 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.|
2861
2862**Example**
2863
2864```js
2865let length = 1;
2866textInputClient.deleteForward(length, (err, result) => {
2867  if (err) {
2868    console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
2869    return;
2870  }
2871  if (result) {
2872    console.log('Succeeded in deleting forward.');
2873  } else {
2874    console.error('Failed to deleteForward.');
2875  }
2876});
2877```
2878
2879### deleteForward<sup>(deprecated)</sup>
2880
2881deleteForward(length:number): Promise&lt;boolean&gt;
2882
2883Deletes the fixed-length text before the cursor. This API uses a promise to return the result.
2884
2885> **NOTE**
2886>
2887> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9) instead.
2888
2889**System capability**: SystemCapability.MiscServices.InputMethodFramework
2890
2891**Parameters**
2892
2893| Name| Type  | Mandatory| Description      |
2894| ------ | ------ | ---- | ---------- |
2895| length | number | Yes  | Text length.|
2896
2897**Return value**
2898
2899| Type                  | Description          |
2900| ---------------------- | -------------- |
2901| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.|
2902
2903**Example**
2904
2905```js
2906let length = 1;
2907textInputClient.deleteForward(length).then((result) => {
2908  if (result) {
2909    console.log('Succeeded in deleting forward.');
2910  } else {
2911    console.error('Failed to delete forward.');
2912  }
2913}).catch((err) => {
2914  console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
2915});
2916```
2917
2918### deleteBackward<sup>(deprecated)</sup>
2919
2920deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
2921
2922Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result.
2923
2924> **NOTE**
2925>
2926> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9) instead.
2927
2928**System capability**: SystemCapability.MiscServices.InputMethodFramework
2929
2930**Parameters**
2931
2932| Name  | Type                        | Mandatory| Description          |
2933| -------- | ---------------------------- | ---- | -------------- |
2934| length   | number                       | Yes  | Text length.    |
2935| 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.|
2936
2937**Example**
2938
2939```js
2940let length = 1;
2941textInputClient.deleteBackward(length, (err, result) => {
2942  if (err) {
2943    console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
2944    return;
2945  }
2946  if (result) {
2947    console.log('Succeeded in deleting backward.');
2948  } else {
2949    console.error('Failed to deleteBackward.');
2950  }
2951});
2952```
2953
2954### deleteBackward<sup>(deprecated)</sup>
2955
2956deleteBackward(length:number): Promise&lt;boolean&gt;
2957
2958Deletes the fixed-length text after the cursor. This API uses a promise to return the result.
2959
2960> **NOTE**
2961>
2962> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9) instead.
2963
2964**System capability**: SystemCapability.MiscServices.InputMethodFramework
2965
2966**Parameters**
2967
2968| Name| Type| Mandatory| Description|
2969| -------- | -------- | -------- | -------- |
2970| length | number | Yes| Text length.|
2971
2972**Return value**
2973
2974| Type                           | Description                                                        |
2975| ------------------------------- | ------------------------------------------------------------ |
2976| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.|
2977
2978**Example**
2979
2980```js
2981let length = 1;
2982textInputClient.deleteBackward(length).then((result) => {
2983  if (result) {
2984    console.log('Succeeded in deleting backward.');
2985  } else {
2986    console.error('Failed to deleteBackward.');
2987  }
2988}).catch((err) => {
2989  console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
2990});
2991```
2992### sendKeyFunction<sup>(deprecated)</sup>
2993
2994sendKeyFunction(action: number, callback: AsyncCallback&lt;boolean&gt;): void
2995
2996Sends the function key. This API uses an asynchronous callback to return the result.
2997
2998> **NOTE**
2999>
3000> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9) instead.
3001
3002**System capability**: SystemCapability.MiscServices.InputMethodFramework
3003
3004**Parameters**
3005
3006| Name| Type| Mandatory| Description|
3007| -------- | -------- | -------- | -------- |
3008| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).|
3009| 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.|
3010
3011**Example**
3012
3013```js
3014let action = 1;
3015textInputClient.sendKeyFunction(action, (err, result) => {
3016  if (err) {
3017    console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
3018    return;
3019  }
3020  if (result) {
3021    console.log('Succeeded in sending key function.');
3022  } else {
3023    console.error('Failed to sendKeyFunction.');
3024  }
3025});
3026```
3027
3028### sendKeyFunction<sup>(deprecated)</sup>
3029
3030sendKeyFunction(action: number): Promise&lt;boolean&gt;
3031
3032Sends the function key. This API uses a promise to return the result.
3033
3034> **NOTE**
3035>
3036> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9) instead.
3037
3038**System capability**: SystemCapability.MiscServices.InputMethodFramework
3039
3040**Parameters**
3041
3042| Name| Type| Mandatory| Description|
3043| -------- | -------- | -------- | -------- |
3044| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).|
3045
3046**Return value**
3047
3048| Type                           | Description                                                        |
3049| ------------------------------- | ------------------------------------------------------------ |
3050| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the setting is successful, and **false** means the opposite.|
3051
3052**Example**
3053
3054```js
3055let action = 1;
3056textInputClient.sendKeyFunction(action).then((result) => {
3057  if (result) {
3058    console.log('Succeeded in sending key function.');
3059  } else {
3060    console.error('Failed to sendKeyFunction.');
3061  }
3062}).catch((err) => {
3063  console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
3064});
3065```
3066
3067### insertText<sup>(deprecated)</sup>
3068
3069insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
3070
3071Inserts text. This API uses an asynchronous callback to return the result.
3072
3073> **NOTE**
3074>
3075> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9) instead.
3076
3077**System capability**: SystemCapability.MiscServices.InputMethodFramework
3078
3079**Parameters**
3080
3081| Name| Type| Mandatory| Description|
3082| -------- | -------- | -------- | -------- |
3083| text | string | Yes| Text to insert.|
3084| 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.|
3085
3086**Example**
3087
3088```js
3089textInputClient.insertText('test', (err, result) => {
3090  if (err) {
3091    console.error(`Failed to insertText: ${JSON.stringify(err)}`);
3092    return;
3093  }
3094  if (result) {
3095    console.log('Succeeded in inserting text.');
3096  } else {
3097    console.error('Failed to insertText.');
3098  }
3099});
3100```
3101
3102### insertText<sup>(deprecated)</sup>
3103
3104insertText(text:string): Promise&lt;boolean&gt;
3105
3106Inserts text. This API uses a promise to return the result.
3107
3108> **NOTE**
3109>
3110> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9) instead.
3111
3112**System capability**: SystemCapability.MiscServices.InputMethodFramework
3113
3114**Parameters**
3115
3116| Name| Type| Mandatory| Description|
3117| -------- | -------- | -------- | -------- |
3118| text | string | Yes| Text to insert.|
3119
3120**Return value**
3121
3122| Type                           | Description                                                        |
3123| ------------------------------- | ------------------------------------------------------------ |
3124| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the insertion is successful, and **false** means the opposite.|
3125
3126**Example**
3127
3128```js
3129textInputClient.insertText('test').then((result) => {
3130  if (result) {
3131    console.log('Succeeded in inserting text.');
3132  } else {
3133    console.error('Failed to insertText.');
3134  }
3135}).catch((err) => {
3136  console.error(`Failed to insertText: ${JSON.stringify(err)}`);
3137});
3138```
3139
3140### getEditorAttribute<sup>(deprecated)</sup>
3141
3142getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
3143
3144Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result.
3145
3146> **NOTE**
3147>
3148> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9) instead.
3149
3150**System capability**: SystemCapability.MiscServices.InputMethodFramework
3151
3152**Parameters**
3153
3154| Name   | Type  | Mandatory | Description  |
3155| -------- | ----- | ----- | ----- |
3156| 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.|
3157
3158**Example**
3159
3160```js
3161textInputClient.getEditorAttribute((err, editorAttribute) => {
3162  if (err) {
3163    console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
3164    return;
3165  }
3166  console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
3167  console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
3168});
3169```
3170
3171### getEditorAttribute<sup>(deprecated)</sup>
3172
3173getEditorAttribute(): Promise&lt;EditorAttribute&gt;
3174
3175Obtains the attribute of the edit box. This API uses a promise to return the result.
3176
3177> **NOTE**
3178>
3179> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9) instead.
3180
3181**System capability**: SystemCapability.MiscServices.InputMethodFramework
3182
3183**Return value**
3184
3185| Type                           | Description                                                        |
3186| ------------------------------- | ------------------------------------------------------------ |
3187| Promise&lt;[EditorAttribute](#editorattribute)&gt; |  Promise used to return the attribute of the edit box.          |
3188
3189**Example**
3190
3191```js
3192textInputClient.getEditorAttribute().then((editorAttribute) => {
3193  console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
3194  console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
3195}).catch((err) => {
3196  console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
3197});
3198```
3199<!--no_check-->
3200