• 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
61The input method can use the obtained instance to subscribe to a soft keyboard display/hide request event.
62
63**System capability**: SystemCapability.MiscServices.InputMethodFramework
64
65**Return value**
66
67| Type                                     | Description              |
68| ----------------------------------------- | ------------------ |
69| [InputMethodAbility](#inputmethodability) | **InputMethodAbility** instance.|
70
71**Example**
72
73```js
74let InputMethodAbility = inputMethodEngine.getInputMethodAbility();
75```
76
77## inputMethodEngine.getKeyboardDelegate<sup>9+</sup>
78
79getKeyboardDelegate(): KeyboardDelegate
80
81Obtains 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.
82
83**System capability**: SystemCapability.MiscServices.InputMethodFramework
84
85**Return value**
86
87| Type                                 | Description                    |
88| ------------------------------------- | ------------------------ |
89| [KeyboardDelegate](#keyboarddelegate) | **KeyboardDelegate** instance.|
90
91**Example**
92
93```js
94let KeyboardDelegate = inputMethodEngine.getKeyboardDelegate();
95```
96
97## inputMethodEngine.getInputMethodEngine<sup>(deprecated)</sup>
98
99getInputMethodEngine(): InputMethodEngine
100
101Obtains 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.
102
103> **NOTE**
104>
105> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethodAbility()](#inputmethodenginegetinputmethodability9) instead.
106
107**System capability**: SystemCapability.MiscServices.InputMethodFramework
108
109**Return value**
110
111| Type                                     | Description              |
112| ----------------------------------------- | ------------------ |
113| [InputMethodEngine](#inputmethodengine) | **InputMethodAbility** instance.|
114
115**Example**
116
117```js
118let InputMethodEngine = inputMethodEngine.getInputMethodEngine();
119```
120
121## inputMethodEngine.createKeyboardDelegate<sup>(deprecated)</sup>
122
123createKeyboardDelegate(): KeyboardDelegate
124
125Obtains 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.
126
127> **NOTE**
128>
129>This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getKeyboardDelegate()](#inputmethodenginegetkeyboarddelegate9) instead.
130
131**System capability**: SystemCapability.MiscServices.InputMethodFramework
132
133**Return value**
134
135| Type                                 | Description                    |
136| ------------------------------------- | ------------------------ |
137| [KeyboardDelegate](#keyboarddelegate) | **KeyboardDelegate** instance.|
138
139**Example**
140
141```js
142let keyboardDelegate = inputMethodEngine.createKeyboardDelegate();
143```
144
145## InputMethodEngine
146
147In the following API examples, you must first use **[getInputMethodEngine](#inputmethodenginegetinputmethodenginedeprecated)** to obtain an **InputMethodEngine** instance, and then call the APIs using the obtained instance.
148
149### on('inputStart')
150
151on(type: 'inputStart', callback: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
152
153Enables listening for the input method binding event. This API uses an asynchronous callback to return the result.
154
155**System capability**: SystemCapability.MiscServices.InputMethodFramework
156
157**Parameters**
158
159| Name  | Type                           | Mandatory| Description                                                        |
160| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
161| type     | string                        | Yes  | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
162| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclientdeprecated)) => void | Yes| Callback used to return the **KeyboardController** and **TextInputClient** instances.|
163
164**Example**
165
166```js
167inputMethodEngine.getInputMethodEngine().on('inputStart', (kbController, textClient) => {
168    let keyboardController = kbController;
169    let textInputClient = textClient;
170});
171```
172
173### off('inputStart')
174
175off(type: 'inputStart', callback?: (kbController: KeyboardController, textInputClient: TextInputClient) => void): void
176
177Cancels listening for the input method binding event.
178
179**System capability**: SystemCapability.MiscServices.InputMethodFramework
180
181**Parameters**
182
183| Name  | Type                | Mandatory| Description                    |
184| -------- | -------------------- | ---- | ------------------------ |
185| type | string                                                       | Yes  | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
186| callback | (kbController: [KeyboardController](#keyboardcontroller), textInputClient: [TextInputClient](#textinputclientdeprecated)) => void | No| Callback used to return the **KeyboardController** and **TextInputClient** instances.|
187
188**Example**
189
190```js
191inputMethodEngine.getInputMethodEngine().off('inputStart', (kbController, textInputClient) => {
192    console.log('delete inputStart notification.');
193});
194```
195
196### on('keyboardShow'|'keyboardHide')
197
198on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
199
200Enables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result.
201
202**System capability**: SystemCapability.MiscServices.InputMethodFramework
203
204**Parameters**
205
206| Name  | Type  | Mandatory| Description                                                        |
207| -------- | ------ | ---- | ------------------------------------------------------------ |
208| type     | string | Yes  | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.|
209| callback | () => void   | Yes  | Callback used to return the result.                                                  |
210
211**Example**
212
213```js
214inputMethodEngine.getInputMethodEngine().on('keyboardShow', () => {
215    console.log('inputMethodEngine keyboardShow.');
216});
217inputMethodEngine.getInputMethodEngine().on('keyboardHide', () => {
218    console.log('inputMethodEngine keyboardHide.');
219});
220```
221
222### off('keyboardShow'|'keyboardHide')
223
224off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
225
226Disables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result.
227
228**System capability**: SystemCapability.MiscServices.InputMethodFramework
229
230**Parameters**
231
232| Name  | Type  | Mandatory| Description                                                        |
233| -------- | ------ | ---- | ------------------------------------------------------------ |
234| type     | string | Yes  | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.|
235| callback | () => void   | No  | Callback used to return the result.|
236
237**Example**
238
239```js
240inputMethodEngine.getInputMethodEngine().off('keyboardShow');
241inputMethodEngine.getInputMethodEngine().off('keyboardHide');
242```
243
244## InputMethodAbility
245
246In the following API examples, you must first use **[getInputMethodAbility](#inputmethodenginegetinputmethodability9)** to obtain an **InputMethodAbility** instance, and then call the APIs using the obtained instance.
247
248### on('inputStart')<sup>9+</sup>
249
250on(type: 'inputStart', callback: (kbController: KeyboardController, inputClient: InputClient) => void): void
251
252Enables listening for the input method binding event. This API uses an asynchronous callback to return the result.
253
254**System capability**: SystemCapability.MiscServices.InputMethodFramework
255
256**Parameters**
257
258| Name  | Type                           | Mandatory| Description                                                        |
259| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
260| type     | string                        | Yes  | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
261| callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | Yes| Callback used to return the result.|
262
263**Example**
264
265```js
266inputMethodEngine.getInputMethodAbility().on('inputStart', (kbController, client) => {
267    let keyboardController = kbController;
268    let inputClient = client;
269});
270```
271
272### off('inputStart')<sup>9+</sup>
273
274off(type: 'inputStart', callback?: (kbController: KeyboardController, inputClient: InputClient) => void): void
275
276Cancels listening for the input method binding event. This API uses an asynchronous callback to return the result.
277
278**System capability**: SystemCapability.MiscServices.InputMethodFramework
279
280**Parameters**
281
282| Name  | Type                | Mandatory| Description                    |
283| -------- | -------------------- | ---- | ------------------------ |
284| type | string                                                       | Yes  | Listening type.<br>The value **'inputStart'** indicates the input method binding event.|
285| callback | (kbController: [KeyboardController](#keyboardcontroller), inputClient: [InputClient](#inputclient9)) => void | No| Callback used to return the result.|
286
287**Example**
288
289```js
290inputMethodEngine.getInputMethodAbility().off('inputStart');
291```
292
293### on('inputStop')<sup>9+</sup>
294
295on(type: 'inputStop', callback: () => void): void
296
297Enables listening for the input method unbinding event. This API uses an asynchronous callback to return the result.
298
299**System capability**: SystemCapability.MiscServices.InputMethodFramework
300
301**Parameters**
302
303| Name  | Type  | Mandatory| Description                                                        |
304| -------- | ------ | ---- | ------------------------------------------------------------ |
305| type     | string | Yes  | Listening type.<br>The value **'inputStop'** indicates the input method unbinding event.|
306| callback | () => void   | Yes  | Callback used to return the result.                                                  |
307
308**Example**
309
310```js
311inputMethodEngine.getInputMethodAbility().on('inputStop', () => {
312    console.log('inputMethodAbility inputStop');
313});
314```
315
316### off('inputStop')<sup>9+</sup>
317
318off(type: 'inputStop', callback: () => void): void
319
320Cancels listening for the input method stop event. This API uses an asynchronous callback to return the result.
321
322**System capability**: SystemCapability.MiscServices.InputMethodFramework
323
324**Parameters**
325
326| Name  | Type  | Mandatory| Description                                                        |
327| -------- | ------ | ---- | ------------------------------------------------------------ |
328| type     | string | Yes  | Listening type.<br>The value **'inputStop'** indicates the input method unbinding event.|
329| callback | () => void   | Yes  | Callback used to return the result.                                                  |
330
331**Example**
332
333```js
334inputMethodEngine.getInputMethodAbility().off('inputStop', () => {
335    console.log('inputMethodAbility delete inputStop notification.');
336});
337```
338
339### on('setCallingWindow')<sup>9+</sup>
340
341on(type: 'setCallingWindow', callback: (wid: number) => void): void
342
343Enables listening for the window invocation setting event. This API uses an asynchronous callback to return the result.
344
345**System capability**: SystemCapability.MiscServices.InputMethodFramework
346
347**Parameters**
348
349| Name  | Type  | Mandatory| Description                                                        |
350| -------- | ------ | ---- | ------------------------------------------------------------ |
351| type     | string | Yes  | Listening type.<br>The value **'setCallingWindow'** indicates the window invocation setting event.|
352| callback | (wid: number) => void | Yes  | Callback used to return the window ID of the caller.                                           |
353
354**Example**
355
356```js
357inputMethodEngine.getInputMethodAbility().on('setCallingWindow', (wid) => {
358    console.log('inputMethodAbility setCallingWindow');
359});
360```
361
362### off('setCallingWindow')<sup>9+</sup>
363
364off(type: 'setCallingWindow', callback: (wid:number) => void): void
365
366Disables listening for the window invocation setting event. This API uses an asynchronous callback to return the result.
367
368**System capability**: SystemCapability.MiscServices.InputMethodFramework
369
370**Parameters**
371
372| Name  | Type  | Mandatory| Description                                                        |
373| -------- | ------ | ---- | ------------------------------------------------------------ |
374| type     | string | Yes  | Listening type.<br>The value **'setCallingWindow'** indicates the window invocation setting event.|
375| callback | (wid:number) => void | Yes  | Callback used to return the window ID of the caller.                                |
376
377**Example**
378
379```js
380inputMethodEngine.getInputMethodAbility().off('setCallingWindow', () => {
381    console.log('inputMethodAbility delete setCallingWindow notification.');
382});
383```
384
385### on('keyboardShow'|'keyboardHide')<sup>9+</sup>
386
387on(type: 'keyboardShow'|'keyboardHide', callback: () => void): void
388
389Enables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result.
390
391**System capability**: SystemCapability.MiscServices.InputMethodFramework
392
393**Parameters**
394
395| Name  | Type  | Mandatory| Description                                                        |
396| -------- | ------ | ---- | ------------------------------------------------------------ |
397| type     | string | Yes  | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.|
398| callback | () => void   | Yes  | Callback used to return the result.                                                  |
399
400**Example**
401
402```js
403inputMethodEngine.getInputMethodAbility().on('keyboardShow', () => {
404    console.log('InputMethodAbility keyboardShow.');
405});
406inputMethodEngine.getInputMethodAbility().on('keyboardHide', () => {
407    console.log('InputMethodAbility keyboardHide.');
408});
409```
410
411### off('keyboardShow'|'keyboardHide')<sup>9+</sup>
412
413off(type: 'keyboardShow'|'keyboardHide', callback?: () => void): void
414
415Disables listening for a keyboard visibility event. This API uses an asynchronous callback to return the result.
416
417**System capability**: SystemCapability.MiscServices.InputMethodFramework
418
419**Parameters**
420
421| Name  | Type  | Mandatory| Description                                                        |
422| -------- | ------ | ---- | ------------------------------------------------------------ |
423| type     | string | Yes  | Listening type.<br>- The value **'keyboardShow'** indicates the keyboard display event.<br>- The value **'keyboardHide'** indicates the keyboard hiding event.|
424| callback | () => void   | No  | Callback used to return the result.    |
425
426**Example**
427
428```js
429inputMethodEngine.getInputMethodAbility().off('keyboardShow', () => {
430    console.log('InputMethodAbility delete keyboardShow notification.');
431});
432inputMethodEngine.getInputMethodAbility().off('keyboardHide', () => {
433    console.log('InputMethodAbility delete keyboardHide notification.');
434});
435```
436
437### on('setSubtype')<sup>9+</sup>
438
439on(type: 'setSubtype', callback: (inputMethodSubtype: InputMethodSubtype) => void): void
440
441Enables listening for the input method subtype setting event. This API uses an asynchronous callback to return the result.
442
443**System capability**: SystemCapability.MiscServices.InputMethodFramework
444
445**Parameters**
446
447| Name   | Type| Mandatory | Description|
448| -------- | --- | ---- | --- |
449| type     | string | Yes  | Listening type.<br>The value **'setSubtype'** indicates the input method subtype setting event.|
450| callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | Yes  | Callback used to return the input method subtype.                          |
451
452**Example**
453
454```js
455inputMethodEngine.getInputMethodAbility().on('setSubtype', (inputMethodSubtype) => {
456    console.log('InputMethodAbility setSubtype.');
457});
458```
459
460### off('setSubtype')<sup>9+</sup>
461
462off(type: 'setSubtype', callback?: (inputMethodSubtype: InputMethodSubtype) => void): void
463
464Disables listening for the input method subtype setting event. This API uses an asynchronous callback to return the result.
465
466**System capability**: SystemCapability.MiscServices.InputMethodFramework
467
468**Parameters**
469
470| Name  | Type | Mandatory| Description  |
471| ------- | ----- | ---- | ---- |
472| type     | string | Yes  | Listening type.<br>The value **'setSubtype'** indicates the input method subtype setting event.|
473| callback | (inputMethodSubtype: [InputMethodSubtype](js-apis-inputmethod-subtype.md)) => void | No  | Callback used to return the input method subtype. |
474
475**Example**
476
477```js
478inputMethodEngine.getInputMethodAbility().off('setSubtype', () => {
479    console.log('InputMethodAbility delete setSubtype notification.');
480});
481```
482
483## KeyboardDelegate
484
485In the following API examples, you must first use **[getKeyboardDelegate](#inputmethodenginegetkeyboarddelegate9)** to obtain a **KeyboardDelegate** instance, and then call the APIs using the obtained instance.
486
487### on('keyDown'|'keyUp')
488
489on(type: 'keyDown'|'keyUp', callback: (event: KeyEvent) => boolean): void
490
491Enables listening for a keyboard event. This API uses an asynchronous callback to return the result.
492
493**System capability**: SystemCapability.MiscServices.InputMethodFramework
494
495**Parameters**
496
497| Name  | Type                           | Mandatory| Description                                                        |
498| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
499| type   | string         | Yes  | Listening type.<br>The value **'keyDown'** indicates the keydown event.<br>The value **'keyUp'** indicates the keyup event.|
500| callback | (event: [KeyEvent](#keyevent)) => boolean | Yes| Callback used to return the key information.|
501
502**Example**
503
504```js
505inputMethodEngine.getKeyboardDelegate().on('keyUp', (keyEvent) => {
506    console.info('inputMethodEngine keyCode.(keyUp):' + JSON.stringify(keyEvent.keyCode));
507    console.info('inputMethodEngine keyAction.(keyUp):' + JSON.stringify(keyEvent.keyAction));
508    return true;
509});
510inputMethodEngine.getKeyboardDelegate().on('keyDown', (keyEvent) => {
511    console.info('inputMethodEngine keyCode.(keyDown):' + JSON.stringify(keyEvent.keyCode));
512    console.info('inputMethodEngine keyAction.(keyDown):' + JSON.stringify(keyEvent.keyAction));
513    return true;
514});
515```
516
517### off('keyDown'|'keyUp')
518
519off(type: 'keyDown'|'keyUp', callback?: (event: KeyEvent) => boolean): void
520
521Disables listening for a keyboard event. This API uses an asynchronous callback to return the result.
522
523**System capability**: SystemCapability.MiscServices.InputMethodFramework
524
525**Parameters**
526
527| Name   | Type    | Mandatory | Description |
528| -------- | ------- | ---- | ----- |
529| type     | string  | Yes  | Listening type.<br>The value **'keyDown'** indicates the keydown event.<br>The value **'keyUp'** indicates the keyup event.|
530| callback | (event: [KeyEvent](#keyevent)) => boolean | No  | Callback used to return the key information. |
531
532**Example**
533
534```js
535inputMethodEngine.getKeyboardDelegate().off('keyUp', (keyEvent) => {
536    console.log('delete keyUp notification.');
537    return true;
538});
539inputMethodEngine.getKeyboardDelegate().off('keyDown', (keyEvent) => {
540    console.log('delete keyDown notification.');
541    return true;
542});
543```
544
545### on('cursorContextChange')
546
547on(type: 'cursorContextChange', callback: (x: number, y:number, height:number) => void): void
548
549Enables listening for the cursor change event. This API uses an asynchronous callback to return the result.
550
551**System capability**: SystemCapability.MiscServices.InputMethodFramework
552
553**Parameters**
554
555| Name   | Type | Mandatory | Description |
556| -------- | ---- | ---- | ----- |
557| type     | string | Yes  | Listening type.<br>The value **'cursorContextChange'** indicates the cursor change event.|
558| 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.|
559
560**Example**
561
562```js
563inputMethodEngine.getKeyboardDelegate().on('cursorContextChange', (x, y, height) => {
564    console.log('inputMethodEngine cursorContextChange x:' + x);
565    console.log('inputMethodEngine cursorContextChange y:' + y);
566    console.log('inputMethodEngine cursorContextChange height:' + height);
567});
568```
569
570### off('cursorContextChange')
571
572off(type: 'cursorContextChange', callback?: (x: number, y: number, height: number) => void): void
573
574Cancels listening for cursor context changes. This API uses an asynchronous callback to return the result.
575
576**System capability**: SystemCapability.MiscServices.InputMethodFramework
577
578  **Parameters**
579
580| Name   | Type | Mandatory | Description  |
581| -------- | ---- | ---- | ------ |
582| type     | string  | Yes  | Listening type.<br>The value **'cursorContextChange'** indicates the cursor change event.|
583| 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>|
584
585
586  **Example**
587
588```js
589inputMethodEngine.getKeyboardDelegate().off('cursorContextChange', (x, y, height) => {
590    console.log('delete cursorContextChange notification.');
591});
592```
593### on('selectionChange')
594
595on(type: 'selectionChange', callback: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
596
597Enables listening for the text selection change event. This API uses an asynchronous callback to return the result.
598
599**System capability**: SystemCapability.MiscServices.InputMethodFramework
600
601**Parameters**
602
603| Name   | Type  | Mandatory| Description  |
604| -------- | ----- | ---- | ---- |
605| type     | string  | Yes  | Listening type.<br>The value **'selectionChange'** indicates the text selection change event.|
606| 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.|
607
608**Example**
609
610```js
611inputMethodEngine.getKeyboardDelegate().on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
612    console.log('inputMethodEngine beforeEach selectionChange oldBegin:' + oldBegin);
613    console.log('inputMethodEngine beforeEach selectionChange oldEnd:' + oldEnd);
614    console.log('inputMethodEngine beforeEach selectionChange newBegin:' + newBegin);
615    console.log('inputMethodEngine beforeEach selectionChange newEnd:' + newEnd);
616});
617```
618
619### off('selectionChange')
620
621off(type: 'selectionChange', callback?: (oldBegin: number, oldEnd: number, newBegin: number, newEnd: number) => void): void
622
623Cancels listening for text selection changes. This API uses an asynchronous callback to return the result.
624
625**System capability**: SystemCapability.MiscServices.InputMethodFramework
626
627**Parameters**
628
629| Name  | Type | Mandatory| Description    |
630| -------- | ------- | ---- | ------- |
631| type     | string  | Yes  | Listening type.<br>The value **'selectionChange'** indicates the text selection change event.|
632| 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>|
633
634**Example**
635
636```js
637inputMethodEngine.getKeyboardDelegate().off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => {
638  console.log('delete selectionChange notification.');
639});
640```
641
642
643### on('textChange')
644
645on(type: 'textChange', callback: (text: string) => void): void
646
647Enables listening for the text change event. This API uses an asynchronous callback to return the result.
648
649**System capability**: SystemCapability.MiscServices.InputMethodFramework
650
651**Parameters**
652
653| Name  | Type  | Mandatory| Description                                                        |
654| -------- | ------ | ---- | ------------------------------------------------------------ |
655| type     | string | Yes  | Listening type.<br>The value **'textChange'** indicates the text change event.|
656| callback | (text: string) => void | Yes  | Callback used to return the text content.|
657
658**Example**
659
660```js
661inputMethodEngine.getKeyboardDelegate().on('textChange', (text) => {
662    console.log('inputMethodEngine textChange. text:' + text);
663});
664```
665
666### off('textChange')
667
668off(type: 'textChange', callback?: (text: string) => void): void
669
670Cancels listening for text changes. This API uses an asynchronous callback to return the result.
671
672**System capability**: SystemCapability.MiscServices.InputMethodFramework
673
674**Parameters**
675
676| Name  | Type  | Mandatory| Description                                                        |
677| -------- | ------ | ---- | ------------------------------------------------------------ |
678| type     | string | Yes  | Listening type.<br>The value **'textChange'** indicates the text change event.|
679| callback | (text: string) => void | No  | Callback used to return the text content.|
680
681**Example**
682
683```js
684inputMethodEngine.getKeyboardDelegate().off('textChange', (text) => {
685    console.log('delete textChange notification. text:' + text);
686});
687```
688
689## KeyboardController
690
691In 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.
692
693### hide<sup>9+</sup>
694
695hide(callback: AsyncCallback&lt;void&gt;): void
696
697Hides the keyboard. This API uses an asynchronous callback to return the result.
698
699**System capability**: SystemCapability.MiscServices.InputMethodFramework
700
701**Parameters**
702
703| Name  | Type                  | Mandatory| Description    |
704| -------- | ---------------------- | ---- | -------- |
705| 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.|
706
707**Error codes**
708
709For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
710
711| Error Code ID| Error Message                |
712| -------- | -------------------------- |
713| 12800003 | input method client error. |
714
715**Example**
716
717```js
718keyboardController.hide((err) => {
719    if (err !== undefined) {
720        console.error('Failed to hide keyboard: ' + JSON.stringify(err));
721        return;
722    }
723    console.log('Succeeded in hiding keyboard.');
724});
725```
726
727### hide<sup>9+</sup>
728
729hide(): Promise&lt;void&gt;
730
731Hides the keyboard. This API uses a promise to return the result.
732
733**System capability**: SystemCapability.MiscServices.InputMethodFramework
734
735**Return value**
736
737| Type            | Description                     |
738| ---------------- | ------------------------- |
739| Promise&lt;void> | Promise that returns no value.|
740
741**Error codes**
742
743For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
744
745| Error Code ID| Error Message                |
746| -------- | -------------------------- |
747| 12800003 | input method client error. |
748
749**Example**
750
751```js
752keyboardController.hide().then(() => {
753    console.info('Succeeded in hiding keyboard.');
754}).catch((err) => {
755    console.info('Failed to hide keyboard: ' + JSON.stringify(err));
756});
757```
758
759### hideKeyboard<sup>(deprecated)</sup>
760
761hideKeyboard(callback: AsyncCallback&lt;void&gt;): void
762
763Hides the keyboard. This API uses an asynchronous callback to return the result.
764
765> **NOTE**
766>
767> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9) instead.
768
769**System capability**: SystemCapability.MiscServices.InputMethodFramework
770
771**Parameters**
772
773| Name  | Type                  | Mandatory| Description    |
774| -------- | ---------------------- | ---- | -------- |
775| 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.|
776
777**Example**
778
779```js
780keyboardController.hideKeyboard((err) => {
781    if (err !== undefined) {
782        console.error('Failed to hide Keyboard: ' + JSON.stringify(err));
783        return;
784    }
785    console.log('Succeeded in hiding keyboard.');
786});
787```
788
789### hideKeyboard<sup>(deprecated)</sup>
790
791hideKeyboard(): Promise&lt;void&gt;
792
793Hides the keyboard. This API uses a promise to return the result.
794
795> **NOTE**
796>
797> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [hide](#hide9-1) instead.
798
799**System capability**: SystemCapability.MiscServices.InputMethodFramework
800
801**Return value**
802
803| Type            | Description                     |
804| ---------------- | ------------------------- |
805| Promise&lt;void> | Promise that returns no value.|
806
807**Example**
808
809```js
810keyboardController.hideKeyboard().then(() => {
811    console.info('Succeeded in hiding keyboard.');
812}).catch((err) => {
813    console.info('Failed to hide Keyboard: ' + JSON.stringify(err));
814});
815```
816
817## InputClient<sup>9+</sup>
818
819In 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.
820
821### sendKeyFunction<sup>9+</sup>
822
823sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
824
825Sends the function key. This API uses an asynchronous callback to return the result.
826
827**System capability**: SystemCapability.MiscServices.InputMethodFramework
828
829  **Parameters**
830
831| Name| Type| Mandatory| Description|
832| -------- | -------- | -------- | -------- |
833| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).|
834| 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.|
835
836**Error codes**
837
838For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
839
840| Error Code ID| Error Message                |
841| -------- | -------------------------- |
842| 12800003 | input method client error. |
843
844 **Example**
845
846```js
847let action = 1;
848try {
849    inputClient.sendKeyFunction(action, (err, result) => {
850        if (err !== undefined) {
851            console.error('Failed to sendKeyFunction: ' + JSON.stringify(err));
852            return;
853        }
854        if (result) {
855            console.info('Succeeded in sending key function. ');
856        } else {
857            console.error('Failed to sendKeyFunction. ');
858        }
859    });
860} catch (err) {
861    console.error('sendKeyFunction err: ' + JSON.stringify(err));
862}
863```
864
865### sendKeyFunction<sup>9+</sup>
866
867sendKeyFunction(action: number): Promise&lt;boolean&gt;
868
869Sends the function key. This API uses a promise to return the result.
870
871**System capability**: SystemCapability.MiscServices.InputMethodFramework
872
873**Parameters**
874
875| Name| Type| Mandatory| Description|
876| -------- | -------- | -------- | -------- |
877| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).|
878
879**Return value**
880
881| Type                           | Description                                                        |
882| ------------------------------- | ------------------------------------------------------------ |
883| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.|
884
885**Error codes**
886
887For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
888
889| Error Code ID| Error Message                |
890| -------- | -------------------------- |
891| 12800003 | input method client error. |
892
893**Example**
894
895```js
896let action = 1;
897try {
898    inputClient.sendKeyFunction(action).then((result) => {
899        if (result) {
900            console.info('Succeeded in sending key function. ');
901        } else {
902            console.error('Failed to sendKeyFunction. ');
903        }
904    }).catch((err) => {
905        console.error('Failed to sendKeyFunction:' + JSON.stringify(err));
906    });
907} catch (err) {
908    console.error('Failed to sendKeyFunction: ' + JSON.stringify(err));
909}
910```
911
912### getForward<sup>9+</sup>
913
914getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
915
916Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result.
917
918**System capability**: SystemCapability.MiscServices.InputMethodFramework
919
920**Parameters**
921
922| Name| Type| Mandatory| Description|
923| -------- | -------- | -------- | -------- |
924| length | number | Yes| Text length.|
925| 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.|
926
927**Error codes**
928
929For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
930
931| Error Code ID| Error Message                    |
932| -------- | ------------------------------ |
933| 12800003 | input method client error.     |
934| 12800006 | Input method controller error. |
935
936**Example**
937
938```js
939let length = 1;
940try {
941    inputClient.getForward(length, (err, text) => {
942        if (err !== undefined) {
943            console.error('Failed to getForward: ' + JSON.stringify(err));
944            return;
945        }
946        console.log('Succeeded in getting forward, text: ' + text);
947    });
948} catch (err) {
949    console.error('Failed to getForward: ' + JSON.stringify(err));
950}
951```
952
953### getForward<sup>9+</sup>
954
955getForward(length:number): Promise&lt;string&gt;
956
957Obtains the specific-length text before the cursor. This API uses a promise to return the result.
958
959**System capability**: SystemCapability.MiscServices.InputMethodFramework
960
961**Parameters**
962
963| Name| Type| Mandatory| Description|
964| -------- | -------- | -------- | -------- |
965| length | number | Yes| Text length.|
966
967**Return value**
968
969| Type                           | Description                                                        |
970| ------------------------------- | ------------------------------------------------------------ |
971| Promise&lt;string&gt;           |  Promise used to return the specific-length text before the cursor.                    |
972
973**Error codes**
974
975For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
976
977| Error Code ID| Error Message                    |
978| -------- | ------------------------------ |
979| 12800003 | input method client error.     |
980| 12800006 | Input method controller error. |
981
982**Example**
983
984```js
985let length = 1;
986try {
987    inputClient.getForward(length).then((text) => {
988        console.info('Succeeded in getting forward, text: ' + text);
989    }).catch((err) => {
990        console.error('Failed to getForward: ' + JSON.stringify(err));
991    });
992} catch (err) {
993    console.error('Failed to getForward: ' + JSON.stringify(err));
994}
995```
996
997### getBackward<sup>9+</sup>
998
999getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
1000
1001Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result.
1002
1003**System capability**: SystemCapability.MiscServices.InputMethodFramework
1004
1005**Parameters**
1006
1007| Name| Type| Mandatory| Description|
1008| -------- | -------- | -------- | -------- |
1009| length | number | Yes| Text length.|
1010| 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.|
1011
1012**Error codes**
1013
1014For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1015
1016| Error Code ID| Error Message                    |
1017| -------- | ------------------------------ |
1018| 12800003 | input method client error.     |
1019| 12800006 | Input method controller error. |
1020
1021**Example**
1022
1023```js
1024let length = 1;
1025try {
1026    inputClient.getBackward(length, (err, text) => {
1027        if (err !== undefined) {
1028            console.error('Failed to getForward: ' + JSON.stringify(err));
1029            return;
1030        }
1031        console.log('Succeeded in getting backward, text: ' + text);
1032    });
1033} catch (err) {
1034    console.error('Failed to getForward: ' + JSON.stringify(err));
1035}
1036```
1037
1038### getBackward<sup>9+</sup>
1039
1040getBackward(length:number): Promise&lt;string&gt;
1041
1042Obtains the specific-length text after the cursor. This API uses a promise to return the result.
1043
1044**System capability**: SystemCapability.MiscServices.InputMethodFramework
1045
1046**Parameters**
1047
1048| Name| Type| Mandatory| Description|
1049| -------- | -------- | -------- | -------- |
1050| length | number | Yes| Text length.|
1051
1052**Return value**
1053
1054| Type                           | Description                                                        |
1055| ------------------------------- | ------------------------------------------------------------ |
1056| Promise&lt;string&gt;           |  Promise used to return the specific-length text after the cursor.                    |
1057
1058**Error codes**
1059
1060For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1061
1062| Error Code ID| Error Message                    |
1063| -------- | ------------------------------ |
1064| 12800003 | input method client error.     |
1065| 12800006 | Input method controller error. |
1066
1067**Example**
1068
1069```js
1070let length = 1;
1071try {
1072    inputClient.getBackward(length).then((text) => {
1073        console.info('Succeeded in getting backward, text: ' + text);
1074    }).catch((err) => {
1075        console.error('Failed to getForward: ' + JSON.stringify(err));
1076    });
1077} catch (err) {
1078  console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
1079}
1080```
1081
1082### deleteForward<sup>9+</sup>
1083
1084deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
1085
1086Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result.
1087
1088**System capability**: SystemCapability.MiscServices.InputMethodFramework
1089
1090**Parameters**
1091
1092| Name| Type| Mandatory| Description|
1093| -------- | -------- | -------- | -------- |
1094| length | number | Yes| Text length.|
1095| 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.|
1096
1097**Error codes**
1098
1099For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1100
1101| Error Code ID| Error Message                |
1102| -------- | -------------------------- |
1103| 12800002 | input method engine error. |
1104| 12800003 | input method client error. |
1105
1106**Example**
1107
1108```js
1109let length = 1;
1110try {
1111    inputClient.deleteForward(length, (err, result) => {
1112        if (err !== undefined) {
1113            console.error('Failed to delete forward: ' + JSON.stringify(err));
1114            return;
1115        }
1116        if (result) {
1117            console.info('Succeeded in deleting forward. ');
1118        } else {
1119            console.error('Failed to delete forward: ' + JSON.stringify(err));
1120        }
1121    });
1122} catch (err) {
1123    console.error('Failed to delete forward: ' + JSON.stringify(err));
1124}
1125```
1126
1127### deleteForward<sup>9+</sup>
1128
1129deleteForward(length:number): Promise&lt;boolean&gt;
1130
1131Deletes the fixed-length text before the cursor. This API uses a promise to return the result.
1132
1133**System capability**: SystemCapability.MiscServices.InputMethodFramework
1134
1135**Parameters**
1136
1137| Name| Type  | Mandatory| Description      |
1138| ------ | ------ | ---- | ---------- |
1139| length | number | Yes  | Text length.|
1140
1141**Return value**
1142
1143| Type                  | Description          |
1144| ---------------------- | -------------- |
1145| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.|
1146
1147**Error codes**
1148
1149For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1150
1151| Error Code ID| Error Message                |
1152| -------- | -------------------------- |
1153| 12800002 | Input method engine error. |
1154| 12800003 | input method client error. |
1155
1156**Example**
1157
1158```js
1159let length = 1;
1160try {
1161    inputClient.deleteForward(length).then((result) => {
1162        if (result) {
1163            console.info('Succeeded in deleting forward. ');
1164        } else {
1165            console.error('Failed to delete Forward. ');
1166        }
1167    }).catch((err) => {
1168        console.error('Failed to delete Forward: ' + JSON.stringify(err));
1169    });
1170} catch (err) {
1171  console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
1172}
1173```
1174
1175### deleteBackward<sup>9+</sup>
1176
1177deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
1178
1179Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result.
1180
1181**System capability**: SystemCapability.MiscServices.InputMethodFramework
1182
1183**Parameters**
1184
1185| Name  | Type                        | Mandatory| Description          |
1186| -------- | ---------------------------- | ---- | -------------- |
1187| length   | number                       | Yes  | Text length.    |
1188| 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.|
1189
1190**Error codes**
1191
1192For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1193
1194| Error Code ID| Error Message                |
1195| -------- | -------------------------- |
1196| 12800002 | Input method engine error. |
1197| 12800003 | input method client error. |
1198
1199**Example**
1200
1201```js
1202let length = 1;
1203try {
1204    inputClient.deleteBackward(length, (err, result) => {
1205        if (err !== undefined) {
1206            console.error('Failed to delete Backward: ' + JSON.stringify(err));
1207            return;
1208        }
1209        if (result) {
1210            console.info('Succeeded in deleting backward. ');
1211        } else {
1212            console.error('Failed to delete Backward: ' + JSON.stringify(err));
1213        }
1214    });
1215} catch (err) {
1216    console.error('deleteBackward err: ' + JSON.stringify(err));
1217}
1218```
1219
1220### deleteBackward<sup>9+</sup>
1221
1222deleteBackward(length:number): Promise&lt;boolean&gt;
1223
1224Deletes the fixed-length text after the cursor. This API uses a promise to return the result.
1225
1226**System capability**: SystemCapability.MiscServices.InputMethodFramework
1227
1228**Parameters**
1229
1230| Name| Type| Mandatory| Description|
1231| -------- | -------- | -------- | -------- |
1232| length | number | Yes| Text length.|
1233
1234**Return value**
1235
1236| Type                           | Description                                                        |
1237| ------------------------------- | ------------------------------------------------------------ |
1238| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.|
1239
1240**Error codes**
1241
1242For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1243
1244| Error Code ID| Error Message                |
1245| -------- | -------------------------- |
1246| 12800002 | Input method engine error. |
1247| 12800003 | input method client error. |
1248
1249**Example**
1250
1251```js
1252let length = 1;
1253inputClient.deleteBackward(length).then((result) => {
1254    if (result) {
1255        console.info('Succeeded in deleting backward. ');
1256    } else {
1257        console.error('Failed to deleteBackward. ');
1258    }
1259}).catch((err) => {
1260    console.error('Failed to deleteBackward: ' + JSON.stringify(err));
1261});
1262```
1263
1264### insertText<sup>9+</sup>
1265
1266insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
1267
1268Inserts text. This API uses an asynchronous callback to return the result.
1269
1270**System capability**: SystemCapability.MiscServices.InputMethodFramework
1271
1272**Parameters**
1273
1274| Name| Type| Mandatory| Description|
1275| -------- | -------- | -------- | -------- |
1276| text | string | Yes| Text to insert.|
1277| 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.|
1278
1279**Error codes**
1280
1281For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1282
1283| Error Code ID| Error Message                |
1284| -------- | -------------------------- |
1285| 12800002 | Input method engine error. |
1286| 12800003 | input method client error. |
1287
1288**Example**
1289
1290```js
1291inputClient.insertText('test', (err, result) => {
1292    if (err !== undefined) {
1293        console.error('Failed to insertText: ' + JSON.stringify(err));
1294        return;
1295    }
1296    if (result) {
1297        console.info('Succeeded in inserting text. ');
1298    } else {
1299        console.error('Failed to insertText. ');
1300    }
1301});
1302```
1303
1304### insertText<sup>9+</sup>
1305
1306insertText(text:string): Promise&lt;boolean&gt;
1307
1308Inserts text. This API uses a promise to return the result.
1309
1310**System capability**: SystemCapability.MiscServices.InputMethodFramework
1311
1312**Parameters**
1313
1314| Name| Type| Mandatory| Description|
1315| -------- | -------- | -------- | -------- |
1316| text | string | Yes| Text to insert.|
1317
1318**Return value**
1319
1320| Type                           | Description                                                        |
1321| ------------------------------- | ------------------------------------------------------------ |
1322| Promise&lt;boolean&gt;  |  Promise used to return the result. The value **true** means that the insertion is successful, and **false** means the opposite. |
1323
1324**Error codes**
1325
1326For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1327
1328| Error Code ID| Error Message                |
1329| -------- | -------------------------- |
1330| 12800002 | Input method engine error. |
1331| 12800003 | input method client error. |
1332
1333**Example**
1334
1335```js
1336try {
1337    inputClient.insertText('test').then((result) => {
1338        if (result) {
1339            console.info('Succeeded in inserting text. ');
1340        } else {
1341            console.error('Failed to insertText. ');
1342        }
1343    }).catch((err) => {
1344        console.error('Failed to insertText: ' + JSON.stringify(err));
1345    });
1346} catch (err) {
1347    console.error('Failed to insertText: ' + JSON.stringify(err));
1348}
1349```
1350
1351### getEditorAttribute<sup>9+</sup>
1352
1353getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
1354
1355Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result.
1356
1357**System capability**: SystemCapability.MiscServices.InputMethodFramework
1358
1359**Parameters**
1360
1361| Name                        | Type                         | Mandatory                           | Description                                                        |
1362| ------------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
1363| 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.|
1364
1365**Error codes**
1366
1367For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1368
1369| Error Code ID| Error Message                |
1370| -------- | -------------------------- |
1371| 12800003 | input method client error. |
1372
1373**Example**
1374
1375```js
1376inputClient.getEditorAttribute((err, editorAttribute) => {
1377    if (err !== undefined) {
1378        console.error('Failed to getEditorAttribute: ' + JSON.stringify(err));
1379        return;
1380    }
1381    console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
1382    console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
1383});
1384```
1385
1386### getEditorAttribute<sup>9+</sup>
1387
1388getEditorAttribute(): Promise&lt;EditorAttribute&gt;
1389
1390Obtains the attribute of the edit box. This API uses a promise to return the result.
1391
1392**System capability**: SystemCapability.MiscServices.InputMethodFramework
1393
1394**Return value**
1395
1396| Type                           | Description                                                        |
1397| ------------------------------- | ------------------------------------------------------------ |
1398| Promise&lt;[EditorAttribute](#editorattribute)&gt; |  Promise used to return the attribute of the edit box.          |
1399
1400**Error codes**
1401
1402For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1403
1404| Error Code ID| Error Message                |
1405| -------- | -------------------------- |
1406| 12800003 | input method client error. |
1407
1408**Example**
1409
1410```js
1411inputClient.getEditorAttribute().then((editorAttribute) => {
1412    console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
1413    console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
1414}).catch((err) => {
1415    console.error('Failed to getEditorAttribute: ' + JSON.stringify(err));
1416});
1417```
1418
1419### moveCursor<sup>9+</sup>
1420
1421moveCursor(direction: number, callback: AsyncCallback&lt;void&gt;): void
1422
1423Moves the cursor. This API uses an asynchronous callback to return the result.
1424
1425**System capability**: SystemCapability.MiscServices.InputMethodFramework
1426
1427**Parameters**
1428
1429| Name   | Type                     | Mandatory| Description          |
1430| --------- | ------------------------- | ---- | -------------- |
1431| direction | number                    | Yes  | Direction in which the cursor moves.|
1432| 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.   |
1433
1434**Error codes**
1435
1436For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1437
1438| Error Code ID| Error Message                |
1439| -------- | -------------------------- |
1440| 12800003 | input method client error. |
1441
1442**Example**
1443
1444```js
1445try {
1446    inputClient.moveCursor(inputMethodEngine.CURSOR_UP, (err) => {
1447        if (err !== undefined) {
1448            console.error('Failed to moveCursor: ' + JSON.stringify(err));
1449            return;
1450        }
1451        console.info('Succeeded in moving cursor.');
1452    });
1453} catch (err) {
1454    console.error('Failed to moveCursor: ' + JSON.stringify(err));
1455}
1456```
1457
1458### moveCursor<sup>9+</sup>
1459
1460moveCursor(direction: number): Promise&lt;void&gt;
1461
1462Moves the cursor. This API uses a promise to return the result.
1463
1464**System capability**: SystemCapability.MiscServices.InputMethodFramework
1465
1466**Parameters**
1467
1468| Name   | Type  | Mandatory| Description          |
1469| --------- | ------ | ---- | -------------- |
1470| direction | number | Yes  | Direction in which the cursor moves.|
1471
1472**Return value**
1473
1474| Type               | Description                     |
1475| ------------------- | ------------------------- |
1476| Promise&lt;void&gt; | Promise that returns no value.|
1477
1478**Error codes**
1479
1480For details about the error codes, see [Input Method Framework Error Codes](../errorcodes/errorcode-inputmethod-framework.md).
1481
1482| Error Code ID| Error Message                |
1483| -------- | -------------------------- |
1484| 12800003 | input method client error. |
1485
1486**Example**
1487
1488```js
1489try {
1490    inputClient.moveCursor(inputMethodEngine.CURSOR_UP).then(() => {
1491        console.log('Succeeded in moving cursor.');
1492    }).catch((err) => {
1493        console.error('Failed to moveCursor: ' + JSON.stringify(err));
1494    });
1495} catch (err) {
1496    console.log('Failed to moveCursor: ' + JSON.stringify(err));
1497}
1498```
1499
1500## EditorAttribute
1501
1502Attribute of the edit box.
1503
1504**System capability**: SystemCapability.MiscServices.InputMethodFramework
1505
1506| Name        | Type| Readable| Writable| Description              |
1507| ------------ | -------- | ---- | ---- | ------------------ |
1508| enterKeyType | number   | Yes  | No  | Function attribute of the edit box.|
1509| inputPattern | number   | Yes  | No  | Text attribute of the edit box.|
1510
1511## KeyEvent
1512
1513Describes the attribute of a key.
1514
1515**System capability**: SystemCapability.MiscServices.InputMethodFramework
1516
1517| Name     | Type| Readable| Writable| Description        |
1518| --------- | -------- | ---- | ---- | ------------ |
1519| keyCode   | number   | Yes  | No  | Key value. For detail, see [KeyCode](js-apis-keycode.md#keycode).|
1520| keyAction | number   | Yes  | No  | Key event type.<br>- **2**: keydown event.<br>- **3**: keyup event.|
1521
1522## TextInputClient<sup>(deprecated)</sup>
1523
1524> **NOTE**
1525>
1526> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [InputClient](#inputclient9) instead.
1527
1528In 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.
1529
1530### getForward<sup>(deprecated)</sup>
1531
1532getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
1533
1534Obtains the specific-length text before the cursor. This API uses an asynchronous callback to return the result.
1535
1536> **NOTE**
1537>
1538> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9) instead.
1539
1540**System capability**: SystemCapability.MiscServices.InputMethodFramework
1541
1542**Parameters**
1543
1544| Name| Type| Mandatory| Description|
1545| -------- | -------- | -------- | -------- |
1546| length | number | Yes| Text length.|
1547| 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.|
1548
1549**Example**
1550
1551```js
1552let length = 1;
1553textInputClient.getForward(length, (err, text) => {
1554    if (err !== undefined) {
1555        console.error('Failed to getForward: ' + JSON.stringify(err));
1556        return;
1557    }
1558    console.log('Succeeded in getting forward, text: ' + text);
1559});
1560```
1561
1562### getForward<sup>(deprecated)</sup>
1563
1564getForward(length:number): Promise&lt;string&gt;
1565
1566Obtains the specific-length text before the cursor. This API uses a promise to return the result.
1567
1568> **NOTE**
1569>
1570> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getForward](#getforward9) instead.
1571
1572**System capability**: SystemCapability.MiscServices.InputMethodFramework
1573
1574**Parameters**
1575
1576| Name| Type| Mandatory| Description|
1577| -------- | -------- | -------- | -------- |
1578| length | number | Yes| Text length.|
1579
1580**Return value**
1581
1582| Type                           | Description                                                        |
1583| ------------------------------- | ------------------------------------------------------------ |
1584| Promise&lt;string&gt; |  Promise used to return the specific-length text before the cursor.               |
1585
1586**Example**
1587
1588```js
1589let length = 1;
1590textInputClient.getForward(length).then((text) => {
1591    console.info('Succeeded in getting forward, text: ' + text);
1592}).catch((err) => {
1593    console.error('Failed to getForward: ' + JSON.stringify(err));
1594});
1595```
1596
1597### getBackward<sup>(deprecated)</sup>
1598
1599getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
1600
1601Obtains the specific-length text after the cursor. This API uses an asynchronous callback to return the result.
1602
1603> **NOTE**
1604>
1605> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9) instead.
1606
1607**System capability**: SystemCapability.MiscServices.InputMethodFramework
1608
1609**Parameters**
1610
1611| Name| Type| Mandatory| Description|
1612| -------- | -------- | -------- | -------- |
1613| length | number | Yes| Text length.|
1614| 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.|
1615
1616**Example**
1617
1618```js
1619let length = 1;
1620textInputClient.getBackward(length, (err, text) => {
1621    if (err !== undefined) {
1622        console.error('Failed to getBackward: ' + JSON.stringify(err));
1623        return;
1624    }
1625    console.log('Succeeded in getting borward, text: ' + text);
1626});
1627```
1628
1629### getBackward<sup>(deprecated)</sup>
1630
1631getBackward(length:number): Promise&lt;string&gt;
1632
1633Obtains the specific-length text after the cursor. This API uses a promise to return the result.
1634
1635> **NOTE**
1636>
1637> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getBackward](#getbackward9) instead.
1638
1639**System capability**: SystemCapability.MiscServices.InputMethodFramework
1640
1641**Parameters**
1642
1643| Name| Type| Mandatory| Description|
1644| -------- | -------- | -------- | -------- |
1645| length | number | Yes| Text length.|
1646
1647**Return value**
1648
1649| Type                           | Description                                                        |
1650| ------------------------------- | ------------------------------------------------------------ |
1651| Promise&lt;string&gt; |  Promise used to return the specific-length text after the cursor.               |
1652
1653**Example**
1654
1655```js
1656let length = 1;
1657textInputClient.getBackward(length).then((text) => {
1658    console.info('Succeeded in getting backward: ' + JSON.stringify(text));
1659}).catch((err) => {
1660    console.error('Failed to getBackward: ' + JSON.stringify(err));
1661});
1662```
1663
1664### deleteForward<sup>(deprecated)</sup>
1665
1666deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
1667
1668Deletes the fixed-length text before the cursor. This API uses an asynchronous callback to return the result.
1669
1670> **NOTE**
1671>
1672> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9) instead.
1673
1674**System capability**: SystemCapability.MiscServices.InputMethodFramework
1675
1676**Parameters**
1677
1678| Name| Type| Mandatory| Description|
1679| -------- | -------- | -------- | -------- |
1680| length | number | Yes| Text length.|
1681| 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.|
1682
1683**Example**
1684
1685```js
1686let length = 1;
1687textInputClient.deleteForward(length, (err, result) => {
1688    if (err !== undefined) {
1689        console.error('Failed to deleteForward: ' + JSON.stringify(err));
1690        return;
1691    }
1692    if (result) {
1693        console.info('Succeeded in deleting forward. ');
1694    } else {
1695        console.error('Failed to deleteForward. ');
1696    }
1697});
1698```
1699
1700### deleteForward<sup>(deprecated)</sup>
1701
1702deleteForward(length:number): Promise&lt;boolean&gt;
1703
1704Deletes the fixed-length text before the cursor. This API uses a promise to return the result.
1705
1706> **NOTE**
1707>
1708> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteForward](#deleteforward9) instead.
1709
1710**System capability**: SystemCapability.MiscServices.InputMethodFramework
1711
1712**Parameters**
1713
1714| Name| Type  | Mandatory| Description      |
1715| ------ | ------ | ---- | ---------- |
1716| length | number | Yes  | Text length.|
1717
1718**Return value**
1719
1720| Type                  | Description          |
1721| ---------------------- | -------------- |
1722| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.|
1723
1724**Example**
1725
1726```js
1727let length = 1;
1728textInputClient.deleteForward(length).then((result) => {
1729    if (result) {
1730        console.info('Succeeded in deleting forward. ');
1731    } else {
1732        console.error('Failed to delete forward. ');
1733    }
1734}).catch((err) => {
1735    console.error('Failed to delete forward: ' + JSON.stringify(err));
1736});
1737```
1738
1739### deleteBackward<sup>(deprecated)</sup>
1740
1741deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
1742
1743Deletes the fixed-length text after the cursor. This API uses an asynchronous callback to return the result.
1744
1745> **NOTE**
1746>
1747> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9) instead.
1748
1749**System capability**: SystemCapability.MiscServices.InputMethodFramework
1750
1751**Parameters**
1752
1753| Name  | Type                        | Mandatory| Description          |
1754| -------- | ---------------------------- | ---- | -------------- |
1755| length   | number                       | Yes  | Text length.    |
1756| 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.|
1757
1758**Example**
1759
1760```js
1761let length = 1;
1762textInputClient.deleteBackward(length, (err, result) => {
1763    if (err !== undefined) {
1764        console.error('Failed to delete backward: ' + JSON.stringify(err));
1765        return;
1766    }
1767    if (result) {
1768        console.info('Succeeded in deleting backward. ');
1769    } else {
1770        console.error('Failed to deleteBackward. ');
1771    }
1772});
1773```
1774
1775### deleteBackward<sup>(deprecated)</sup>
1776
1777deleteBackward(length:number): Promise&lt;boolean&gt;
1778
1779Deletes the fixed-length text after the cursor. This API uses a promise to return the result.
1780
1781> **NOTE**
1782>
1783> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [deleteBackward](#deletebackward9) instead.
1784
1785**System capability**: SystemCapability.MiscServices.InputMethodFramework
1786
1787**Parameters**
1788
1789| Name| Type| Mandatory| Description|
1790| -------- | -------- | -------- | -------- |
1791| length | number | Yes| Text length.|
1792
1793**Return value**
1794
1795| Type                           | Description                                                        |
1796| ------------------------------- | ------------------------------------------------------------ |
1797| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the deletion is successful, and **false** means the opposite.|
1798
1799**Example**
1800
1801```js
1802let length = 1;
1803textInputClient.deleteBackward(length).then((result) => {
1804    if (result) {
1805        console.info('Succeeded in deleting backward. ');
1806    } else {
1807        console.error('Failed to deleteBackward. ');
1808    }
1809}).catch((err) => {
1810    console.error('Failed to deleteBackward: ' + JSON.stringify(err));
1811});
1812```
1813### sendKeyFunction<sup>(deprecated)</sup>
1814
1815sendKeyFunction(action: number, callback: AsyncCallback&lt;boolean&gt;): void
1816
1817Sends the function key. This API uses an asynchronous callback to return the result.
1818
1819> **NOTE**
1820>
1821> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9) instead.
1822
1823**System capability**: SystemCapability.MiscServices.InputMethodFramework
1824
1825**Parameters**
1826
1827| Name| Type| Mandatory| Description|
1828| -------- | -------- | -------- | -------- |
1829| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).|
1830| 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.|
1831
1832**Example**
1833
1834```js
1835let action = 1;
1836textInputClient.sendKeyFunction(action, (err, result) => {
1837    if (err !== undefined) {
1838        console.error('Failed to sendKeyFunction: ' + JSON.stringify(err));
1839        return;
1840    }
1841    if (result) {
1842        console.info('Succeeded in sending key function. ');
1843    } else {
1844        console.error('Failed to sendKeyFunction. ');
1845    }
1846});
1847```
1848
1849### sendKeyFunction<sup>(deprecated)</sup>
1850
1851sendKeyFunction(action: number): Promise&lt;boolean&gt;
1852
1853Sends the function key. This API uses a promise to return the result.
1854
1855> **NOTE**
1856>
1857> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [sendKeyFunction](#sendkeyfunction9) instead.
1858
1859**System capability**: SystemCapability.MiscServices.InputMethodFramework
1860
1861**Parameters**
1862
1863| Name| Type| Mandatory| Description|
1864| -------- | -------- | -------- | -------- |
1865| action | number | Yes| Action of the function key.<br>- **0**: invalid key.<br>- **1**: confirm key (Enter key).|
1866
1867**Return value**
1868
1869| Type                           | Description                                                        |
1870| ------------------------------- | ------------------------------------------------------------ |
1871| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the setting is successful, and **false** means the opposite.|
1872
1873**Example**
1874
1875```js
1876let action = 1;
1877textInputClient.sendKeyFunction(action).then((result) => {
1878    if (result) {
1879        console.info('Succeeded in sending key function. ');
1880    } else {
1881        console.error('Failed to sendKeyFunction. ');
1882    }
1883}).catch((err) => {
1884    console.error('Failed to sendKeyFunction:' + JSON.stringify(err));
1885});
1886```
1887
1888### insertText<sup>(deprecated)</sup>
1889
1890insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
1891
1892Inserts text. This API uses an asynchronous callback to return the result.
1893
1894> **NOTE**
1895>
1896> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9) instead.
1897
1898**System capability**: SystemCapability.MiscServices.InputMethodFramework
1899
1900**Parameters**
1901
1902| Name| Type| Mandatory| Description|
1903| -------- | -------- | -------- | -------- |
1904| text | string | Yes| Text to insert.|
1905| 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.|
1906
1907**Example**
1908
1909```js
1910textInputClient.insertText('test', (err, result) => {
1911    if (err !== undefined) {
1912        console.error('Failed to insertText: ' + JSON.stringify(err));
1913        return;
1914    }
1915    if (result) {
1916        console.info('Succeeded in inserting text. ');
1917    } else {
1918        console.error('Failed to insertText. ');
1919    }
1920});
1921```
1922
1923### insertText<sup>(deprecated)</sup>
1924
1925insertText(text:string): Promise&lt;boolean&gt;
1926
1927Inserts text. This API uses a promise to return the result.
1928
1929> **NOTE**
1930>
1931> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [insertText](#inserttext9) instead.
1932
1933**System capability**: SystemCapability.MiscServices.InputMethodFramework
1934
1935**Parameters**
1936
1937| Name| Type| Mandatory| Description|
1938| -------- | -------- | -------- | -------- |
1939| text | string | Yes| Text to insert.|
1940
1941**Return value**
1942
1943| Type                           | Description                                                        |
1944| ------------------------------- | ------------------------------------------------------------ |
1945| Promise&lt;boolean&gt; |  Promise used to return the result. The value **true** means that the insertion is successful, and **false** means the opposite.|
1946
1947**Example**
1948
1949```js
1950textInputClient.insertText('test').then((result) => {
1951    if (result) {
1952        console.info('Succeeded in inserting text. ');
1953    } else {
1954        console.error('Failed to insertText. ');
1955    }
1956}).catch((err) => {
1957    console.error('Failed to insertText: ' + JSON.stringify(err));
1958});
1959```
1960
1961### getEditorAttribute<sup>(deprecated)</sup>
1962
1963getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
1964
1965Obtains the attribute of the edit box. This API uses an asynchronous callback to return the result.
1966
1967> **NOTE**
1968>
1969> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9) instead.
1970
1971**System capability**: SystemCapability.MiscServices.InputMethodFramework
1972
1973**Parameters**
1974
1975| Name   | Type  | Mandatory | Description  |
1976| -------- | ----- | ----- | ----- |
1977| 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.|
1978
1979**Example**
1980
1981```js
1982textInputClient.getEditorAttribute((err, editorAttribute) => {
1983    if (err !== undefined) {
1984        console.error('Failed to getEditorAttribute: ' + JSON.stringify(err));
1985        return;
1986    }
1987    console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
1988    console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
1989});
1990```
1991
1992### getEditorAttribute<sup>(deprecated)</sup>
1993
1994getEditorAttribute(): Promise&lt;EditorAttribute&gt;
1995
1996Obtains the attribute of the edit box. This API uses a promise to return the result.
1997
1998> **NOTE**
1999>
2000> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getEditorAttribute](#geteditorattribute9) instead.
2001
2002**System capability**: SystemCapability.MiscServices.InputMethodFramework
2003
2004**Return value**
2005
2006| Type                           | Description                                                        |
2007| ------------------------------- | ------------------------------------------------------------ |
2008| Promise&lt;[EditorAttribute](#editorattribute)&gt; |  Promise used to return the attribute of the edit box.          |
2009
2010**Example**
2011
2012```js
2013textInputClient.getEditorAttribute().then((editorAttribute) => {
2014    console.info('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
2015    console.info('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
2016}).catch((err) => {
2017    console.error('Failed to getEditorAttribute: ' + JSON.stringify(err));
2018});
2019```
2020