• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.inputMethod (Input Method Framework)
2<!--Kit: IME Kit-->
3<!--Subsystem: MiscServices-->
4<!--Owner: @illybyy-->
5<!--Designer: @andeszhang-->
6<!--Tester: @murphy1984-->
7<!--Adviser: @zhang_yixin13-->
8
9The **inputMethod** module is oriented to common foreground applications (third-party applications and system applications such as Notes, Messaging, and Settings). It provides input method control and management capabilities, including displaying or hiding the soft keyboard, switching between input methods, and obtaining the list of all input methods.
10
11> **NOTE**
12>
13> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
14
15
16## Modules to Import
17
18```ts
19import { inputMethod } from '@kit.IMEKit';
20```
21
22## Constant
23
24Provides the constants.
25
26**System capability**: SystemCapability.MiscServices.InputMethodFramework
27
28| Name| Type| Value| Description|
29| -------- | -------- | -------- | -------- |
30| MAX_TYPE_NUM<sup>8+</sup> | number | 128 | Maximum number of supported input methods.|
31
32## InputMethodProperty<sup>8+</sup>
33
34Describes the input method application attributes.
35
36**System capability**: SystemCapability.MiscServices.InputMethodFramework
37
38| Name| Type| Read-only| Optional| Description|
39| -------- | -------- | -------- | -------- | -------- |
40| name<sup>9+</sup>  | string | Yes| No| Mandatory. Name of the input method package.|
41| id<sup>9+</sup>    | string | Yes| No| Mandatory. Unique identifier of an input method extension in an app. **id** and **name** form a globally unique identifier of the input method extension.|
42| label<sup>9+</sup>    | string | Yes| Yes| Optional.<br>- When **InputMethodProperty** is used as the input parameter of an API for switching or querying, you do not need to set this field. You can use name and ID to uniquely specify an input method extension.<br>- When **InputMethodProperty** is used as the return value of an API for querying (for example, [getCurrentInputMethod](#inputmethodgetcurrentinputmethod9)), this field indicates the name of the input method extension displayed externally. Use the label configured for the InputMethodExtensionAbility. If no label is configured, the label of the application entry ability is automatically used. If no label is configured for the application entry ability, the label configured in **AppScope** is automatically used.|
43| labelId<sup>10+</sup>    | number | Yes| Yes| Optional.<br>- When **InputMethodProperty** is used as the input parameter of an API for switching or querying, you do not need to set this field. You can use name and ID to uniquely specify an input method extension.<br>- When **InputMethodProperty** is used as the return value of an API for querying (for example, [getCurrentInputMethod](#inputmethodgetcurrentinputmethod9)), this field indicates the resource ID of the **label** field.|
44| icon<sup>9+</sup>    | string | Yes| Yes| Optional.<br>- When **InputMethodProperty** is used as the input parameter of an API for switching or querying, you do not need to set this field. You can use name and ID to uniquely specify an input method extension.<br>- When **InputMethodProperty** is used as the return value of an API for querying (for example, [getCurrentInputMethod](#inputmethodgetcurrentinputmethod9)), this field indicates the input method icon data, which can be obtained through icon ID.|
45| iconId<sup>9+</sup>    | number | Yes| Yes| Optional.<br>- When **InputMethodProperty** is used as the input parameter of an API for switching or querying, you do not need to set this field. You can use name and ID to uniquely specify an input method extension.<br>- When **InputMethodProperty** is used as the return value of an API for querying (for example, [getCurrentInputMethod](#inputmethodgetcurrentinputmethod9)), this field indicates the resource ID of the **icon** field.|
46| enabledState<sup>20+</sup>    | [EnabledState](js-apis-inputmethod.md#enabledstate15) | Yes| Yes| Optional.<br>- When **InputMethodProperty** is used as the input parameter of an API for switching or querying, you do not need to set this field. You can use name and ID to uniquely specify an input method extension.<br>- When **InputMethodProperty** is used as the return value of an API for querying (for example, [getCurrentInputMethod](#inputmethodgetcurrentinputmethod9)), this field indicates whether the input method is enabled.|
47| extra<sup>9+</sup>    | object | No| Yes| Extra information about the input method. This parameter is reserved and currently has no specific meaning.<br>- API version 10 and later: optional<br>- API version 9: mandatory|
48| packageName<sup>(deprecated)</sup> | string | Yes| No| Name of the input method package. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **name** instead.|
49| methodId<sup>(deprecated)</sup> | string | Yes| No| Unique ID of the input method. Mandatory.<br>**NOTE**<br>This API is supported since API version 8 and deprecated since API version 9. You are advised to use **id** instead.|
50
51## CapitalizeMode<sup>20+</sup>
52
53Enumerates the modes of capitalizing the first letter of a text.
54
55**System capability**: SystemCapability.MiscServices.InputMethodFramework
56
57| Name| Value| Description|
58| -------- | -- | -------- |
59| NONE | 0 | The first letter is not capitalized.|
60| SENTENCES | 1 | The first letter of each sentence is capitalized.|
61| WORDS | 2 | The first letter of each word is capitalized.|
62| CHARACTERS | 3 | All letters are capitalized.|
63
64## inputMethod.getController<sup>9+</sup>
65
66getController(): InputMethodController
67
68Obtains an [InputMethodController](#inputmethodcontroller) instance.
69
70**System capability**: SystemCapability.MiscServices.InputMethodFramework
71
72**Return value**
73
74| Type                                           | Description                  |
75| ----------------------------------------------- | ---------------------- |
76| [InputMethodController](#inputmethodcontroller) | **InputMethodController** instance.|
77
78**Error codes**
79
80For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
81
82| ID| Error Message                    |
83| -------- | ------------------------------ |
84| 12800006 | input method controller error. Possible cause: create InputMethodController object failed. |
85
86**Example**
87
88```ts
89let inputMethodController = inputMethod.getController();
90```
91
92## inputMethod.getDefaultInputMethod<sup>11+</sup>
93
94getDefaultInputMethod(): InputMethodProperty
95
96Obtains the default input method.
97
98**System capability**: SystemCapability.MiscServices.InputMethodFramework
99
100**Return value**
101
102| Type                                        | Description                    |
103| -------------------------------------------- | ------------------------ |
104| [InputMethodProperty](#inputmethodproperty8) | Default input method.|
105
106**Error codes**
107
108For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
109
110| ID| Error Message                            |
111| -------- | -------------------------------------- |
112| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
113
114**Example**
115
116```ts
117try {
118  let defaultIme = inputMethod.getDefaultInputMethod();
119} catch(err) {
120  console.error(`Failed to getDefaultInputMethod: ${JSON.stringify(err)}`);
121}
122```
123
124## inputMethod.getSystemInputMethodConfigAbility<sup>11+</sup>
125
126getSystemInputMethodConfigAbility(): ElementName
127
128Obtains the information about the input method configuration page ability.
129
130**System capability**: SystemCapability.MiscServices.InputMethodFramework
131
132**Return value**
133
134| Type                                        | Description                    |
135| -------------------------------------------- | ------------------------ |
136| [ElementName](../apis-ability-kit/js-apis-bundleManager-elementName.md) | Element name of the input method configuration page ability.|
137
138**Error codes**
139
140For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
141
142| ID| Error Message                            |
143| -------- | -------------------------------------- |
144| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
145
146**Example**
147
148```ts
149try {
150  let inputMethodConfig = inputMethod.getSystemInputMethodConfigAbility();
151} catch(err) {
152  console.error(`Failed to get getSystemInputMethodConfigAbility: ${JSON.stringify(err)}`);
153}
154```
155
156## inputMethod.getSetting<sup>9+</sup>
157
158getSetting(): InputMethodSetting
159
160Obtains an [InputMethodSetting](#inputmethodsetting8) instance.
161
162**System capability**: SystemCapability.MiscServices.InputMethodFramework
163
164**Return value**
165
166| Type                                     | Description                      |
167| ----------------------------------------- | -------------------------- |
168| [InputMethodSetting](#inputmethodsetting8) | **InputMethodSetting** instance.|
169
170**Error codes**
171
172For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
173
174| ID| Error Message                            |
175| -------- | -------------------------------------- |
176| 12800007 |  input method setter error. Possible cause: create InputMethodSetting object failed. |
177
178**Example**
179
180```ts
181let inputMethodSetting = inputMethod.getSetting();
182```
183
184## inputMethod.switchInputMethod<sup>9+</sup>
185
186switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolean&gt;): void
187
188Switches to another input method. This API uses an asynchronous callback to return the result.
189> **NOTE**
190>
191>  - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission.
192>  - Since API version 11, this API can only be called by the current input method application.
193
194**System capability**: SystemCapability.MiscServices.InputMethodFramework
195
196**Parameters**
197
198| Name| Type| Mandatory| Description|
199| -------- | -------- | -------- | -------- |
200| target | [InputMethodProperty](#inputmethodproperty8) | Yes| Target input method.|
201| 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.|
202
203**Error codes**
204
205For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
206
207| ID| Error Message                            |
208| -------- | -------------------------------------- |
209| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
210| 12800005 | configuration persistence error.        |
211| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
212
213**Example**
214
215```ts
216import { BusinessError } from '@kit.BasicServicesKit';
217
218let currentIme = inputMethod.getCurrentInputMethod();
219try{
220  inputMethod.switchInputMethod(currentIme, (err: BusinessError, result: boolean) => {
221    if (err) {
222      console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
223      return;
224    }
225    if (result) {
226      console.info('Succeeded in switching input method.');
227    } else {
228      console.error('Failed to switch input method.');
229    }
230  });
231} catch(err) {
232  console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
233}
234```
235
236> **NOTE**
237>
238> Since API version 11, the error code `201 permissions check fails` is removed.
239
240## inputMethod.switchInputMethod<sup>9+</sup>
241switchInputMethod(target: InputMethodProperty): Promise&lt;boolean&gt;
242
243Switches to another input method. This API uses a promise to return the result.
244> **NOTE**
245>
246>  - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission.
247>  - Since API version 11, this API can only be called by the current input method application.
248
249**System capability**: SystemCapability.MiscServices.InputMethodFramework
250
251**Parameters**
252
253  | Name| Type| Mandatory| Description|
254  | -------- | -------- | -------- | -------- |
255  |target |  [InputMethodProperty](#inputmethodproperty8)| Yes| Target input method.|
256
257**Return value**
258
259  | Type                                     | Description                        |
260  | ----------------------------------------- | ---------------------------- |
261  | Promise\<boolean> | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.|
262
263**Error codes**
264
265For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
266
267| ID| Error Message                            |
268| -------- | -------------------------------------- |
269| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
270| 12800005 | configuration persistence error.        |
271| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
272
273**Example**
274
275```ts
276import { BusinessError } from '@kit.BasicServicesKit';
277
278let currentIme = inputMethod.getCurrentInputMethod();
279try {
280  inputMethod.switchInputMethod(currentIme).then((result: boolean) => {
281    if (result) {
282      console.info('Succeeded in switching input method.');
283    } else {
284      console.error('Failed to switch input method.');
285    }
286  }).catch((err: BusinessError) => {
287    console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
288  })
289} catch (err) {
290  console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
291}
292```
293
294> **NOTE**
295>
296> Since API version 11, the error code `201 permissions check fails` is removed.
297
298## inputMethod.getCurrentInputMethod<sup>9+</sup>
299
300getCurrentInputMethod(): InputMethodProperty
301
302Obtains the current input method. This API returns the result synchronously.
303
304**System capability**: SystemCapability.MiscServices.InputMethodFramework
305
306**Return value**
307
308| Type                                        | Description                    |
309| -------------------------------------------- | ------------------------ |
310| [InputMethodProperty](#inputmethodproperty8) | **InputmethodProperty** instance of the current input method.|
311
312**Example**
313
314```ts
315let currentIme = inputMethod.getCurrentInputMethod();
316```
317
318## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
319
320switchCurrentInputMethodSubtype(target: InputMethodSubtype, callback: AsyncCallback\<boolean>): void
321
322Switches to another subtype of this input method. This API uses an asynchronous callback to return the result.
323
324> **NOTE**
325>
326>  - In API version 9, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission.
327>  - In API version 10, this API can only be called by system applications and the current input method application, and the **ohos.permission.CONNECT_IME_ABILITY** permission is required.
328>  - Since API version 11, this API can only be called by the current input method application.
329
330**System capability**: SystemCapability.MiscServices.InputMethodFramework
331
332**Parameters**
333
334| Name| Type| Mandatory| Description|
335| -------- | -------- | -------- | -------- |
336| target |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.|
337| 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.|
338
339**Error codes**
340
341For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
342
343| ID| Error Message                            |
344| -------- | -------------------------------------- |
345| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
346| 12800005 | configuration persistence error.        |
347| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
348
349**Example**
350
351```ts
352import { BusinessError } from '@kit.BasicServicesKit';
353
354try {
355  let extra: Record<string, string> = {}
356  inputMethod.switchCurrentInputMethodSubtype({
357    id: "ServiceExtAbility",
358    label: "",
359    name: "com.example.kikakeyboard",
360    mode: "upper",
361    locale: "",
362    language: "",
363    icon: "",
364    iconId: 0,
365    extra: extra
366  }, (err: BusinessError, result: boolean) => {
367    if (err) {
368      console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
369      return;
370    }
371    if (result) {
372      console.info('Succeeded in switching currentInputMethodSubtype.');
373    } else {
374      console.error('Failed to switchCurrentInputMethodSubtype');
375    }
376  });
377} catch(err) {
378  console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
379}
380```
381
382> **NOTE**
383>
384> Since API version 11, the error code `201 permissions check fails` is removed.
385
386## inputMethod.switchCurrentInputMethodSubtype<sup>9+</sup>
387
388switchCurrentInputMethodSubtype(target: InputMethodSubtype): Promise&lt;boolean&gt;
389
390Switches to another subtype of this input method. This API uses a promise to return the result.
391
392> **NOTE**
393>
394>  - In API version 9, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission.
395>  - In API version 10, this API can only be called by system applications and the current input method application, and the **ohos.permission.CONNECT_IME_ABILITY** permission is required.
396>  - Since API version 11, this API can only be called by the current input method application.
397
398**System capability**: SystemCapability.MiscServices.InputMethodFramework
399
400**Parameters**
401
402| Name| Type| Mandatory| Description|
403| -------- | -------- | -------- | -------- |
404|target |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.|
405
406**Return value**
407
408| Type                                     | Description                        |
409| ----------------------------------------- | ---------------------------- |
410| Promise\<boolean> | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.|
411
412**Error codes**
413
414For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
415
416| ID| Error Message                            |
417| -------- | -------------------------------------- |
418| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
419| 12800005 | configuration persistence error.        |
420| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
421
422**Example**
423
424```ts
425import { BusinessError } from '@kit.BasicServicesKit';
426
427try {
428  let extra: Record<string, string> = {}
429  inputMethod.switchCurrentInputMethodSubtype({
430    id: "ServiceExtAbility",
431    label: "",
432    name: "com.example.kikakeyboard",
433    mode: "upper",
434    locale: "",
435    language: "",
436    icon: "",
437    iconId: 0,
438    extra: extra
439  }).then((result: boolean) => {
440    if (result) {
441      console.info('Succeeded in switching currentInputMethodSubtype.');
442    } else {
443      console.error('Failed to switchCurrentInputMethodSubtype.');
444    }
445  }).catch((err: BusinessError) => {
446    console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
447  })
448} catch(err) {
449  console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
450}
451```
452
453> **NOTE**
454>
455> Since API version 11, the error code `201 permissions check fails` is removed.
456
457## inputMethod.getCurrentInputMethodSubtype<sup>9+</sup>
458
459getCurrentInputMethodSubtype(): InputMethodSubtype
460
461Obtains the current input method subtype.
462
463**System capability**: SystemCapability.MiscServices.InputMethodFramework
464
465**Return value**
466
467| Type                                        | Description                    |
468| -------------------------------------------- | ------------------------ |
469| [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype) | Current input method subtype.|
470
471**Example**
472
473```ts
474let currentImeSubType = inputMethod.getCurrentInputMethodSubtype();
475```
476
477## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>
478
479switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype, callback: AsyncCallback\<boolean>): void
480
481Switches to a specified subtype of a specified input method. This API uses an asynchronous callback to return the result.
482
483> **NOTE**
484>
485>  - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission.
486>  - Since API version 11, this API can only be called by the current input method application.
487
488**System capability**: SystemCapability.MiscServices.InputMethodFramework
489
490**Parameters**
491
492| Name| Type| Mandatory| Description|
493| -------- | -------- | -------- | -------- |
494|inputMethodProperty |  [InputMethodProperty](#inputmethodproperty8)| Yes| Target input method.|
495|inputMethodSubtype |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.|
496| 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.|
497
498**Error codes**
499
500For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
501
502| ID| Error Message                            |
503| -------- | -------------------------------------- |
504| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
505| 12800005 | configuration persistence error.        |
506| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
507
508**Example**
509
510```ts
511import { BusinessError } from '@kit.BasicServicesKit';
512
513let currentIme = inputMethod.getCurrentInputMethod();
514let imSubType = inputMethod.getCurrentInputMethodSubtype();
515try {
516  inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err: BusinessError, result: boolean) => {
517    if (err) {
518      console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
519      return;
520    }
521    if (result) {
522      console.info('Succeeded in switching currentInputMethodAndSubtype.');
523    } else {
524      console.error('Failed to switchCurrentInputMethodAndSubtype.');
525    }
526  });
527} catch (err) {
528  console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
529}
530```
531
532> **NOTE**
533>
534> Since API version 11, the error code `201 permissions check fails` is removed.
535
536## inputMethod.switchCurrentInputMethodAndSubtype<sup>9+</sup>
537
538switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype): Promise&lt;boolean&gt;
539
540Switches to a specified subtype of a specified input method. This API uses a promise to return the result.
541
542> **NOTE**
543>
544>  - In API versions 9 and 10, this API can only be called by system applications granted the **ohos.permission.CONNECT_IME_ABILITY** permission.
545>  - Since API version 11, this API can only be called by the current input method application.
546
547**System capability**: SystemCapability.MiscServices.InputMethodFramework
548
549**Parameters**
550
551| Name| Type| Mandatory| Description|
552| -------- | -------- | -------- | -------- |
553|inputMethodProperty |  [InputMethodProperty](#inputmethodproperty8)| Yes| Target input method.|
554|inputMethodSubtype |  [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)| Yes| Target input method subtype.|
555
556**Return value**
557
558| Type                                     | Description                        |
559| ----------------------------------------- | ---------------------------- |
560| Promise\<boolean> | Promise used to return the result. The value **true** means that the switching is successful, and **false** means the opposite.|
561
562**Error codes**
563
564For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
565
566| ID| Error Message                            |
567| -------- | -------------------------------------- |
568| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
569| 12800005 | configuration persistence error.        |
570| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
571
572**Example**
573
574```ts
575import { BusinessError } from '@kit.BasicServicesKit';
576
577let currentIme = inputMethod.getCurrentInputMethod();
578let imSubType = inputMethod.getCurrentInputMethodSubtype();
579try {
580  inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType).then((result: boolean) => {
581    if (result) {
582      console.info('Succeeded in switching currentInputMethodAndSubtype.');
583    } else {
584      console.error('Failed to switchCurrentInputMethodAndSubtype.');
585    }
586  }).catch((err: BusinessError) => {
587    console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
588  })
589} catch(err) {
590  console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
591}
592```
593
594> **NOTE**
595>
596> Since API version 11, the error code `201 permissions check fails` is removed.
597
598## inputMethod.getInputMethodController<sup>(deprecated)</sup>
599
600getInputMethodController(): InputMethodController
601
602Obtains an [InputMethodController](#inputmethodcontroller) instance.
603
604> **NOTE**
605>
606> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getController()](#inputmethodgetcontroller9) instead.
607
608**System capability**: SystemCapability.MiscServices.InputMethodFramework
609
610**Return value**
611
612| Type                                           | Description                    |
613| ----------------------------------------------- | ------------------------ |
614| [InputMethodController](#inputmethodcontroller) | Current **InputMethodController** instance.|
615
616**Example**
617
618```ts
619let inputMethodController = inputMethod.getInputMethodController();
620```
621
622## inputMethod.getInputMethodSetting<sup>(deprecated)</sup>
623
624getInputMethodSetting(): InputMethodSetting
625
626Obtains an [InputMethodSetting](#inputmethodsetting8) instance.
627
628> **NOTE**
629>
630> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getSetting()](#inputmethodgetsetting9) instead.
631
632**System capability**: SystemCapability.MiscServices.InputMethodFramework
633
634**Return value**
635
636| Type                                     | Description                      |
637| ----------------------------------------- | -------------------------- |
638| [InputMethodSetting](#inputmethodsetting8) | **InputMethodSetting** instance.|
639
640**Example**
641
642```ts
643let inputMethodSetting = inputMethod.getInputMethodSetting();
644```
645
646## inputMethod.setSimpleKeyboardEnabled<sup>20+</sup>
647
648setSimpleKeyboardEnabled(enable: boolean): void
649
650Enables or disables the simple keyboard.
651
652**System capability**: SystemCapability.MiscServices.InputMethodFramework
653
654**Parameters**
655
656| Name| Type| Mandatory| Description|
657| -------- | -------- | -------- | -------- |
658| enable | boolean | Yes| Whether to enable the simple keyboard. The value **true** means that the simple keyboard is enabled; the value **false** means the opposite.<br> The native edit box takes effect when it is focused next time, while the self-drawing component takes effect when the input method is attached by calling [attach](#attach10) next time.|
659
660**Example**
661
662```ts
663  let enable = false;
664  inputMethod.setSimpleKeyboardEnabled(enable);
665```
666
667## TextInputType<sup>10+</sup>
668
669Enumerates the text input types.
670
671**System capability**: SystemCapability.MiscServices.InputMethodFramework
672
673| Name| Value|Description|
674| -------- | -------- |-------- |
675| NONE  | -1 |None.|
676| TEXT  | 0 |Text.|
677| MULTILINE  | 1 |Multi-line.|
678| NUMBER  | 2 |Number.|
679| PHONE  | 3 |Phone number.|
680| DATETIME  | 4 |Date.|
681| EMAIL_ADDRESS  | 5 |Email address.|
682| URL  | 6 |URL.|
683| VISIBLE_PASSWORD  | 7 |Password.|
684| NUMBER_PASSWORD<sup>11+</sup> | 8 |Numeric password.|
685| SCREEN_LOCK_PASSWORD<sup>20+</sup> | 9 |Lock screen password.|
686| USER_NAME<sup>20+</sup> | 10 |Username.|
687| NEW_PASSWORD<sup>20+</sup> | 11 |New password.|
688| NUMBER_DECIMAL<sup>20+</sup> | 12 |Number with a decimal point.|
689| ONE_TIME_CODE<sup>20+</sup> | 13 |Verification code.|
690
691## EnterKeyType<sup>10+</sup>
692
693Enumerates the function types represented by the Enter key of the input method.
694
695**System capability**: SystemCapability.MiscServices.InputMethodFramework
696
697| Name| Value|Description|
698| -------- | -------- |-------- |
699| UNSPECIFIED  | 0 |Not specified.|
700| NONE  | 1 |None.|
701| GO  | 2 |Go.|
702| SEARCH  | 3 |Search.|
703| SEND  | 4 |Send.|
704| NEXT  | 5 |Next.|
705| DONE  | 6 |Done.|
706| PREVIOUS  | 7 |Previous.|
707| NEWLINE<sup>12+</sup>  | 8 | Line break.|
708
709## KeyboardStatus<sup>10+</sup>
710
711Enumerates the soft keyboard states of the input method.
712
713**System capability**: SystemCapability.MiscServices.InputMethodFramework
714
715| Name| Value|Description|
716| -------- | -------- |-------- |
717| NONE  | 0 |None.|
718| HIDE  | 1 |Hidden.|
719| SHOW  | 2 |Shown.|
720
721## Direction<sup>10+</sup>
722
723Enumerates the directions of cursor movement of the input method.
724
725**System capability**: SystemCapability.MiscServices.InputMethodFramework
726
727| Name| Value|Description|
728| -------- | -------- |-------- |
729| CURSOR_UP  | 1 |Upward.|
730| CURSOR_DOWN  | 2 |Downward.|
731| CURSOR_LEFT  | 3 |Leftward.|
732| CURSOR_RIGHT  | 4 |Rightward.|
733
734## ExtendAction<sup>10+</sup>
735
736Describes the type of the extended edit action on the text box.
737
738**System capability**: SystemCapability.MiscServices.InputMethodFramework
739
740| Name| Value|Description|
741| -------- | -------- |-------- |
742| SELECT_ALL  | 0 |Select all.|
743| CUT  | 3 |Cut.|
744| COPY  | 4 |Copy.|
745| PASTE  | 5 |Paste.|
746
747## FunctionKey<sup>10+</sup>
748
749Describes the type of the input method function key.
750
751**System capability**: SystemCapability.MiscServices.InputMethodFramework
752
753| Name| Type| Read-only| Optional| Description|
754| -------- | -------- | -------- | -------- | -------- |
755| enterKeyType<sup>10+</sup>  | [EnterKeyType](#enterkeytype10) | No| No| Function type represented by the Enter key of the input method.|
756
757## InputAttribute<sup>10+</sup>
758
759Describes the attributes of the edit box, including the text input type and Enter key function type.
760
761**System capability**: SystemCapability.MiscServices.InputMethodFramework
762
763| Name| Type| Read-only| Optional| Description|
764| -------- | -------- | -------- | -------- | -------- |
765| textInputType<sup>10+</sup>  | [TextInputType](#textinputtype10) | No| No| Enumerates the text input types.|
766| enterKeyType<sup>10+</sup>  | [EnterKeyType](#enterkeytype10) | No| No| Function type represented by the Enter key.|
767| placeholder<sup>20+</sup> | string | No| Yes| Placeholder information set for the edit box.<br>- When placeholder information is set for the edit box, the length cannot exceed 255 characters (a placeholder longer than 255 characters will be automatically truncated to 255 characters). It is used to prompt or guide users to enter temporary text or symbols. (For example, the placeholder prompts whether the input item is mandatory.)<br>- If no placeholder is set for the edit box, the value is an empty string by default.<br>- This field is provided for the input method application when [attach](#attach10) is called.|
768| abilityName<sup>20+</sup> | string | No| Yes| Ability name set for the edit box.<br>- If the ability name is set for the edit box, the length cannot exceed 127 characters. (A name longer than 127 characters will be automatically truncated to 127 characters.)<br>- If the ability name is not set for the edit box, the value is an empty string by default.<br>- This field is provided for the input method application when [attach](#attach10) is called.|
769
770## TextConfig<sup>10+</sup>
771
772Describes the configuration of the edit box.
773
774**System capability**: SystemCapability.MiscServices.InputMethodFramework
775
776| Name| Type| Read-only| Optional| Description|
777| -------- | -------- | -------- | -------- | -------- |
778| inputAttribute<sup>10+</sup>  | [InputAttribute](#inputattribute10) | No| No| Edit box attribute.|
779| cursorInfo<sup>10+</sup>  | [CursorInfo](#cursorinfo10) | No| Yes| Cursor information.|
780| selection<sup>10+</sup>  | [Range](#range10) | No| Yes| Text selection range.|
781| windowId<sup>10+</sup>  | number | No| Yes| ID of the window where the edit box is located.|
782| newEditBox<sup>20+</sup> | boolean | No| Yes| Whether the edit box is new. The value **true** means the edit box is new; the value **false** means the opposite.|
783| capitalizeMode<sup>20+</sup> | [CapitalizeMode](#capitalizemode20) | No| Yes| Whether to capitalize the first letter in the edit box. If it is not set or is set to an invalid value, the first letter is not capitalized by default.|
784
785## CursorInfo<sup>10+</sup>
786
787Represents the cursor information.
788
789**System capability**: SystemCapability.MiscServices.InputMethodFramework
790
791| Name| Type| Read-only| Optional| Description|
792| -------- | -------- | -------- | -------- | -------- |
793| left  | number | No| No| Left coordinate of the cursor.|
794| top  | number | No| No| Top coordinate of the cursor.|
795| width  | number | No| No| Width of the cursor.|
796| height  | number | No| No| Height of the cursor.|
797
798## Range<sup>10+</sup>
799
800Describes the range of the selected text.
801
802**System capability**: SystemCapability.MiscServices.InputMethodFramework
803
804| Name| Type| Read-only| Optional| Description|
805| -------- | -------- | -------- | -------- | -------- |
806| start  | number | No| No| Index of the first selected character in the text box.|
807| end  | number | No| No| Index of the last selected character in the text box.|
808
809## Movement<sup>10+</sup>
810
811Describes the direction in which the cursor moves when the text is selected.
812
813**System capability**: SystemCapability.MiscServices.InputMethodFramework
814
815| Name| Type| Read-only| Optional| Description|
816| -------- | -------- | -------- | -------- | -------- |
817| direction  | [Direction](#direction10) | No| No| Direction in which the cursor moves when the text is selected.|
818
819## InputWindowInfo<sup>10+</sup>
820
821Describes the window information of the input method keyboard.
822
823**System capability**: SystemCapability.MiscServices.InputMethodFramework
824
825| Name| Type| Read-only| Optional| Description|
826| -------- | -------- | -------- | -------- | -------- |
827| name  | string | No| No| Name of the input method keyboard window.|
828| left  | number | No| No| Horizontal coordinate of the upper left corner of the input method keyboard window, in px.|
829| top  | number | No| No| Vertical coordinate of the upper left corner of the input method keyboard window, in px.|
830| width  | number | No| No| Width of the input method keyboard window, in px.|
831| height  | number | No| No| Height of the input method keyboard window, in px.|
832
833## EnabledState<sup>15+</sup>
834
835Indicates whether the input method is enabled.
836
837**System capability**: SystemCapability.MiscServices.InputMethodFramework
838
839| Name| Value|Description|
840| -------- | -------- |-------- |
841| DISABLED   | 0 |Disabled.|
842| BASIC_MODE  | 1 |Basic mode.|
843| FULL_EXPERIENCE_MODE  | 2 |Full experience mode.|
844
845## RequestKeyboardReason<sup>15+</sup>
846
847Describes the reason for keyboard request.
848
849**System capability**: SystemCapability.MiscServices.InputMethodFramework
850
851| Name| Value|Description|
852| -------- | -------- |-------- |
853| NONE   | 0 |The keyboard request is triggered for no reason.|
854| MOUSE  | 1 |The keyboard request is triggered by a mouse operation.|
855| TOUCH  | 2 |The keyboard request is triggered by a touch operation.|
856| OTHER  | 20 |The keyboard request is triggered by other reasons.|
857
858## MessageHandler<sup>15+</sup>
859
860Represents a custom communication object.
861
862> **NOTE**
863>
864> You can register this object to receive custom communication data sent by the input method application. When the custom communication data is received, the [onMessage](#onmessage15) callback in this object is triggered.
865>
866> This object is globally unique. After multiple registrations, only the last registered object is valid and retained, and the [onTerminated](#onterminated15) callback of the penultimate registered object is triggered.
867>
868> If this object is unregistered, its [onTerminated](#onterminated15) callback will be triggered.
869
870### onMessage<sup>15+</sup>
871
872onMessage(msgId: string, msgParam?: ArrayBuffer): void
873
874Receives custom data sent by the input method application.
875
876> **NOTE**
877>
878> This callback is triggered when the registered MeesageHandler receives custom communication data sent by the input method application.
879>
880> The **msgId** parameter is mandatory, and the **msgParam** parameter is optional. If only the custom **msgId** data is received, confirm it with the data sender.
881
882**System capability**: SystemCapability.MiscServices.InputMethodFramework
883
884**Parameters**
885
886| Name  | Type       | Mandatory| Description                            |
887| -------- | ----------- | ---- | -------------------------------- |
888| msgId    | string      | Yes  | Identifier of the received custom communication data.|
889| msgParam | ArrayBuffer | No  | Message body of the received custom communication data.|
890
891**Example**
892
893```ts
894import { BusinessError } from '@kit.BasicServicesKit';
895
896let inputMethodController = inputMethod.getController();
897try {
898    let messageHandler: inputMethod.MessageHandler = {
899        onTerminated(): void {
900            console.info('OnTerminated.');
901        },
902        onMessage(msgId: string, msgParam?:ArrayBuffer): void {
903            console.info('recv message.');
904        }
905    }
906    inputMethodController.recvMessage(messageHandler);
907} catch(err) {
908  console.error(`Failed to recvMessage: ${JSON.stringify(err)}`);
909}
910```
911
912### onTerminated<sup>15+</sup>
913
914onTerminated(): void
915
916Listens for MessageHandler termination.
917
918> **NOTE**
919>
920> When an application registers a new MessageHandler object, the **OnTerminated** callback of the previous registered MessageHandler object is triggered.
921>
922> When an application unregisters a MessageHandler object, the **OnTerminated** callback of the current registered MessageHandler object is triggered.
923
924**System capability**: SystemCapability.MiscServices.InputMethodFramework
925
926**Example**
927
928```ts
929import { BusinessError } from '@kit.BasicServicesKit';
930
931let inputMethodController = inputMethod.getController();
932try {
933    let messageHandler: inputMethod.MessageHandler = {
934        onTerminated(): void {
935            console.info('OnTerminated.');
936        },
937        onMessage(msgId: string, msgParam?:ArrayBuffer): void {
938            console.info('recv message.');
939        }
940    }
941    inputMethodController.recvMessage(messageHandler);
942} catch(err) {
943  console.error(`Failed to recvMessage: ${JSON.stringify(err)}`);
944}
945```
946
947## SetPreviewTextCallback<sup>17+</sup>
948
949type SetPreviewTextCallback = (text: string, range: Range) => void
950
951Callback triggered when the input method framework needs to display the text preview.
952
953**System capability**: SystemCapability.MiscServices.InputMethodFramework
954
955| Name      | Type         | Mandatory| Description                         |
956| ------- | ----------------- | ---- | ----------------------------- |
957| text    | string            | Yes  | Text preview.                |
958| range   | [Range](#range10) | Yes  | Describes the range of the selected text.|
959
960## InputMethodController
961
962In the following API examples, you must first use [getController](#inputmethodgetcontroller9) to obtain an **InputMethodController** instance, and then call the APIs using the obtained instance.
963
964### attach<sup>10+</sup>
965
966attach(showKeyboard: boolean, textConfig: TextConfig, callback: AsyncCallback&lt;void&gt;): void
967
968Attaches a self-drawing component to the input method. This API uses an asynchronous callback to return the result.
969
970> **NOTE**
971>
972> An input method can use the following features only when it has a self-drawing component attached to it: showing or hiding the keyboard, updating the cursor information, changing the selection range of the edit box, saving the configuration information, and listening for and processing the information or commands sent by the input method.
973
974**System capability**: SystemCapability.MiscServices.InputMethodFramework
975
976**Parameters**
977
978| Name| Type| Mandatory| Description|
979| -------- | -------- | -------- | -------- |
980| showKeyboard | boolean | Yes| Whether to start the input method keyboard after the self-drawing component is attached to the input method.<br>- **true** means to start the input method keyboard.<br>- **false** means not to start the input method keyboard.|
981| textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the edit box.|
982| 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.|
983
984**Error codes**
985
986For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
987
988| ID| Error Message                            |
989| -------- | -------------------------------------- |
990| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
991| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
992| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
993
994**Example**
995
996```ts
997import { BusinessError } from '@kit.BasicServicesKit';
998
999try {
1000  let textConfig: inputMethod.TextConfig = {
1001    inputAttribute: {
1002      textInputType: 0,
1003      enterKeyType: 1
1004    }
1005  };
1006  inputMethodController.attach(true, textConfig, (err: BusinessError) => {
1007    if (err) {
1008      console.error(`Failed to attach: ${JSON.stringify(err)}`);
1009      return;
1010    }
1011    console.info('Succeeded in attaching the inputMethod.');
1012  });
1013} catch(err) {
1014  console.error(`Failed to attach: ${JSON.stringify(err)}`);
1015}
1016```
1017
1018### attach<sup>10+</sup>
1019
1020attach(showKeyboard: boolean, textConfig: TextConfig): Promise&lt;void&gt;
1021
1022Attaches a self-drawing component to the input method. This API uses a promise to return the result.
1023
1024> **NOTE**
1025>
1026> An input method can use the following features only when it has a self-drawing component attached to it: showing or hiding the keyboard, updating the cursor information, changing the selection range of the edit box, saving the configuration information, and listening for and processing the information or commands sent by the input method.
1027
1028**System capability**: SystemCapability.MiscServices.InputMethodFramework
1029
1030**Parameters**
1031
1032| Name| Type| Mandatory| Description|
1033| -------- | -------- | -------- | -------- |
1034| showKeyboard | boolean | Yes| Whether to start the input method keyboard after the self-drawing component is attached to the input method.<br>- **true** means to start the input method keyboard.<br>- **false** means not to start the input method keyboard.|
1035| textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the edit box.|
1036
1037**Return value**
1038
1039| Type| Description|
1040| -------- | -------- |
1041| Promise&lt;void&gt; | Promise that returns no value.|
1042
1043**Error codes**
1044
1045For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1046
1047| ID| Error Message                            |
1048| -------- | -------------------------------------- |
1049| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1050| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1051| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1052
1053**Example**
1054
1055```ts
1056import { BusinessError } from '@kit.BasicServicesKit';
1057
1058try {
1059  let textConfig: inputMethod.TextConfig = {
1060    inputAttribute: {
1061      textInputType: 0,
1062      enterKeyType: 1
1063    }
1064  };
1065  inputMethodController.attach(true, textConfig).then(() => {
1066    console.info('Succeeded in attaching inputMethod.');
1067  }).catch((err: BusinessError) => {
1068    console.error(`Failed to attach: ${JSON.stringify(err)}`);
1069  })
1070} catch(err) {
1071  console.error(`Failed to attach: ${JSON.stringify(err)}`);
1072}
1073```
1074
1075### attach<sup>15+</sup>
1076
1077attach(showKeyboard: boolean, textConfig: TextConfig, requestKeyboardReason: RequestKeyboardReason): Promise&lt;void&gt;
1078
1079Attaches a self-drawing component to the input method. This API uses a promise to return the result.
1080
1081> **NOTE**
1082>
1083> An input method can use the following features only when it has a self-drawing component attached to it: showing or hiding the keyboard, updating the cursor information, changing the selection range of the edit box, saving the configuration information, and listening for and processing the information or commands sent by the input method.
1084
1085**System capability**: SystemCapability.MiscServices.InputMethodFramework
1086
1087**Parameters**
1088
1089| Name| Type| Mandatory| Description|
1090| -------- | -------- | -------- | -------- |
1091| showKeyboard | boolean | Yes| Whether to start the input method keyboard after the self-drawing component is attached to the input method.<br>- **true** means to start the input method keyboard.<br>- **false** means not to start the input method keyboard.|
1092| textConfig | [TextConfig](#textconfig10) | Yes| Configuration of the edit box.|
1093| requestKeyboardReason | [RequestKeyboardReason](#requestkeyboardreason15) | Yes| Reason for keyboard request.|
1094
1095**Return value**
1096
1097| Type| Description|
1098| -------- | -------- |
1099| Promise&lt;void&gt; | Promise that returns no value.|
1100
1101**Error codes**
1102
1103For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1104
1105| ID| Error Message                            |
1106| -------- | -------------------------------------- |
1107| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1108| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1109| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1110
1111**Example**
1112
1113```ts
1114import { BusinessError } from '@kit.BasicServicesKit';
1115
1116try {
1117  let textConfig: inputMethod.TextConfig = {
1118    inputAttribute: {
1119      textInputType: 0,
1120      enterKeyType: 1
1121    }
1122  };
1123
1124  let requestKeyboardReason: inputMethod.RequestKeyboardReason = inputMethod.RequestKeyboardReason.MOUSE;
1125
1126  inputMethodController.attach(true, textConfig, requestKeyboardReason).then(() => {
1127    console.info('Succeeded in attaching inputMethod.');
1128  }).catch((err: BusinessError) => {
1129    console.error(`Failed to attach: ${JSON.stringify(err)}`);
1130  })
1131} catch(err) {
1132  console.error(`Failed to attach: ${JSON.stringify(err)}`);
1133}
1134```
1135
1136### discardTypingText<sup>20+</sup>
1137
1138discardTypingText(): Promise&lt;void&gt;
1139
1140Discards the text that is being typed. This API uses a promise to return the result.
1141
1142> **NOTE**
1143>
1144> This API can be called after the edit box is attached to an input method.
1145
1146**System capability**: SystemCapability.MiscServices.InputMethodFramework
1147
1148**Return value**
1149
1150| Type| Description|
1151| -------- | -------- |
1152| Promise&lt;void&gt; | Promise used to return the result. Promise that returns no value.|
1153
1154**Error codes**
1155
1156For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1157
1158| ID| Error Message                            |
1159| -------- | -------------------------------------- |
1160| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1161| 12800009 | input method client detached. |
1162| 12800015 | the other side does not accept the request. |
1163
1164**Example**
1165
1166```ts
1167import { BusinessError } from '@kit.BasicServicesKit';
1168import { inputMethod } from '@kit.IMEKit';
1169
1170inputMethod.getController().discardTypingText().then(() => {
1171  console.info('Succeeded discardTypingText.');
1172}).catch((err: BusinessError) => {
1173  console.error(`Failed to discardTypingText errCode:${err.code}, errMsg:${err.message}`);
1174});
1175```
1176
1177### showTextInput<sup>10+</sup>
1178
1179showTextInput(callback: AsyncCallback&lt;void&gt;): void
1180
1181Enters the text editing mode. This API uses an asynchronous callback to return the result.
1182
1183> **NOTE**
1184>
1185> After the edit box is attached to an input method, this API can be called to start the soft keyboard and enter the text editing state.
1186
1187**System capability**: SystemCapability.MiscServices.InputMethodFramework
1188
1189**Parameters**
1190
1191| Name| Type| Mandatory| Description|
1192| -------- | -------- | -------- | -------- |
1193| 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.|
1194
1195**Error codes**
1196
1197For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1198
1199| ID| Error Message                            |
1200| -------- | -------------------------------------- |
1201| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1202| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1203| 12800009 | input method client detached. |
1204
1205**Example**
1206
1207```ts
1208import { BusinessError } from '@kit.BasicServicesKit';
1209
1210inputMethodController.showTextInput((err: BusinessError) => {
1211  if (err) {
1212    console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
1213    return;
1214  }
1215  console.info('Succeeded in showing the inputMethod.');
1216});
1217```
1218
1219### showTextInput<sup>10+</sup>
1220
1221showTextInput(): Promise&lt;void&gt;
1222
1223Enters the text editing mode. This API uses a promise to return the result.
1224
1225> **NOTE**
1226>
1227> After the edit box is attached to an input method, this API can be called to start the soft keyboard and enter the text editing state.
1228
1229**System capability**: SystemCapability.MiscServices.InputMethodFramework
1230
1231**Return value**
1232
1233| Type| Description|
1234| -------- | -------- |
1235| Promise&lt;void&gt; | Promise that returns no value.|
1236
1237**Error codes**
1238
1239For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1240
1241| ID| Error Message                            |
1242| -------- | -------------------------------------- |
1243| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1244| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1245| 12800009 | input method client detached. |
1246
1247**Example**
1248
1249```ts
1250import { BusinessError } from '@kit.BasicServicesKit';
1251
1252inputMethodController.showTextInput().then(() => {
1253  console.info('Succeeded in showing text input.');
1254}).catch((err: BusinessError) => {
1255  console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
1256});
1257```
1258
1259### showTextInput<sup>15+</sup>
1260
1261showTextInput(requestKeyboardReason: RequestKeyboardReason): Promise&lt;void&gt;
1262
1263Enters the text editing mode. This API uses a promise to return the result.
1264
1265> **NOTE**
1266>
1267> After the edit box is attached to an input method, this API can be called to start the soft keyboard and enter the text editing state.
1268
1269**System capability**: SystemCapability.MiscServices.InputMethodFramework
1270
1271**Parameters**
1272
1273| Name| Type| Mandatory| Description|
1274| -------- | -------- | -------- | -------- |
1275| requestKeyboardReason | [RequestKeyboardReason](#requestkeyboardreason15) | Yes| Reason for keyboard request.|
1276
1277**Return value**
1278
1279| Type| Description|
1280| -------- | -------- |
1281| Promise&lt;void&gt; | Promise that returns no value.|
1282
1283**Error codes**
1284
1285For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1286
1287| ID| Error Message                            |
1288| -------- | -------------------------------------- |
1289| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1290| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1291| 12800009 | input method client detached. |
1292
1293**Example**
1294
1295```ts
1296import { BusinessError } from '@kit.BasicServicesKit';
1297
1298let requestKeyboardReason = inputMethod.RequestKeyboardReason.MOUSE;
1299
1300inputMethodController.showTextInput(requestKeyboardReason).then(() => {
1301  console.info('Succeeded in showing text input.');
1302}).catch((err: BusinessError) => {
1303  console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
1304});
1305```
1306
1307### hideTextInput<sup>10+</sup>
1308
1309hideTextInput(callback: AsyncCallback&lt;void&gt;): void
1310
1311Exits the text editing mode. This API uses an asynchronous callback to return the result.
1312
1313> **NOTE**
1314>
1315> If the soft keyboard is displayed when this API is called, it will be hidden.
1316>
1317> Calling this API does not detach the edit box from the input method. The edit box can call [showTextInput](#showtextinput10) again to reenter the text editing mode.
1318
1319**System capability**: SystemCapability.MiscServices.InputMethodFramework
1320
1321**Parameters**
1322
1323| Name| Type| Mandatory| Description|
1324| -------- | -------- | -------- | -------- |
1325| 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.|
1326
1327**Error codes**
1328
1329For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1330
1331| ID| Error Message                            |
1332| -------- | -------------------------------------- |
1333| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1334| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1335| 12800009 | input method client detached.             |
1336
1337**Example**
1338
1339```ts
1340import { BusinessError } from '@kit.BasicServicesKit';
1341
1342inputMethodController.hideTextInput((err: BusinessError) => {
1343  if (err) {
1344    console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
1345    return;
1346  }
1347  console.info('Succeeded in hiding text input.');
1348});
1349```
1350
1351### hideTextInput<sup>10+</sup>
1352
1353hideTextInput(): Promise&lt;void&gt;
1354
1355Exits the text editing mode. This API uses a promise to return the result.
1356
1357> **NOTE**
1358>
1359> If the soft keyboard is displayed when this API is called, it will be hidden.
1360>
1361> Calling this API does not detach the edit box from the input method. The edit box can call [showTextInput](#showtextinput10) again to reenter the text editing mode.
1362
1363**System capability**: SystemCapability.MiscServices.InputMethodFramework
1364
1365**Return value**
1366
1367| Type| Description|
1368| -------- | -------- |
1369| Promise&lt;void&gt; | Promise that returns no value.|
1370
1371**Error codes**
1372
1373For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1374
1375| ID| Error Message                            |
1376| -------- | -------------------------------------- |
1377| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1378| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1379| 12800009 | input method client detached. |
1380
1381**Example**
1382
1383```ts
1384import { BusinessError } from '@kit.BasicServicesKit';
1385
1386inputMethodController.hideTextInput().then(() => {
1387  console.info('Succeeded in hiding inputMethod.');
1388}).catch((err: BusinessError) => {
1389  console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
1390})
1391```
1392
1393### detach<sup>10+</sup>
1394
1395detach(callback: AsyncCallback&lt;void&gt;): void
1396
1397Detaches the self-drawing component from the input method. This API uses an asynchronous callback to return the result.
1398
1399**System capability**: SystemCapability.MiscServices.InputMethodFramework
1400
1401**Parameters**
1402
1403| Name| Type| Mandatory| Description|
1404| -------- | -------- | -------- | -------- |
1405| 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.|
1406
1407**Error codes**
1408
1409For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1410
1411| ID| Error Message                            |
1412| -------- | -------------------------------------- |
1413| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1414| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1415
1416**Example**
1417
1418```ts
1419import { BusinessError } from '@kit.BasicServicesKit';
1420
1421inputMethodController.detach((err: BusinessError) => {
1422  if (err) {
1423    console.error(`Failed to detach: ${JSON.stringify(err)}`);
1424    return;
1425  }
1426  console.info('Succeeded in detaching inputMethod.');
1427});
1428```
1429
1430### detach<sup>10+</sup>
1431
1432detach(): Promise&lt;void&gt;
1433
1434Detaches the self-drawing component from the input method. This API uses a promise to return the result.
1435
1436**System capability**: SystemCapability.MiscServices.InputMethodFramework
1437
1438**Return value**
1439
1440| Type| Description|
1441| -------- | -------- |
1442| Promise&lt;void&gt; | Promise that returns no value.|
1443
1444**Error codes**
1445
1446For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1447
1448| ID| Error Message                            |
1449| -------- | -------------------------------------- |
1450| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1451| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1452
1453**Example**
1454
1455```ts
1456import { BusinessError } from '@kit.BasicServicesKit';
1457
1458inputMethodController.detach().then(() => {
1459  console.info('Succeeded in detaching inputMethod.');
1460}).catch((err: BusinessError) => {
1461  console.error(`Failed to detach: ${JSON.stringify(err)}`);
1462});
1463```
1464
1465### setCallingWindow<sup>10+</sup>
1466
1467setCallingWindow(windowId: number, callback: AsyncCallback&lt;void&gt;): void
1468
1469Sets the window to be avoided by the input method. This API uses an asynchronous callback to return the result.
1470
1471> **NOTE**
1472>
1473> After the window ID of the application bound to the input method is passed in the API, the input method window will not cover the window holding the application.
1474
1475**System capability**: SystemCapability.MiscServices.InputMethodFramework
1476
1477**Parameters**
1478
1479| Name| Type| Mandatory| Description|
1480| -------- | -------- | -------- | -------- |
1481| windowId | number | Yes| Window ID of the application bound to the input method.|
1482| 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.|
1483
1484**Error codes**
1485
1486For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1487
1488| ID| Error Message                            |
1489| -------- | -------------------------------------- |
1490| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1491| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1492| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1493| 12800009 | input method client detached.             |
1494
1495**Example**
1496
1497```ts
1498import { BusinessError } from '@kit.BasicServicesKit';
1499
1500try {
1501  let windowId: number = 2000;
1502  inputMethodController.setCallingWindow(windowId, (err: BusinessError) => {
1503    if (err) {
1504      console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1505      return;
1506    }
1507    console.info('Succeeded in setting callingWindow.');
1508  });
1509} catch(err) {
1510  console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1511}
1512```
1513
1514### setCallingWindow<sup>10+</sup>
1515
1516setCallingWindow(windowId: number): Promise&lt;void&gt;
1517
1518Sets the window to be avoided by the input method. This API uses a promise to return the result.
1519
1520> **NOTE**
1521>
1522> After the window ID of the application bound to the input method is passed in the API, the input method window will not cover the window holding the application.
1523
1524**System capability**: SystemCapability.MiscServices.InputMethodFramework
1525
1526**Parameters**
1527
1528| Name| Type| Mandatory| Description|
1529| -------- | -------- | -------- | -------- |
1530| windowId | number | Yes| Window ID of the application bound to the input method.|
1531
1532**Return value**
1533
1534| Type| Description|
1535| -------- | -------- |
1536| Promise&lt;void&gt; | Promise that returns no value.|
1537
1538**Error codes**
1539
1540For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1541
1542| ID| Error Message                            |
1543| -------- | -------------------------------------- |
1544| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1545| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1546| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1547| 12800009 | input method client detached. |
1548
1549**Example**
1550
1551```ts
1552import { BusinessError } from '@kit.BasicServicesKit';
1553
1554try {
1555  let windowId: number = 2000;
1556  inputMethodController.setCallingWindow(windowId).then(() => {
1557    console.info('Succeeded in setting callingWindow.');
1558  }).catch((err: BusinessError) => {
1559    console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1560  })
1561} catch(err) {
1562  console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
1563}
1564```
1565
1566### updateCursor<sup>10+</sup>
1567
1568updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback&lt;void&gt;): void
1569
1570Updates the cursor information in this edit box. This API can be called to notify the input method of the cursor changes. This API uses an asynchronous callback to return the result.
1571
1572**System capability**: SystemCapability.MiscServices.InputMethodFramework
1573
1574**Parameters**
1575
1576| Name| Type| Mandatory| Description|
1577| -------- | -------- | -------- | -------- |
1578| cursorInfo | [CursorInfo](#cursorinfo10) | Yes| Cursor information.|
1579| 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.|
1580
1581**Error codes**
1582
1583For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1584
1585| ID| Error Message                            |
1586| -------- | -------------------------------------- |
1587| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1588| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1589| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1590| 12800009 | input method client detached.             |
1591
1592**Example**
1593
1594```ts
1595import { BusinessError } from '@kit.BasicServicesKit';
1596
1597try {
1598  let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 };
1599  inputMethodController.updateCursor(cursorInfo, (err: BusinessError) => {
1600    if (err) {
1601      console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1602      return;
1603    }
1604    console.info('Succeeded in updating cursorInfo.');
1605  });
1606} catch(err) {
1607  console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1608}
1609```
1610
1611### updateCursor<sup>10+</sup>
1612
1613updateCursor(cursorInfo: CursorInfo): Promise&lt;void&gt;
1614
1615Updates the cursor information in this edit box. This API can be called to notify the input method of the cursor changes. This API uses a promise to return the result.
1616
1617**System capability**: SystemCapability.MiscServices.InputMethodFramework
1618
1619**Parameters**
1620
1621| Name| Type| Mandatory| Description|
1622| -------- | -------- | -------- | -------- |
1623| cursorInfo | [CursorInfo](#cursorinfo10) | Yes| Cursor information.|
1624
1625**Return value**
1626
1627| Type| Description|
1628| -------- | -------- |
1629| Promise&lt;void&gt; | Promise that returns no value.|
1630
1631**Error codes**
1632
1633For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1634
1635| ID| Error Message                            |
1636| -------- | -------------------------------------- |
1637| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
1638| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1639| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1640| 12800009 | input method client detached. |
1641
1642**Example**
1643
1644```ts
1645import { BusinessError } from '@kit.BasicServicesKit';
1646
1647try {
1648  let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 };
1649  inputMethodController.updateCursor(cursorInfo).then(() => {
1650    console.info('Succeeded in updating cursorInfo.');
1651  }).catch((err: BusinessError) => {
1652    console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1653  })
1654} catch(err) {
1655  console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
1656}
1657```
1658
1659### changeSelection<sup>10+</sup>
1660
1661changeSelection(text: string, start: number, end: number, callback: AsyncCallback&lt;void&gt;): void
1662
1663Updates the information about the selected text in this edit box, to notify the input method when the selected text content or text range changes. This API uses an asynchronous callback to return the result.
1664
1665**System capability**: SystemCapability.MiscServices.InputMethodFramework
1666
1667**Parameters**
1668
1669| Name| Type| Mandatory| Description|
1670| -------- | -------- | -------- | -------- |
1671| text | string | Yes| All input text.|
1672| start | number | Yes| Start position of the selected text.|
1673| end | number | Yes| End position of the selected text.|
1674| 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.|
1675
1676**Error codes**
1677
1678For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1679
1680| ID| Error Message                            |
1681| -------- | -------------------------------------- |
1682| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1683| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1684| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1685| 12800009 | input method client detached.             |
1686
1687**Example**
1688
1689```ts
1690import { BusinessError } from '@kit.BasicServicesKit';
1691
1692try {
1693  inputMethodController.changeSelection('text', 0, 5, (err: BusinessError) => {
1694    if (err) {
1695      console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1696      return;
1697    }
1698    console.info('Succeeded in changing selection.');
1699  });
1700} catch(err) {
1701  console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1702}
1703```
1704
1705### changeSelection<sup>10+</sup>
1706
1707changeSelection(text: string, start: number, end: number): Promise&lt;void&gt;
1708
1709Updates the information about the selected text in this edit box, to notify the input method when the selected text content or text range changes. This API uses a promise to return the result.
1710
1711**System capability**: SystemCapability.MiscServices.InputMethodFramework
1712
1713**Parameters**
1714
1715| Name| Type| Mandatory| Description|
1716| -------- | -------- | -------- | -------- |
1717| text | string | Yes| All input text.|
1718| start | number | Yes| Start position of the selected text.|
1719| end | number | Yes| End position of the selected text.|
1720
1721**Return value**
1722
1723| Type| Description|
1724| -------- | -------- |
1725| Promise&lt;void&gt; | Promise that returns no value.|
1726
1727**Error codes**
1728
1729For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1730
1731| ID| Error Message                            |
1732| -------- | -------------------------------------- |
1733| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1734| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1735| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1736| 12800009 | input method client detached. |
1737
1738**Example**
1739
1740```ts
1741import { BusinessError } from '@kit.BasicServicesKit';
1742
1743try {
1744  inputMethodController.changeSelection('test', 0, 5).then(() => {
1745    console.info('Succeeded in changing selection.');
1746  }).catch((err: BusinessError) => {
1747    console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1748  })
1749} catch(err) {
1750  console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
1751}
1752```
1753
1754### updateAttribute<sup>10+</sup>
1755
1756updateAttribute(attribute: InputAttribute, callback: AsyncCallback&lt;void&gt;): void
1757
1758Updates the attribute information of this edit box. This API uses an asynchronous callback to return the result.
1759
1760**System capability**: SystemCapability.MiscServices.InputMethodFramework
1761
1762**Parameters**
1763
1764| Name| Type| Mandatory| Description|
1765| -------- | -------- | -------- | -------- |
1766| attribute | [InputAttribute](#inputattribute10) | Yes| Attribute information.|
1767| 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.|
1768
1769**Error codes**
1770
1771For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1772
1773| ID| Error Message                            |
1774| -------- | -------------------------------------- |
1775| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1776| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1777| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1778| 12800009 | input method client detached.             |
1779
1780**Example**
1781
1782```ts
1783import { BusinessError } from '@kit.BasicServicesKit';
1784
1785try {
1786  let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 };
1787  inputMethodController.updateAttribute(inputAttribute, (err: BusinessError) => {
1788    if (err) {
1789      console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1790      return;
1791    }
1792    console.info('Succeeded in updating attribute.');
1793  });
1794} catch(err) {
1795  console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1796}
1797```
1798
1799### updateAttribute<sup>10+</sup>
1800
1801updateAttribute(attribute: InputAttribute): Promise&lt;void&gt;
1802
1803Updates the attribute information of this edit box. This API uses a promise to return the result.
1804
1805**System capability**: SystemCapability.MiscServices.InputMethodFramework
1806
1807**Parameters**
1808
1809| Name| Type| Mandatory| Description|
1810| -------- | -------- | -------- | -------- |
1811| attribute | [InputAttribute](#inputattribute10) | Yes|  Attribute information.|
1812
1813**Return value**
1814
1815| Type| Description|
1816| -------- | -------- |
1817| Promise&lt;void&gt; | Promise that returns no value.|
1818
1819**Error codes**
1820
1821For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1822
1823| ID| Error Message                            |
1824| -------- | -------------------------------------- |
1825| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
1826| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1827| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1828| 12800009 | input method client detached. |
1829
1830**Example**
1831
1832```ts
1833import { BusinessError } from '@kit.BasicServicesKit';
1834
1835try {
1836  let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 };
1837  inputMethodController.updateAttribute(inputAttribute).then(() => {
1838    console.info('Succeeded in updating attribute.');
1839  }).catch((err: BusinessError) => {
1840    console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1841  })
1842} catch(err) {
1843  console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
1844}
1845```
1846
1847### stopInputSession<sup>9+</sup>
1848
1849stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void
1850
1851Ends this input session. This API uses an asynchronous callback to return the result.
1852
1853> **NOTE**
1854>
1855> This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused.
1856
1857**System capability**: SystemCapability.MiscServices.InputMethodFramework
1858
1859**Parameters**
1860
1861| Name| Type| Mandatory| Description|
1862| -------- | -------- | -------- | -------- |
1863| 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.|
1864
1865**Error codes**
1866
1867For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1868
1869| ID| Error Message                            |
1870| -------- | -------------------------------------- |
1871| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1872| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1873
1874**Example**
1875
1876```ts
1877import { BusinessError } from '@kit.BasicServicesKit';
1878
1879try {
1880  inputMethodController.stopInputSession((err: BusinessError, result: boolean) => {
1881    if (err) {
1882      console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1883      return;
1884    }
1885    if (result) {
1886      console.info('Succeeded in stopping inputSession.');
1887    } else {
1888      console.error('Failed to stopInputSession.');
1889    }
1890  });
1891} catch(err) {
1892  console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1893}
1894```
1895
1896### stopInputSession<sup>9+</sup>
1897
1898stopInputSession(): Promise&lt;boolean&gt;
1899
1900Ends this input session. This API uses a promise to return the result.
1901
1902> **NOTE**
1903>
1904> This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused.
1905
1906**System capability**: SystemCapability.MiscServices.InputMethodFramework
1907
1908**Return value**
1909
1910| Type| Description|
1911| -------- | -------- |
1912| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.|
1913
1914**Error codes**
1915
1916For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
1917
1918| ID| Error Message                            |
1919| -------- | -------------------------------------- |
1920| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1921| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1922
1923**Example**
1924
1925```ts
1926import { BusinessError } from '@kit.BasicServicesKit';
1927
1928try {
1929  inputMethodController.stopInputSession().then((result: boolean) => {
1930    if (result) {
1931      console.info('Succeeded in stopping inputSession.');
1932    } else {
1933      console.error('Failed to stopInputSession.');
1934    }
1935  }).catch((err: BusinessError) => {
1936    console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1937  })
1938} catch(err) {
1939  console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
1940}
1941```
1942
1943### showSoftKeyboard<sup>9+</sup>
1944
1945showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
1946
1947Shows the soft keyboard. This API uses an asynchronous callback to return the result.
1948
1949> **NOTE**
1950>
1951> This API can be called only when the edit box is attached to the input method. That is, it can be called to show the soft keyboard only when the edit box is focused.
1952
1953**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only)
1954
1955**System capability**: SystemCapability.MiscServices.InputMethodFramework
1956
1957**Parameters**
1958
1959| Name  | Type                 | Mandatory| Description      |
1960| -------- | ------------------------- | ---- | ---------- |
1961| 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.|
1962
1963**Error codes**
1964
1965For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
1966
1967| ID| Error Message                            |
1968| -------- | -------------------------------------- |
1969| 201      | permissions check fails.  |
1970| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
1971| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
1972
1973**Example**
1974
1975```ts
1976import { BusinessError } from '@kit.BasicServicesKit';
1977
1978inputMethodController.showSoftKeyboard((err: BusinessError) => {
1979  if (!err) {
1980    console.info('Succeeded in showing softKeyboard.');
1981  } else {
1982    console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`);
1983  }
1984})
1985```
1986
1987### showSoftKeyboard<sup>9+</sup>
1988
1989showSoftKeyboard(): Promise&lt;void&gt;
1990
1991Shows the soft keyboard. This API uses a promise to return the result.
1992
1993> **NOTE**
1994>
1995> This API can be called only when the edit box is attached to the input method. That is, it can be called to show the soft keyboard only when the edit box is focused.
1996
1997**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only)
1998
1999**System capability**: SystemCapability.MiscServices.InputMethodFramework
2000
2001**Return value**
2002
2003| Type               | Description                     |
2004| ------------------- | ------------------------- |
2005| Promise&lt;void&gt; | Promise that returns no value.|
2006
2007**Error codes**
2008
2009For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2010
2011| ID| Error Message                            |
2012| -------- | -------------------------------------- |
2013| 201      | permissions check fails.  |
2014| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
2015| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
2016
2017**Example**
2018
2019```ts
2020import { BusinessError } from '@kit.BasicServicesKit';
2021
2022inputMethodController.showSoftKeyboard().then(() => {
2023  console.info('Succeeded in showing softKeyboard.');
2024}).catch((err: BusinessError) => {
2025  console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`);
2026});
2027```
2028
2029### hideSoftKeyboard<sup>9+</sup>
2030
2031hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
2032
2033Hides the soft keyboard. This API uses an asynchronous callback to return the result.
2034
2035> **NOTE**
2036>
2037> This API can be called only when the edit box is attached to the input method. That is, it can be called to hide the soft keyboard only when the edit box is focused.
2038
2039**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only)
2040
2041**System capability**: SystemCapability.MiscServices.InputMethodFramework
2042
2043**Parameters**
2044
2045| Name  | Type                 | Mandatory| Description      |
2046| -------- | ------------------------- | ---- | ---------- |
2047| 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.|
2048
2049**Error codes**
2050
2051For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2052
2053| ID| Error Message                            |
2054| -------- | -------------------------------------- |
2055| 201      | permissions check fails.  |
2056| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
2057| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
2058
2059**Example**
2060
2061```ts
2062import { BusinessError } from '@kit.BasicServicesKit';
2063
2064inputMethodController.hideSoftKeyboard((err: BusinessError) => {
2065  if (!err) {
2066    console.info('Succeeded in hiding softKeyboard.');
2067  } else {
2068    console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`);
2069  }
2070})
2071```
2072
2073### hideSoftKeyboard<sup>9+</sup>
2074
2075hideSoftKeyboard(): Promise&lt;void&gt;
2076
2077Hides the soft keyboard. This API uses a promise to return the result.
2078
2079> **NOTE**
2080>
2081> This API can be called only when the edit box is attached to the input method. That is, it can be called to hide the soft keyboard only when the edit box is focused.
2082
2083**Required permissions**: ohos.permission.CONNECT_IME_ABILITY (for system applications only)
2084
2085**System capability**: SystemCapability.MiscServices.InputMethodFramework
2086
2087**Return value**
2088
2089| Type               | Description                     |
2090| ------------------- | ------------------------- |
2091| Promise&lt;void&gt; | Promise that returns no value.|
2092
2093**Error codes**
2094
2095For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2096
2097| ID| Error Message                            |
2098| -------- | -------------------------------------- |
2099| 201      | permissions check fails.  |
2100| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
2101| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
2102
2103**Example**
2104
2105```ts
2106import { BusinessError } from '@kit.BasicServicesKit';
2107
2108inputMethodController.hideSoftKeyboard().then(() => {
2109  console.info('Succeeded in hiding softKeyboard.');
2110}).catch((err: BusinessError) => {
2111  console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`);
2112});
2113```
2114
2115### sendMessage<sup>15+</sup>
2116
2117sendMessage(msgId: string, msgParam?: ArrayBuffer): Promise<void&gt;
2118
2119Sends the custom communication to the input method application. This API uses a promise to return the result.
2120
2121> **NOTE**
2122>
2123> This API can be called only when the edit box is attached to the input method and enter the edit mode, and the input method application is in full experience mode.
2124>
2125> The maximum length of **msgId** is 256 B, and the maximum length of **msgParam** is 128 KB.
2126
2127**System capability**: SystemCapability.MiscServices.InputMethodFramework
2128
2129**Parameters**
2130
2131| Name  | Type       | Mandatory| Description                                      |
2132| -------- | ----------- | ---- | ------------------------------------------ |
2133| msgId    | string      | Yes  | Identifier of the custom data to be sent to the input method application.|
2134| msgParam | ArrayBuffer | No  | Message body of the custom data to be sent to the input method application.|
2135
2136**Return value**
2137
2138| Type               | Description                     |
2139| ------------------- | ------------------------- |
2140| Promise&lt;void&gt; | Promise that returns no value.|
2141
2142**Error codes**
2143
2144For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2145
2146| ID| Error Message                                   |
2147| -------- | ------------------------------------------- |
2148| 401      | parameter error. Possible causes: 1. Incorrect parameter types. 2. Incorrect parameter length.  |
2149| 12800003 | input method client error. Possible causes: 1.the edit box is not focused. 2.no edit box is bound to current input method application. |
2150| 12800009 | input method client detached.               |
2151| 12800014 | the input method is in basic mode.          |
2152| 12800015 | the other side does not accept the request. |
2153| 12800016 | input method client is not editable.        |
2154
2155**Example**
2156
2157```ts
2158import { BusinessError } from '@kit.BasicServicesKit';
2159
2160let msgId: string = "testMsgId";
2161let msgParam: ArrayBuffer = new ArrayBuffer(128);
2162inputMethodController.sendMessage(msgId, msgParam).then(() => {
2163  console.info('Succeeded send message.');
2164}).catch((err: BusinessError) => {
2165  console.error(`Failed to send message: ${JSON.stringify(err)}`);
2166});
2167```
2168
2169### recvMessage<sup>15+</sup>
2170
2171recvMessage(msgHandler?: MessageHandler): void
2172
2173Registers or unregisters MessageHandler.
2174
2175> **NOTE**
2176>
2177> The [MessageHandler](#messagehandler15) object is globally unique. After multiple registrations, only the last registered object is valid and retained, and the [onTerminated](#onterminated15) callback of the penultimate registered object is triggered.
2178>
2179> If no parameter is set, unregister [MessageHandler](#messagehandler15). Its [onTerminated](#onterminated15) callback will be triggered.
2180
2181**System capability**: SystemCapability.MiscServices.InputMethodFramework
2182
2183**Parameters**
2184
2185| Name    | Type                               | Mandatory| Description                                                        |
2186| ---------- | ----------------------------------- | ---- | ------------------------------------------------------------ |
2187| msgHandler | [MessageHandler](#messagehandler15) | No  | This object receives custom communication data from the input method application through [onMessage](#onmessage15) and receives a message for terminating the subscription to this object through [onTerminated](#onterminated15).<br>If no parameter is set, unregister [MessageHandler](#messagehandler15). Its [onTerminated](#onterminated15) callback will be triggered.|
2188
2189**Error codes**
2190
2191For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2192
2193| ID| Error Message        |
2194| -------- | ---------------- |
2195| 401      | parameter error. Possible causes: 1. Incorrect parameter types. |
2196
2197**Example**
2198
2199```ts
2200import { BusinessError } from '@kit.BasicServicesKit';
2201let messageHandler: inputMethod.MessageHandler = {
2202    onTerminated(): void {
2203        console.info('OnTerminated.');
2204    },
2205    onMessage(msgId: string, msgParam?:ArrayBuffer): void {
2206        console.info('recv message.');
2207    }
2208}
2209inputMethodController.recvMessage(messageHandler);
2210inputMethodController.recvMessage();
2211```
2212
2213### stopInput<sup>(deprecated)</sup>
2214
2215stopInput(callback: AsyncCallback&lt;boolean&gt;): void
2216
2217Ends this input session. This API uses an asynchronous callback to return the result.
2218
2219> **NOTE**
2220>
2221> This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused.
2222>
2223> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9) instead.
2224
2225**System capability**: SystemCapability.MiscServices.InputMethodFramework
2226
2227**Parameters**
2228
2229| Name| Type| Mandatory| Description|
2230| -------- | -------- | -------- | -------- |
2231| 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.|
2232
2233**Example**
2234
2235```ts
2236import { BusinessError } from '@kit.BasicServicesKit';
2237
2238inputMethodController.stopInput((err: BusinessError, result: boolean) => {
2239  if (err) {
2240    console.error(`Failed to stopInput: ${JSON.stringify(err)}`);
2241    return;
2242  }
2243  if (result) {
2244    console.info('Succeeded in stopping input.');
2245  } else {
2246    console.error('Failed to stopInput.');
2247  }
2248});
2249```
2250
2251### stopInput<sup>(deprecated)</sup>
2252
2253stopInput(): Promise&lt;boolean&gt;
2254
2255Ends this input session. This API uses a promise to return the result.
2256
2257> **NOTE**
2258>
2259> This API can be called only when the edit box is attached to the input method. That is, it can be called to end the input session only when the edit box is focused.
2260>
2261> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [stopInputSession()](#stopinputsession9) instead.
2262
2263**System capability**: SystemCapability.MiscServices.InputMethodFramework
2264
2265**Return value**
2266
2267| Type| Description|
2268| -------- | -------- |
2269| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.|
2270
2271**Example**
2272
2273```ts
2274import { BusinessError } from '@kit.BasicServicesKit';
2275
2276inputMethodController.stopInput().then((result: boolean) => {
2277  if (result) {
2278    console.info('Succeeded in stopping input.');
2279  } else {
2280    console.error('Failed to stopInput.');
2281  }
2282}).catch((err: BusinessError) => {
2283  console.error(`Failed to stopInput: ${JSON.stringify(err)}`);
2284})
2285```
2286
2287### on('insertText')<sup>10+</sup>
2288
2289on(type: 'insertText', callback: (text: string) => void): void
2290
2291Enables listening for the text insertion event of the input method. This API uses an asynchronous callback to return the result.
2292
2293**System capability**: SystemCapability.MiscServices.InputMethodFramework
2294
2295**Parameters**
2296
2297| Name  | Type                                                        | Mandatory| Description                                                        |
2298| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2299| type     | string                                                       | Yes  | Listening type. The value is fixed at **'insertText'**.|
2300| callback | (text: string) => void | Yes  | Callback used to return the text to be inserted.<br>The application needs to operate the content in the edit box based on the text content returned in the callback.|
2301
2302**Error codes**
2303
2304For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2305
2306| ID| Error Message                            |
2307| -------- | -------------------------------------- |
2308| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2309| 12800009 | input method client detached. |
2310
2311**Example**
2312
2313```ts
2314function callback1(text: string) {
2315  console.info('Succeeded in getting callback1 data: ' + JSON.stringify(text));
2316}
2317
2318function callback2(text: string) {
2319  console.info('Succeeded in getting callback2 data: ' + JSON.stringify(text));
2320}
2321
2322try {
2323  inputMethodController.on('insertText', callback1);
2324  inputMethodController.on('insertText', callback2);
2325  // Cancel only callback1 of insertText.
2326  inputMethodController.off('insertText', callback1);
2327  // Cancel all callbacks of insertText.
2328  inputMethodController.off('insertText');
2329} catch(err) {
2330  console.error(`Failed to subscribe insertText: ${JSON.stringify(err)}`);
2331}
2332```
2333
2334### off('insertText')<sup>10+</sup>
2335
2336off(type: 'insertText', callback?: (text: string) => void): void
2337
2338Disables listening for the text insertion event of the input method.
2339
2340**System capability**: SystemCapability.MiscServices.InputMethodFramework
2341
2342**Parameters**
2343
2344| Name  | Type                  | Mandatory| Description                                                        |
2345| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
2346| type     | string                 | Yes  | Listening type. The value is fixed at **'insertText'**.|
2347| callback | (text: string) => void | No  | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2348
2349**Example**
2350
2351```ts
2352let onInsertTextCallback = (text: string) => {
2353    console.info(`Succeeded in subscribing insertText: ${text}`);
2354};
2355inputMethodController.off('insertText', onInsertTextCallback);
2356inputMethodController.off('insertText');
2357```
2358
2359### on('deleteLeft')<sup>10+</sup>
2360
2361on(type: 'deleteLeft', callback: (length: number) => void): void
2362
2363Enables listening for the leftward delete event. This API uses an asynchronous callback to return the result.
2364
2365**System capability**: SystemCapability.MiscServices.InputMethodFramework
2366
2367**Parameters**
2368
2369| Name  | Type| Mandatory| Description|
2370| -------- | ----- | ---- | ----- |
2371| type     | string  | Yes  | Listening type. The value is fixed at **'deleteLeft'**.|
2372| callback | (length: number) => void | Yes  | Callback used to return the length of the text to be deleted leftward.<br>The application needs to operate the content in the edit box based on the length returned in the callback.|
2373
2374**Error codes**
2375
2376For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2377
2378| ID| Error Message                            |
2379| -------- | -------------------------------------- |
2380| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2381| 12800009 | input method client detached. |
2382
2383**Example**
2384
2385```ts
2386try {
2387  inputMethodController.on('deleteLeft', (length: number) => {
2388    console.info(`Succeeded in subscribing deleteLeft, length: ${length}`);
2389  });
2390} catch(err) {
2391  console.error(`Failed to subscribe deleteLeft: ${JSON.stringify(err)}`);
2392}
2393```
2394
2395### off('deleteLeft')<sup>10+</sup>
2396
2397off(type: 'deleteLeft', callback?: (length: number) => void): void
2398
2399Disables listening for the leftward delete event.
2400
2401**System capability**: SystemCapability.MiscServices.InputMethodFramework
2402
2403**Parameters**
2404
2405| Name  | Type                    | Mandatory| Description                                                        |
2406| -------- | ------------------------ | ---- | ------------------------------------------------------------ |
2407| type     | string                   | Yes  | Listening type. The value is fixed at **'deleteLeft'**.|
2408| callback | (length: number) => void | No  | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2409
2410**Example**
2411
2412```ts
2413let onDeleteLeftCallback = (length: number) => {
2414    console.info(`Succeeded in subscribing deleteLeft, length: ${length}`);
2415};
2416inputMethodController.off('deleteLeft', onDeleteLeftCallback);
2417inputMethodController.off('deleteLeft');
2418```
2419
2420### on('deleteRight')<sup>10+</sup>
2421
2422on(type: 'deleteRight', callback: (length: number) => void): void
2423
2424Enables listening for the rightward delete event. This API uses an asynchronous callback to return the result.
2425
2426**System capability**: SystemCapability.MiscServices.InputMethodFramework
2427
2428**Parameters**
2429
2430| Name  | Type| Mandatory| Description|
2431| -------- | ----- | ---- | ----- |
2432| type     | string  | Yes  | Listening type. The value is fixed at **'deleteRight'**.|
2433| callback | (length: number) => void | Yes  | Callback used to return the length of the text to be deleted rightward.<br>The application needs to operate the content in the edit box based on the length returned in the callback.|
2434
2435**Error codes**
2436
2437For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2438
2439| ID| Error Message                            |
2440| -------- | -------------------------------------- |
2441| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2442| 12800009 | input method client detached. |
2443
2444**Example**
2445
2446```ts
2447try {
2448  inputMethodController.on('deleteRight', (length: number) => {
2449    console.info(`Succeeded in subscribing deleteRight, length: ${length}`);
2450  });
2451} catch(err) {
2452  console.error(`Failed to subscribe deleteRight: ${JSON.stringify(err)}`);
2453}
2454```
2455
2456### off('deleteRight')<sup>10+</sup>
2457
2458off(type: 'deleteRight', callback?: (length: number) => void): void
2459
2460Disables listening for the rightward delete event.
2461
2462**System capability**: SystemCapability.MiscServices.InputMethodFramework
2463
2464**Parameters**
2465
2466| Name  | Type                    | Mandatory| Description                                                        |
2467| -------- | ------------------------ | ---- | ------------------------------------------------------------ |
2468| type     | string                   | Yes  | Listening type. The value is fixed at `deleteRight`.|
2469| callback | (length: number) => void | No  | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2470
2471**Example**
2472
2473```ts
2474let onDeleteRightCallback = (length: number) => {
2475    console.info(`Succeeded in subscribing deleteRight, length: ${length}`);
2476};
2477inputMethodController.off('deleteRight', onDeleteRightCallback);
2478inputMethodController.off('deleteRight');
2479```
2480
2481### on('sendKeyboardStatus')<sup>10+</sup>
2482
2483on(type: 'sendKeyboardStatus', callback: (keyboardStatus: KeyboardStatus) => void): void
2484
2485Enables listening for the soft keyboard status event of the input method. This API uses an asynchronous callback to return the result.
2486
2487**System capability**: SystemCapability.MiscServices.InputMethodFramework
2488
2489**Parameters**
2490
2491| Name  | Type | Mandatory| Description   |
2492| -------- | ------ | ---- | ---- |
2493| type     | string  | Yes  | Listening type. The value is fixed at **'sendKeyboardStatus'**.|
2494| callback | (keyboardStatus: [KeyboardStatus](#keyboardstatus10)) => void | Yes  | Callback used to return the soft keyboard status.<br>The application needs to perform operations based on the soft keyboard state returned in the callback.|
2495
2496**Error codes**
2497
2498For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2499
2500| ID| Error Message                            |
2501| -------- | -------------------------------------- |
2502| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2503| 12800009 | input method client detached. |
2504
2505**Example**
2506
2507```ts
2508try {
2509  inputMethodController.on('sendKeyboardStatus', (keyboardStatus: inputMethod.KeyboardStatus) => {
2510    console.info(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`);
2511  });
2512} catch(err) {
2513  console.error(`Failed to subscribe sendKeyboardStatus: ${JSON.stringify(err)}`);
2514}
2515```
2516
2517### off('sendKeyboardStatus')<sup>10+</sup>
2518
2519off(type: 'sendKeyboardStatus', callback?: (keyboardStatus: KeyboardStatus) => void): void
2520
2521Disables listening for the soft keyboard status event of the input method.
2522
2523**System capability**: SystemCapability.MiscServices.InputMethodFramework
2524
2525**Parameters**
2526
2527| Name  | Type                                                        | Mandatory| Description                                                        |
2528| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2529| type     | string                                                       | Yes  | Listening type. The value is fixed at **'sendKeyboardStatus'**.|
2530| callback | (keyboardStatus: [KeyboardStatus](#keyboardstatus10)) => void | No  | Callback used for disable listening. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2531
2532**Example**
2533
2534```ts
2535let onSendKeyboardStatus = (keyboardStatus: inputMethod.KeyboardStatus) => {
2536    console.info(`Succeeded in subscribing sendKeyboardStatus, keyboardStatus: ${keyboardStatus}`);
2537};
2538inputMethodController.off('sendKeyboardStatus', onSendKeyboardStatus);
2539inputMethodController.off('sendKeyboardStatus');
2540```
2541
2542### on('sendFunctionKey')<sup>10+</sup>
2543
2544on(type: 'sendFunctionKey', callback: (functionKey: FunctionKey) => void): void
2545
2546Enables listening for the function key sending event of the input method. This API uses an asynchronous callback to return the result.
2547
2548**System capability**: SystemCapability.MiscServices.InputMethodFramework
2549
2550**Parameters**
2551
2552| Name  | Type | Mandatory| Description    |
2553| -------- | -------- | ---- | ----- |
2554| type     | string  | Yes  | Listening type. The value is fixed at **'sendFunctionKey'**.|
2555| callback | (functionKey: [FunctionKey](#functionkey10)) => void | Yes  | Callback used to return the function key information sent by the input method.<br>The application needs to perform operations based on the function key information returned in the callback.|
2556
2557**Error codes**
2558
2559For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2560
2561| ID| Error Message                            |
2562| -------- | -------------------------------------- |
2563| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2564| 12800009 | input method client detached. |
2565
2566**Example**
2567
2568```ts
2569try {
2570  inputMethodController.on('sendFunctionKey', (functionKey: inputMethod.FunctionKey) => {
2571    console.info(`Succeeded in subscribing sendFunctionKey, functionKey.enterKeyType: ${functionKey.enterKeyType}`);
2572  });
2573} catch(err) {
2574  console.error(`Failed to subscribe sendFunctionKey: ${JSON.stringify(err)}`);
2575}
2576```
2577
2578### off('sendFunctionKey')<sup>10+</sup>
2579
2580off(type: 'sendFunctionKey', callback?: (functionKey: FunctionKey) => void): void
2581
2582Disables listening for the function key sending event of the input method.
2583
2584**System capability**: SystemCapability.MiscServices.InputMethodFramework
2585
2586**Parameters**
2587
2588| Name  | Type                                                | Mandatory| Description                                                        |
2589| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
2590| type     | string                                               | Yes  | Listening type. The value is fixed at **'sendFunctionKey'**.|
2591| callback | (functionKey: [FunctionKey](#functionkey10)) => void | No  | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2592
2593**Example**
2594
2595```ts
2596let onSendFunctionKey = (functionKey: inputMethod.FunctionKey) => {
2597    console.info(`Succeeded in subscribing sendFunctionKey, functionKey: ${functionKey.enterKeyType}`);
2598};
2599inputMethodController.off('sendFunctionKey', onSendFunctionKey);
2600inputMethodController.off('sendFunctionKey');
2601```
2602
2603### on('moveCursor')<sup>10+</sup>
2604
2605on(type: 'moveCursor', callback: (direction: Direction) => void): void
2606
2607Enables listening for the cursor movement event of the input method. This API uses an asynchronous callback to return the result.
2608
2609**System capability**: SystemCapability.MiscServices.InputMethodFramework
2610
2611**Parameters**
2612
2613| Name  | Type| Mandatory| Description  |
2614| -------- | ------ | ---- | ------ |
2615| type     | string | Yes  | Listening type. The value is fixed at **'moveCursor'**.|
2616| callback | (direction: [Direction](#direction10)) => void | Yes  | Callback used to return the cursor movement direction.<br>The application needs to change the cursor position based on the cursor movement direction returned in the callback. |
2617
2618**Error codes**
2619
2620For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2621
2622| ID| Error Message                          |
2623| -------- | -------------------------------- |
2624| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2625| 12800009 | input method client detached. |
2626
2627**Example**
2628
2629```ts
2630try {
2631  inputMethodController.on('moveCursor', (direction: inputMethod.Direction) => {
2632    console.info(`Succeeded in subscribing moveCursor, direction: ${direction}`);
2633  });
2634} catch(err) {
2635  console.error(`Failed to subscribe moveCursor: ${JSON.stringify(err)}`);
2636}
2637```
2638
2639### off('moveCursor')<sup>10+</sup>
2640
2641off(type: 'moveCursor', callback?: (direction: Direction) => void): void
2642
2643Disables listening for the cursor movement event of the input method.
2644
2645**System capability**: SystemCapability.MiscServices.InputMethodFramework
2646
2647**Parameters**
2648
2649| Name | Type   | Mandatory| Description |
2650| ------ | ------ | ---- | ---- |
2651| type   | string | Yes  | Listening type. The value is fixed at **'moveCursor'**.|
2652| callback | (direction: [Direction<sup>10+</sup>](#direction10)) => void | No| Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2653
2654**Example**
2655
2656```ts
2657let onMoveCursorCallback = (direction: inputMethod.Direction) => {
2658    console.info(`Succeeded in subscribing moveCursor, direction: ${direction}`);
2659};
2660inputMethodController.off('moveCursor', onMoveCursorCallback);
2661inputMethodController.off('moveCursor');
2662```
2663
2664### on('handleExtendAction')<sup>10+</sup>
2665
2666on(type: 'handleExtendAction', callback: (action: ExtendAction) => void): void
2667
2668Enables listening for the extended action handling event of the input method. This API uses an asynchronous callback to return the result.
2669
2670**System capability**: SystemCapability.MiscServices.InputMethodFramework
2671
2672**Parameters**
2673
2674| Name  | Type | Mandatory| Description  |
2675| -------- | ------ | ---- | -------- |
2676| type     | string    | Yes  | Listening type. The value is fixed at **'handleExtendAction'**.|
2677| callback | (action: [ExtendAction](#extendaction10)) => void | Yes  | Callback used to return the extended action type.<br>The application needs to perform operations based on the extended action type returned in the callback.|
2678
2679**Error codes**
2680
2681For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2682
2683| ID| Error Message                            |
2684| -------- | -------------------------------------- |
2685| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2686| 12800009 | input method client detached. |
2687
2688**Example**
2689
2690```ts
2691try {
2692  inputMethodController.on('handleExtendAction', (action: inputMethod.ExtendAction) => {
2693    console.info(`Succeeded in subscribing handleExtendAction, action: ${action}`);
2694  });
2695} catch(err) {
2696  console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`);
2697}
2698```
2699
2700### off('handleExtendAction')<sup>10+</sup>
2701
2702off(type: 'handleExtendAction', callback?: (action: ExtendAction) => void): void
2703
2704Disables listening for the extended action handling event of the input method. This API uses an asynchronous callback to return the result.
2705
2706**System capability**: SystemCapability.MiscServices.InputMethodFramework
2707
2708**Parameters**
2709
2710| Name| Type  | Mandatory| Description |
2711| ------ | ------ | ---- | ------- |
2712| type   | string | Yes  | Listening type. The value is fixed at **'handleExtendAction'**.|
2713| callback | (action: [ExtendAction](#extendaction10)) => void | No| Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2714
2715**Example**
2716
2717```ts
2718try {
2719  let onHandleExtendActionCallback = (action: inputMethod.ExtendAction) => {
2720    console.info(`Succeeded in subscribing handleExtendAction, action: ${action}`);
2721  };
2722  inputMethodController.off('handleExtendAction', onHandleExtendActionCallback);
2723  inputMethodController.off('handleExtendAction');
2724} catch(err) {
2725  console.error(`Failed to subscribe handleExtendAction: ${JSON.stringify(err)}`);
2726}
2727```
2728
2729### on('selectByRange')<sup>10+</sup>
2730
2731on(type: 'selectByRange', callback: Callback&lt;Range&gt;): void
2732
2733Enables listening for the select-by-range event. This API uses an asynchronous callback to return the result.
2734
2735**System capability**: SystemCapability.MiscServices.InputMethodFramework
2736
2737**Parameters**
2738
2739| Name  | Type    | Mandatory| Description    |
2740| -------- | ---- | ---- | ------- |
2741| type     | string  | Yes  | Listening type. The value is fixed at **'selectByRange'**.|
2742| callback | Callback&lt;[Range](#range10)&gt; | Yes  | Callback used to return the range of the text to be selected.<br>The application needs to select the text based on the range returned in the callback.|
2743
2744**Error codes**
2745
2746For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2747
2748| ID| Error Message                                               |
2749| -------- | ------------------------------------------------------- |
2750| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2751
2752**Example**
2753
2754```ts
2755try {
2756  inputMethodController.on('selectByRange', (range: inputMethod.Range) => {
2757    console.info(`Succeeded in subscribing selectByRange: start: ${range.start} , end: ${range.end}`);
2758  });
2759} catch(err) {
2760  console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`);
2761}
2762```
2763
2764### off('selectByRange')<sup>10+</sup>
2765
2766off(type: 'selectByRange', callback?:  Callback&lt;Range&gt;): void
2767
2768Disables listening for the select-by-range event. This API uses an asynchronous callback to return the result.
2769
2770**System capability**: SystemCapability.MiscServices.InputMethodFramework
2771
2772**Parameters**
2773
2774| Name  | Type                             | Mandatory| Description                                                        |
2775| -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
2776| type     | string                            | Yes  | Listening type. The value is fixed at **'selectByRange'**.|
2777| callback | Callback&lt;[Range](#range10)&gt; | No  | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2778
2779**Example**
2780
2781```ts
2782try {
2783  let onSelectByRangeCallback = (range: inputMethod.Range) => {
2784    console.info(`Succeeded in subscribing selectByRange, start: ${range.start} , end: ${range.end}`);
2785  };
2786  inputMethodController.off('selectByRange', onSelectByRangeCallback);
2787  inputMethodController.off('selectByRange');
2788} catch(err) {
2789  console.error(`Failed to subscribe selectByRange: ${JSON.stringify(err)}`);
2790}
2791```
2792
2793### on('selectByMovement')<sup>10+</sup>
2794
2795on(type: 'selectByMovement', callback: Callback&lt;Movement&gt;): void
2796
2797Enables listening for the select-by-cursor-movement event. This API uses an asynchronous callback to return the result.
2798
2799**System capability**: SystemCapability.MiscServices.InputMethodFramework
2800
2801**Parameters**
2802
2803| Name  | Type  | Mandatory| Description    |
2804| -------- | ----- | ---- | ------ |
2805| type     | string  | Yes  | Listening type. The value is fixed at **'selectByMovement'**.|
2806| callback | Callback&lt;[Movement](#movement10)&gt; | Yes  | Callback used to return the direction in which the cursor moves.<br>The application needs to select the text based on the direction returned in the callback.|
2807
2808**Error codes**
2809
2810For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2811
2812| ID| Error Message                                               |
2813| -------- | ------------------------------------------------------- |
2814| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2815
2816**Example**
2817
2818```ts
2819try {
2820  inputMethodController.on('selectByMovement', (movement: inputMethod.Movement) => {
2821    console.info('Succeeded in subscribing selectByMovement: direction: ' + movement.direction);
2822  });
2823} catch(err) {
2824  console.error(`Failed to subscribe selectByMovement: ${JSON.stringify(err)}`);
2825}
2826```
2827
2828### off('selectByMovement')<sup>10+</sup>
2829
2830off(type: 'selectByMovement', callback?: Callback&lt;Movement&gt;): void
2831
2832Disables listening for the select-by-cursor-movement event. This API uses an asynchronous callback to return the result.
2833
2834**System capability**: SystemCapability.MiscServices.InputMethodFramework
2835
2836**Parameters**
2837
2838| Name  | Type                                | Mandatory| Description                                                        |
2839| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
2840| type     | string                               | Yes  | Listening type. The value is fixed at **'selectByMovement'**.|
2841| callback | Callback&lt;[Movement](#movement10)> | No  | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2842
2843**Example**
2844
2845```ts
2846try {
2847  let onSelectByMovementCallback = (movement: inputMethod.Movement) => {
2848    console.info(`Succeeded in subscribing selectByMovement, movement.direction: ${movement.direction}`);
2849  };
2850  inputMethodController.off('selectByMovement', onSelectByMovementCallback);
2851  inputMethodController.off('selectByMovement');
2852} catch(err) {
2853  console.error(`Failed to unsubscribing selectByMovement: ${JSON.stringify(err)}`);
2854}
2855```
2856
2857### on('getLeftTextOfCursor')<sup>10+</sup>
2858
2859on(type: 'getLeftTextOfCursor', callback: (length: number) => string): void
2860
2861Enables listening for the event of obtaining the length of text deleted leftward. This API uses an asynchronous callback to return the result.
2862
2863**System capability**: SystemCapability.MiscServices.InputMethodFramework
2864
2865**Parameters**
2866
2867| Name  | Type  | Mandatory| Description    |
2868| -------- | ----- | ---- | ------ |
2869| type     | string  | Yes  | Listening type. The value is fixed at **'getLeftTextOfCursor'**.|
2870| callback | (length: number) => string | Yes  | Callback used to obtain the text of the specified length deleted leftward.|
2871
2872**Error codes**
2873
2874For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2875
2876| ID| Error Message                            |
2877| -------- | -------------------------------------- |
2878| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2879| 12800009 | input method client detached. |
2880
2881**Example**
2882
2883```ts
2884try {
2885  inputMethodController.on('getLeftTextOfCursor', (length: number) => {
2886    console.info(`Succeeded in subscribing getLeftTextOfCursor, length: ${length}`);
2887    let text:string = "";
2888    return text;
2889  });
2890} catch(err) {
2891  console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`);
2892}
2893```
2894
2895### off('getLeftTextOfCursor')<sup>10+</sup>
2896
2897off(type: 'getLeftTextOfCursor', callback?: (length: number) => string): void
2898
2899Disables listening for the event of obtaining the length of text deleted leftward. This API uses an asynchronous callback to return the result.
2900
2901**System capability**: SystemCapability.MiscServices.InputMethodFramework
2902
2903**Parameters**
2904
2905| Name| Type  | Mandatory| Description                                                        |
2906| ------ | ------ | ---- | ------------------------------------------------------------ |
2907| type   | string | Yes  | Listening type. The value is fixed at **'getLeftTextOfCursor'**.|
2908| callback | (length: number) => string | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2909
2910**Example**
2911
2912```ts
2913try {
2914  let getLeftTextOfCursorCallback = (length: number) => {
2915    console.info(`Succeeded in unsubscribing getLeftTextOfCursor, length: ${length}`);
2916    let text:string = "";
2917    return text;
2918  };
2919  inputMethodController.off('getLeftTextOfCursor', getLeftTextOfCursorCallback);
2920  inputMethodController.off('getLeftTextOfCursor');
2921} catch(err) {
2922  console.error(`Failed to unsubscribing getLeftTextOfCursor. err: ${JSON.stringify(err)}`);
2923}
2924```
2925
2926### on('getRightTextOfCursor')<sup>10+</sup>
2927
2928on(type: 'getRightTextOfCursor', callback: (length: number) => string): void
2929
2930Enables listening for the event of obtaining the length of text deleted rightward. This API uses an asynchronous callback to return the result.
2931
2932**System capability**: SystemCapability.MiscServices.InputMethodFramework
2933
2934**Parameters**
2935
2936| Name  | Type  | Mandatory| Description    |
2937| -------- | ----- | ---- | ------ |
2938| type     | string  | Yes  | Listening type. The value is fixed at **'getRightTextOfCursor'**.|
2939| callback | (length: number) => string | Yes  | Callback used to obtain the text of the specified length deleted rightward.|
2940
2941**Error codes**
2942
2943For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
2944
2945| ID| Error Message                            |
2946| -------- | -------------------------------------- |
2947| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
2948| 12800009 | input method client detached. |
2949
2950**Example**
2951
2952```ts
2953try {
2954  inputMethodController.on('getRightTextOfCursor', (length: number) => {
2955    console.info(`Succeeded in subscribing getRightTextOfCursor, length: ${length}`);
2956    let text:string = "";
2957    return text;
2958  });
2959} catch(err) {
2960  console.error(`Failed to subscribe getRightTextOfCursor. err: ${JSON.stringify(err)}`);
2961}
2962```
2963
2964### off('getRightTextOfCursor')<sup>10+</sup>
2965
2966off(type: 'getRightTextOfCursor', callback?: (length: number) => string): void
2967
2968Disables listening for the event of obtaining the length of text deleted rightward. This API uses an asynchronous callback to return the result.
2969
2970**System capability**: SystemCapability.MiscServices.InputMethodFramework
2971
2972**Parameters**
2973
2974| Name| Type  | Mandatory| Description                                                        |
2975| ------ | ------ | ---- | ------------------------------------------------------------ |
2976| type   | string | Yes  | Listening type. The value is fixed at **'getRightTextOfCursor'**.|
2977| callback | (length: number) => string | No |Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
2978
2979**Example**
2980
2981```ts
2982try {
2983  let getRightTextOfCursorCallback = (length: number) => {
2984    console.info(`Succeeded in unsubscribing getRightTextOfCursor, length: ${length}`);
2985    let text:string = "";
2986    return text;
2987  };
2988  inputMethodController.off('getRightTextOfCursor', getRightTextOfCursorCallback);
2989  inputMethodController.off('getRightTextOfCursor');
2990} catch(err) {
2991  console.error(`Failed to unsubscribing getRightTextOfCursor. err: ${JSON.stringify(err)}`);
2992}
2993```
2994
2995### on('getTextIndexAtCursor')<sup>10+</sup>
2996
2997on(type: 'getTextIndexAtCursor', callback: () => number): void
2998
2999Enables listening for the event of obtaining the index of text at the cursor. This API uses an asynchronous callback to return the result.
3000
3001**System capability**: SystemCapability.MiscServices.InputMethodFramework
3002
3003**Parameters**
3004
3005| Name  | Type  | Mandatory| Description    |
3006| -------- | ----- | ---- | ------ |
3007| type     | string  | Yes  | Listening type. The value is fixed at **'getTextIndexAtCursor'**.|
3008| callback | () => number | Yes  | Callback used to obtain the index of text at the cursor.|
3009
3010**Error codes**
3011
3012For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3013
3014| ID| Error Message                            |
3015| -------- | -------------------------------------- |
3016| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3017| 12800009 | input method client detached. |
3018
3019**Example**
3020
3021```ts
3022try {
3023  inputMethodController.on('getTextIndexAtCursor', () => {
3024    console.info(`Succeeded in subscribing getTextIndexAtCursor.`);
3025    let index:number = 0;
3026    return index;
3027  });
3028} catch(err) {
3029  console.error(`Failed to subscribe getTextIndexAtCursor. err: ${JSON.stringify(err)}`);
3030}
3031```
3032
3033### off('getTextIndexAtCursor')<sup>10+</sup>
3034
3035off(type: 'getTextIndexAtCursor', callback?: () => number): void
3036
3037Disables listening for the event of obtaining the index of text at the cursor. This API uses an asynchronous callback to return the result.
3038
3039**System capability**: SystemCapability.MiscServices.InputMethodFramework
3040
3041**Parameters**
3042
3043| Name| Type  | Mandatory| Description                                                        |
3044| ------ | ------ | ---- | ------------------------------------------------------------ |
3045| type   | string | Yes  | Listening type. The value is fixed at **'getTextIndexAtCursor'**.|
3046| callback | () => number | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
3047
3048**Example**
3049
3050```ts
3051try {
3052  let getTextIndexAtCursorCallback = () => {
3053    console.info(`Succeeded in unsubscribing getTextIndexAtCursor.`);
3054    let index:number = 0;
3055    return index;
3056  };
3057  inputMethodController.off('getTextIndexAtCursor', getTextIndexAtCursorCallback);
3058  inputMethodController.off('getTextIndexAtCursor');
3059} catch(err) {
3060  console.error(`Failed to unsubscribing getTextIndexAtCursor. err: ${JSON.stringify(err)}`);
3061}
3062```
3063
3064### on('setPreviewText')<sup>17+</sup>
3065
3066on(type: 'setPreviewText', callback: SetPreviewTextCallback): void
3067
3068Subscribes to the event for text preview operations in an input method application. This API uses an asynchronous callback to return the result.
3069
3070> **NOTE**
3071>
3072> To use the text preview function, you need to subscribe to this event before calling [attach](#attach10) and subscribe to this event together with [on('finishTextPreview')](#onfinishtextpreview17).
3073
3074**System capability**: SystemCapability.MiscServices.InputMethodFramework
3075
3076**Parameters**
3077
3078| Name  | Type  | Mandatory| Description    |
3079| -------- | ----- | ---- | ------ |
3080| type     | string  | Yes  | Event type, which is **'setPreviewText'**.|
3081| callback | [SetPreviewTextCallback](#setpreviewtextcallback17) | Yes  | Callback used to return the result. It is used to receive and return the text preview.|
3082
3083**Error codes**
3084
3085For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3086
3087| ID| Error Message                            |
3088| -------- | -------------------------------------- |
3089| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3090
3091**Example**
3092
3093```ts
3094let setPreviewTextCallback1: inputMethod.SetPreviewTextCallback = (text: string, range: inputMethod.Range) => {
3095  console.info(`SetPreviewTextCallback1: Received text - ${text}, Received range - start: ${range.start}, end: ${range.end}`);
3096};
3097
3098let setPreviewTextCallback2: inputMethod.SetPreviewTextCallback = (text: string, range: inputMethod.Range) => {
3099  console.info(`setPreviewTextCallback2: Received text - ${text}, Received range - start: ${range.start}, end: ${range.end}`);
3100};
3101
3102try {
3103  inputMethodController.on('setPreviewText', setPreviewTextCallback1);
3104  console.info(`SetPreviewTextCallback1 subscribed to setPreviewText`);
3105  inputMethodController.on('setPreviewText', setPreviewTextCallback2);
3106  console.info(`SetPreviewTextCallback2 subscribed to setPreviewText`);
3107  // Cancel only the callback1 of setPreviewText.
3108  inputMethodController.off('setPreviewText', setPreviewTextCallback1);
3109  console.info(`SetPreviewTextCallback1 unsubscribed from setPreviewText`);
3110  // Cancel all callbacks of setPreviewText.
3111  inputMethodController.off('setPreviewText');
3112  console.info(`All callbacks unsubscribed from setPreviewText`);
3113} catch(err) {
3114  console.error(`Failed to operate on setPreviewText: ${JSON.stringify(err)}`);
3115}
3116```
3117
3118### off('setPreviewText')<sup>17+</sup>
3119
3120off(type: 'setPreviewText', callback?: SetPreviewTextCallback): void
3121
3122Unsubscribes from the event for text preview operations in an input method application. This API uses an asynchronous callback to return the result.
3123
3124**System capability**: SystemCapability.MiscServices.InputMethodFramework
3125
3126**Parameters**
3127
3128| Name| Type  | Mandatory| Description                                                        |
3129| ------ | ------ | ---- | ------------------------------------------------------------ |
3130| type   | string | Yes  | Event type, which is **'setPreviewText'**.|
3131| callback | [SetPreviewTextCallback](#setpreviewtextcallback17) | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
3132
3133**Example**
3134
3135```ts
3136let setPreviewTextCallback1: inputMethod.SetPreviewTextCallback = (text: string, range: inputMethod.Range) => {
3137  console.info(`SetPreviewTextCallback1: Received text - ${text}, Received range - start: ${range.start}, end: ${range.end}`);
3138};
3139
3140let setPreviewTextCallback2: inputMethod.SetPreviewTextCallback = (text: string, range: inputMethod.Range) => {
3141  console.info(`setPreviewTextCallback2: Received text - ${text}, Received range - start: ${range.start}, end: ${range.end}`);
3142};
3143
3144try {
3145  inputMethodController.on('setPreviewText', setPreviewTextCallback1);
3146  console.info(`SetPreviewTextCallback1 subscribed to setPreviewText`);
3147  inputMethodController.on('setPreviewText', setPreviewTextCallback2);
3148  console.info(`SetPreviewTextCallback2 subscribed to setPreviewText`);
3149  // Cancel only the callback1 of setPreviewText.
3150  inputMethodController.off('setPreviewText', setPreviewTextCallback1);
3151  console.info(`SetPreviewTextCallback1 unsubscribed from setPreviewText`);
3152  // Cancel all callbacks of setPreviewText.
3153  inputMethodController.off('setPreviewText');
3154  console.info(`All callbacks unsubscribed from setPreviewText`);
3155} catch(err) {
3156  console.error(`Failed to operate on setPreviewText: ${JSON.stringify(err)}`);
3157}
3158```
3159
3160### on('finishTextPreview')<sup>17+</sup>
3161
3162on(type: 'finishTextPreview', callback: Callback&lt;void&gt;): void
3163
3164Subscribes to the event of finishing text preview. This API uses an asynchronous callback to return the result.
3165
3166> **NOTE**
3167>
3168> To use the text preview function, you need to subscribe to this event before calling [attach](#attach10) and subscribe to this event together with [on('setPreviewText')](#onsetpreviewtext17).
3169
3170**System capability**: SystemCapability.MiscServices.InputMethodFramework
3171
3172**Parameters**
3173
3174| Name  | Type  | Mandatory| Description    |
3175| -------- | ----- | ---- | ------ |
3176| type     | string  | Yes  | Event type, which is **'finishTextPreview'**.|
3177| callback | Callback&lt;void&gt; | Yes  | Callback used to return the result. It is used to process the logic of finishing text preview. Return type: void|
3178
3179**Error codes**
3180
3181For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3182
3183| ID| Error Message                            |
3184| -------- | -------------------------------------- |
3185| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3186
3187**Example**
3188
3189```ts
3190let finishTextPreviewCallback1 = () => {
3191  console.info(`FinishTextPreviewCallback1: finishTextPreview event triggered`);
3192};
3193let finishTextPreviewCallback2 = () => {
3194  console.info(`FinishTextPreviewCallback2: finishTextPreview event triggered`);
3195};
3196
3197try {
3198  inputMethodController.on('finishTextPreview', finishTextPreviewCallback1);
3199  console.info(`FinishTextPreviewCallback1 subscribed to finishTextPreview`);
3200  inputMethodController.on('finishTextPreview', finishTextPreviewCallback2);
3201  console.info(`FinishTextPreviewCallback2 subscribed to finishTextPreview`);
3202  // Cancel only the callback1 of finishTextPreview.
3203  inputMethodController.off('finishTextPreview', finishTextPreviewCallback1);
3204  console.info(`FinishTextPreviewCallback1 unsubscribed from finishTextPreview`);
3205  // Cancel all callbacks of finishTextPreview.
3206  inputMethodController.off('finishTextPreview');
3207  console.info(`All callbacks unsubscribed from finishTextPreview`);
3208} catch(err) {
3209  console.error(`Failed to operate on finishTextPreview (subscribe/off): ${JSON.stringify(err)}`);
3210}
3211```
3212
3213### off('finishTextPreview')<sup>17+</sup>
3214
3215off(type: 'finishTextPreview', callback?: Callback&lt;void&gt;): void
3216
3217Unsubscribes from the event of finishing text preview. This API uses an asynchronous callback to return the result.
3218
3219**System capability**: SystemCapability.MiscServices.InputMethodFramework
3220
3221**Parameters**
3222
3223| Name| Type  | Mandatory| Description                                                        |
3224| ------ | ------ | ---- | ------------------------------------------------------------ |
3225| type   | string | Yes  | Event type, which is **'finishTextPreview'**.|
3226| callback | Callback&lt;void&gt; | No | Callback used for disable listening, which must be the same as that passed by the **on** API.<br>If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.|
3227
3228**Example**
3229
3230```ts
3231let finishTextPreviewCallback1 = () => {
3232  console.info(`FinishTextPreviewCallback1: finishTextPreview event triggered`);
3233};
3234let finishTextPreviewCallback2 = () => {
3235  console.info(`FinishTextPreviewCallback2: finishTextPreview event triggered`);
3236};
3237
3238try {
3239  inputMethodController.on('finishTextPreview', finishTextPreviewCallback1);
3240  console.info(`FinishTextPreviewCallback1 subscribed to finishTextPreview`);
3241  inputMethodController.on('finishTextPreview', finishTextPreviewCallback2);
3242  console.info(`FinishTextPreviewCallback2 subscribed to finishTextPreview`);
3243  // Cancel only the callback1 of finishTextPreview.
3244  inputMethodController.off('finishTextPreview', finishTextPreviewCallback1);
3245  console.info(`FinishTextPreviewCallback1 unsubscribed from finishTextPreview`);
3246  // Cancel all callbacks of finishTextPreview.
3247  inputMethodController.off('finishTextPreview');
3248  console.info(`All callbacks unsubscribed from finishTextPreview`);
3249} catch(err) {
3250  console.error(`Failed to operate on finishTextPreview (subscribe/off): ${JSON.stringify(err)}`);
3251}
3252```
3253
3254## InputMethodSetting<sup>8+</sup>
3255
3256In the following API examples, you must first use [getSetting](#inputmethodgetsetting9) to obtain an **InputMethodSetting** instance, and then call the APIs using the obtained instance.
3257
3258### on('imeChange')<sup>9+</sup>
3259
3260on(type: 'imeChange', callback: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
3261
3262Enables listening for the input method and subtype change event. This API uses an asynchronous callback to return the result.
3263
3264**System capability**: SystemCapability.MiscServices.InputMethodFramework
3265
3266**Parameters**
3267
3268| Name  | Type                           | Mandatory| Description                                                        |
3269| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
3270| type     | string                        | Yes  | Listening type. The value is fixed at **'imeChange'**.|
3271| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void  | Yes| Callback used to return the input method attributes and subtype.|
3272
3273**Example**
3274
3275```ts
3276import { InputMethodSubtype } from '@kit.IMEKit';
3277try {
3278  inputMethodSetting.on('imeChange', (inputMethodProperty: inputMethod.InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => {
3279    console.info('Succeeded in subscribing imeChange: inputMethodProperty: ' + JSON.stringify(inputMethodProperty) + " , inputMethodSubtype: " + JSON.stringify(inputMethodSubtype));
3280  });
3281} catch(err) {
3282  console.error(`Failed to subscribing imeChange. Code: ${err.code}, Message: ${err.message}`);
3283}
3284```
3285
3286### off('imeChange')<sup>9+</sup>
3287
3288off(type: 'imeChange', callback?: (inputMethodProperty: InputMethodProperty, inputMethodSubtype: InputMethodSubtype) => void): void
3289
3290Disables listening for the input method and subtype change event. This API uses an asynchronous callback to return the result.
3291
3292**System capability**: SystemCapability.MiscServices.InputMethodFramework
3293
3294**Parameters**
3295
3296| Name  | Type   | Mandatory| Description         |
3297| -------- | --------- | ---- | --------------- |
3298| type     | string    | Yes  | Listening type. The value is fixed at **'imeChange'**.|
3299| callback | (inputMethodProperty: [InputMethodProperty](#inputmethodproperty8), inputMethodSubtype: [InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)) => void  | No| Callback used to return the input method attributes and subtype.|
3300
3301**Example**
3302
3303```ts
3304inputMethodSetting.off('imeChange');
3305```
3306
3307### listInputMethodSubtype<sup>9+</sup>
3308
3309listInputMethodSubtype(inputMethodProperty: InputMethodProperty, callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): void
3310
3311Obtains all subtypes of a specified input method. This API uses an asynchronous callback to return the result.
3312
3313**System capability**: SystemCapability.MiscServices.InputMethodFramework
3314
3315**Parameters**
3316
3317| Name  | Type                                              | Mandatory| Description                  |
3318| -------- | -------------------------------------------------- | ---- | ---------------------- |
3319| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method.|
3320| callback | AsyncCallback&lt;Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>&gt; | Yes| Callback used to return all subtypes of the specified input method.|
3321
3322**Error codes**
3323
3324For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3325
3326| ID| Error Message                            |
3327| -------- | -------------------------------------- |
3328| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3329| 12800001 | bundle manager error.                 |
3330| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3331
3332**Example**
3333
3334```ts
3335import { InputMethodSubtype } from '@kit.IMEKit';
3336import { BusinessError } from '@kit.BasicServicesKit';
3337
3338let inputMethodProperty: inputMethod.InputMethodProperty = {
3339  name: 'com.example.kikakeyboard',
3340  id: 'propertyId',
3341  packageName: 'com.example.kikakeyboard',
3342  methodId: 'propertyId',
3343}
3344let inputMethodSetting = inputMethod.getSetting();
3345try {
3346  inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err: BusinessError, data: Array<InputMethodSubtype>) => {
3347    if (err) {
3348      console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
3349      return;
3350    }
3351    console.info('Succeeded in listing inputMethodSubtype.');
3352  });
3353} catch (err) {
3354  console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
3355}
3356```
3357
3358### listInputMethodSubtype<sup>9+</sup>
3359
3360listInputMethodSubtype(inputMethodProperty: InputMethodProperty): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;
3361
3362Obtains all subtypes of a specified input method. This API uses a promise to return the result.
3363
3364**System capability**: SystemCapability.MiscServices.InputMethodFramework
3365
3366**Parameters**
3367
3368| Name  | Type                                              | Mandatory| Description                  |
3369| -------- | -------------------------------------------------- | ---- | ---------------------- |
3370| inputMethodProperty | [InputMethodProperty](#inputmethodproperty8)| Yes| Input method.|
3371
3372**Return value**
3373
3374| Type                                                       | Description                  |
3375| ----------------------------------------------------------- | ---------------------- |
3376| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise used to return all subtypes of the specified input method.|
3377
3378**Error codes**
3379
3380For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3381
3382| ID| Error Message                            |
3383| -------- | -------------------------------------- |
3384| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.           |
3385| 12800001 | bundle manager error.                 |
3386| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3387
3388**Example**
3389
3390```ts
3391import { InputMethodSubtype } from '@kit.IMEKit';
3392import { BusinessError } from '@kit.BasicServicesKit';
3393
3394let inputMethodProperty: inputMethod.InputMethodProperty = {
3395  name: 'com.example.kikakeyboard',
3396  id: 'propertyId',
3397  packageName: 'com.example.kikakeyboard',
3398  methodId: 'propertyId',
3399}
3400let inputMethodSetting = inputMethod.getSetting();
3401try {
3402  inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data: Array<InputMethodSubtype>) => {
3403    console.info('Succeeded in listing inputMethodSubtype.');
3404  }).catch((err: BusinessError) => {
3405    console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
3406  })
3407} catch(err) {
3408  console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
3409}
3410```
3411
3412### listCurrentInputMethodSubtype<sup>9+</sup>
3413
3414listCurrentInputMethodSubtype(callback: AsyncCallback&lt;Array&lt;InputMethodSubtype&gt;&gt;): void
3415
3416Obtains all subtypes of this input method. This API uses an asynchronous callback to return the result.
3417
3418**System capability**: SystemCapability.MiscServices.InputMethodFramework
3419
3420**Parameters**
3421
3422| Name  | Type                                              | Mandatory| Description                  |
3423| -------- | -------------------------------------------------- | ---- | ---------------------- |
3424| callback | AsyncCallback&lt;Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>&gt; | Yes  | Callback used to return all subtypes of the current input method.|
3425
3426**Error codes**
3427
3428For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3429
3430| ID| Error Message                            |
3431| -------- | -------------------------------------- |
3432| 12800001 | bundle manager error.                 |
3433| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3434
3435**Example**
3436
3437```ts
3438import { InputMethodSubtype } from '@kit.IMEKit';
3439import { BusinessError } from '@kit.BasicServicesKit';
3440
3441let inputMethodSetting = inputMethod.getSetting();
3442try {
3443  inputMethodSetting.listCurrentInputMethodSubtype((err: BusinessError, data: Array<InputMethodSubtype>) => {
3444    if (err) {
3445      console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
3446      return;
3447    }
3448    console.info('Succeeded in listing currentInputMethodSubtype.');
3449  });
3450} catch(err) {
3451  console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
3452}
3453```
3454
3455### listCurrentInputMethodSubtype<sup>9+</sup>
3456
3457listCurrentInputMethodSubtype(): Promise&lt;Array&lt;InputMethodSubtype&gt;&gt;
3458
3459Obtains all subtypes of this input method. This API uses a promise to return the result.
3460
3461**System capability**: SystemCapability.MiscServices.InputMethodFramework
3462
3463**Return value**
3464
3465| Type                                                       | Description                  |
3466| ----------------------------------------------------------- | ---------------------- |
3467| Promise<Array<[InputMethodSubtype](./js-apis-inputmethod-subtype.md#inputmethodsubtype)>> | Promise used to return all subtypes of the current input method.|
3468
3469**Error codes**
3470
3471For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3472
3473| ID| Error Message                            |
3474| -------- | -------------------------------------- |
3475| 12800001 | bundle manager error.                 |
3476| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3477
3478**Example**
3479
3480```ts
3481import { InputMethodSubtype } from '@kit.IMEKit';
3482import { BusinessError } from '@kit.BasicServicesKit';
3483
3484let inputMethodSetting = inputMethod.getSetting();
3485try {
3486  inputMethodSetting.listCurrentInputMethodSubtype().then((data: Array<InputMethodSubtype>) => {
3487    console.info('Succeeded in listing currentInputMethodSubtype.');
3488  }).catch((err: BusinessError) => {
3489    console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
3490  })
3491} catch(err) {
3492  console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
3493}
3494```
3495
3496### getInputMethods<sup>9+</sup>
3497
3498getInputMethods(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
3499
3500Obtains a list of activated or deactivated input methods. This API uses an asynchronous callback to return the result.
3501
3502> **NOTE**
3503>
3504> An activated input method refers to an input method that is enabled. The default input method is enabled by default. Other input methods can be enabled or disabled as needed.
3505>
3506> The list of activated input methods includes the default input method and enabled input methods. The list of deactivated input methods includes all installed input methods except the enabled ones.
3507
3508**System capability**: SystemCapability.MiscServices.InputMethodFramework
3509
3510**Parameters**
3511
3512| Name  | Type                                               | Mandatory| Description                         |
3513| -------- | --------------------------------------------------- | ---- | ----------------------------- |
3514| enable   | boolean                                             | Yes  |Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.|
3515| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; |  Yes | Callback used to return a list of activated or deactivated input methods.|
3516
3517**Error codes**
3518
3519For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3520
3521| ID| Error Message                           |
3522| -------- | ----------------------------------- |
3523| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3524| 12800001 | bundle manager error.               |
3525| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3526
3527**Example**
3528
3529```ts
3530import { BusinessError } from '@kit.BasicServicesKit';
3531
3532try {
3533  inputMethodSetting.getInputMethods(true, (err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => {
3534    if (err) {
3535      console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
3536      return;
3537    }
3538    console.info('Succeeded in getting inputMethods.');
3539  });
3540} catch (err) {
3541  console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
3542}
3543```
3544
3545### getInputMethods<sup>9+</sup>
3546
3547getInputMethods(enable: boolean): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
3548
3549Obtains a list of activated or deactivated input methods. This API uses a promise to return the result.
3550
3551> **NOTE**
3552>
3553> An activated input method refers to an input method that is enabled. The default input method is enabled by default. Other input methods can be enabled or disabled as needed.
3554>
3555> The list of activated input methods includes the default input method and enabled input methods. The list of deactivated input methods includes all installed input methods except the enabled ones.
3556
3557**System capability**: SystemCapability.MiscServices.InputMethodFramework
3558
3559**Parameters**
3560
3561| Name| Type   | Mandatory| Description                   |
3562| ------ | ------- | ---- | ----------------------- |
3563| enable | boolean | Yes  |Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.|
3564
3565**Return value**
3566
3567| Type                                                        | Description                                      |
3568| ------------------------------------------------------------ | ------------------------------------------ |
3569| Promise\<Array\<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return a list of activated or deactivated input methods.|
3570
3571**Error codes**
3572
3573For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3574
3575| ID| Error Message                           |
3576| -------- | ----------------------------------- |
3577| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3578| 12800001 | bundle manager error.               |
3579| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3580
3581**Example**
3582
3583```ts
3584import { BusinessError } from '@kit.BasicServicesKit';
3585
3586try {
3587  inputMethodSetting.getInputMethods(true).then((data: Array<inputMethod.InputMethodProperty>) => {
3588    console.info('Succeeded in getting inputMethods.');
3589  }).catch((err: BusinessError) => {
3590    console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
3591  })
3592} catch(err) {
3593  console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
3594}
3595```
3596
3597### getInputMethodsSync<sup>11+</sup>
3598
3599getInputMethodsSync(enable: boolean): Array&lt;InputMethodProperty&gt;
3600
3601Obtains a list of activated or deactivated input methods. This API returns the result synchronously.
3602
3603> **NOTE**
3604>
3605> An activated input method refers to an input method that is enabled. The default input method is enabled by default. Other input methods can be enabled or disabled as needed.
3606>
3607> The list of activated input methods includes the default input method and enabled input methods. The list of deactivated input methods includes all installed input methods except the enabled ones.
3608
3609**System capability**: SystemCapability.MiscServices.InputMethodFramework
3610
3611**Parameters**
3612
3613| Name| Type   | Mandatory| Description                   |
3614| ------ | ------- | ---- | ----------------------- |
3615| enable | boolean | Yes  |Whether to return a list of activated input methods. The value **true** means to return a list of activated input methods, and **false** means to return a list of deactivated input methods.|
3616
3617**Return value**
3618
3619| Type                                                | Description                         |
3620| ---------------------------------------------------- | ----------------------------- |
3621| Array\<[InputMethodProperty](#inputmethodproperty8)> | List of activated or deactivated input methods.|
3622
3623**Error codes**
3624
3625For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3626
3627| ID| Error Message                            |
3628| -------- | -------------------------------------- |
3629| 401      | parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
3630| 12800001 | bundle manager error.                 |
3631| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3632
3633**Example**
3634
3635```ts
3636try {
3637  let imeProperty = inputMethodSetting.getInputMethodsSync(true);
3638} catch(err) {
3639  console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
3640}
3641```
3642
3643### getAllInputMethods<sup>11+</sup>
3644
3645getAllInputMethods(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
3646
3647Obtains a list of all input methods. This API uses an asynchronous callback to return the result.
3648
3649**System capability**: SystemCapability.MiscServices.InputMethodFramework
3650
3651**Parameters**
3652
3653| Name  | Type                                                        | Mandatory| Description                          |
3654| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
3655| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | Yes  | Callback used to return a list of all input methods.|
3656
3657**Error codes**
3658
3659For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3660
3661| ID| Error Message                           |
3662| -------- | ----------------------------------- |
3663| 12800001 | bundle manager error.               |
3664| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3665
3666**Example**
3667
3668```ts
3669import { BusinessError } from '@kit.BasicServicesKit';
3670
3671try {
3672  inputMethodSetting.getAllInputMethods((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => {
3673    if (err) {
3674      console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`);
3675      return;
3676    }
3677    console.info('Succeeded in getting all inputMethods.');
3678  });
3679} catch (err) {
3680  console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`);
3681}
3682```
3683
3684### getAllInputMethods<sup>11+</sup>
3685
3686getAllInputMethods(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
3687
3688Obtains a list of all input methods. This API uses a promise to return the result.
3689
3690**System capability**: SystemCapability.MiscServices.InputMethodFramework
3691
3692**Return value**
3693
3694| Type                                                        | Description                             |
3695| ------------------------------------------------------------ | --------------------------------- |
3696| Promise\<Array\<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return a list of all input methods.|
3697
3698**Error codes**
3699
3700For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3701
3702| ID| Error Message                           |
3703| -------- | ----------------------------------- |
3704| 12800001 | bundle manager error.              |
3705| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3706
3707**Example**
3708
3709```ts
3710import { BusinessError } from '@kit.BasicServicesKit';
3711
3712inputMethodSetting.getAllInputMethods().then((data: Array<inputMethod.InputMethodProperty>) => {
3713  console.info('Succeeded in getting all inputMethods.');
3714}).catch((err: BusinessError) => {
3715  console.error(`Failed to getAllInputMethods: ${JSON.stringify(err)}`);
3716})
3717```
3718
3719### getAllInputMethodsSync<sup>11+</sup>
3720
3721getAllInputMethodsSync(): Array&lt;InputMethodProperty&gt;
3722
3723Obtains a list of all input methods. This API returns the result synchronously.
3724
3725**System capability**: SystemCapability.MiscServices.InputMethodFramework
3726
3727**Return value**
3728
3729| Type                                                | Description              |
3730| ---------------------------------------------------- | ------------------ |
3731| Array\<[InputMethodProperty](#inputmethodproperty8)> | List of all input methods.|
3732
3733**Error codes**
3734
3735For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
3736
3737| ID| Error Message                           |
3738| -------- | ----------------------------------- |
3739| 12800001 | bundle manager error.              |
3740| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3741
3742**Example**
3743
3744```ts
3745try {
3746  let imeProperty = inputMethodSetting.getAllInputMethodsSync();
3747} catch(err) {
3748  console.error(`Failed to getAllInputMethodsSync: ${JSON.stringify(err)}`);
3749}
3750```
3751
3752### showOptionalInputMethods<sup>(deprecated)</sup>
3753
3754showOptionalInputMethods(callback: AsyncCallback&lt;boolean&gt;): void
3755
3756Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result.
3757> **NOTE**
3758>
3759> This API is supported since API version 9 and deprecated since API version 18.
3760
3761**System capability**: SystemCapability.MiscServices.InputMethodFramework
3762
3763**Parameters**
3764
3765| Name| Type| Mandatory| Description|
3766| -------- | -------- | -------- | -------- |
3767| 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.|
3768
3769**Error codes**
3770
3771For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
3772
3773| ID| Error Message                            |
3774| -------- | -------------------------------------- |
3775| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3776
3777**Example**
3778
3779```ts
3780import { BusinessError } from '@kit.BasicServicesKit';
3781
3782try {
3783  inputMethodSetting.showOptionalInputMethods((err: BusinessError, data: boolean) => {
3784    if (err) {
3785      console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
3786      return;
3787    }
3788    console.info('Succeeded in showing optionalInputMethods.');
3789  });
3790} catch (err) {
3791  console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
3792}
3793```
3794
3795### showOptionalInputMethods<sup>(deprecated)</sup>
3796
3797showOptionalInputMethods(): Promise&lt;boolean&gt;
3798
3799Displays a dialog box for selecting an input method. This API uses a promise to return the result.
3800
3801> **NOTE**
3802>
3803> This API is supported since API version 9 and deprecated since API version 18.
3804
3805**System capability**: SystemCapability.MiscServices.InputMethodFramework
3806
3807**Return value**
3808
3809| Type| Description|
3810| -------- | -------- |
3811| Promise&lt;boolean&gt; | Promise used to return the result. If the operation is successful, **err** is **undefined** and **data** is **true**. Otherwise, **err** is an error object.|
3812
3813**Error codes**
3814
3815For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md).
3816
3817| ID| Error Message                            |
3818| -------- | -------------------------------------- |
3819| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3820
3821**Example**
3822
3823```ts
3824import { BusinessError } from '@kit.BasicServicesKit';
3825
3826inputMethodSetting.showOptionalInputMethods().then((data: boolean) => {
3827  console.info('Succeeded in showing optionalInputMethods.');
3828}).catch((err: BusinessError) => {
3829  console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
3830})
3831```
3832
3833### listInputMethod<sup>(deprecated)</sup>
3834
3835listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;): void
3836
3837Obtains a list of installed input methods. This API uses an asynchronous callback to return the result.
3838
3839> **NOTE**
3840>
3841> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9) instead.
3842
3843**System capability**: SystemCapability.MiscServices.InputMethodFramework
3844
3845**Parameters**
3846
3847| Name  | Type                                              | Mandatory| Description                  |
3848| -------- | -------------------------------------------------- | ---- | ---------------------- |
3849| callback | AsyncCallback&lt;Array<[InputMethodProperty](#inputmethodproperty8)>&gt; | Yes  | Callback used to return the list of installed input methods.|
3850
3851**Example**
3852
3853```ts
3854import { BusinessError } from '@kit.BasicServicesKit';
3855
3856inputMethodSetting.listInputMethod((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => {
3857  if (err) {
3858    console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`);
3859    return;
3860  }
3861  console.info('Succeeded in listing inputMethod.');
3862 });
3863```
3864
3865### listInputMethod<sup>(deprecated)</sup>
3866
3867listInputMethod(): Promise&lt;Array&lt;InputMethodProperty&gt;&gt;
3868
3869Obtains a list of installed input methods. This API uses a promise to return the result.
3870
3871> **NOTE**
3872>
3873> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [getInputMethods](#getinputmethods9-1) instead.
3874
3875**System capability**: SystemCapability.MiscServices.InputMethodFramework
3876
3877**Return value**
3878
3879| Type                                                       | Description                  |
3880| ----------------------------------------------------------- | ---------------------- |
3881| Promise<Array<[InputMethodProperty](#inputmethodproperty8)>> | Promise used to return the list of installed input methods.|
3882
3883**Example**
3884
3885```ts
3886import { BusinessError } from '@kit.BasicServicesKit';
3887
3888inputMethodSetting.listInputMethod().then((data: Array<inputMethod.InputMethodProperty>) => {
3889  console.info('Succeeded in listing inputMethod.');
3890}).catch((err: BusinessError) => {
3891  console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`);
3892})
3893```
3894
3895### displayOptionalInputMethod<sup>(deprecated)</sup>
3896
3897displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
3898
3899Displays a dialog box for selecting an input method. This API uses an asynchronous callback to return the result.
3900
3901> **NOTE**
3902>
3903> This API is supported since API version 8 and deprecated since API version 9.
3904
3905**System capability**: SystemCapability.MiscServices.InputMethodFramework
3906
3907**Parameters**
3908
3909| Name| Type| Mandatory| Description|
3910| -------- | -------- | -------- | -------- |
3911| 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.|
3912
3913**Example**
3914
3915```ts
3916import { BusinessError } from '@kit.BasicServicesKit';
3917
3918inputMethodSetting.displayOptionalInputMethod((err: BusinessError) => {
3919  if (err) {
3920    console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`);
3921    return;
3922  }
3923  console.info('Succeeded in displaying optionalInputMethod.');
3924});
3925```
3926
3927### displayOptionalInputMethod<sup>(deprecated)</sup>
3928
3929displayOptionalInputMethod(): Promise&lt;void&gt;
3930
3931Displays a dialog box for selecting an input method. This API uses a promise to return the result.
3932
3933> **NOTE**
3934>
3935> This API is supported since API version 8 and deprecated since API version 9.
3936
3937**System capability**: SystemCapability.MiscServices.InputMethodFramework
3938
3939**Return value**
3940
3941| Type| Description|
3942| -------- | -------- |
3943| Promise&lt;void&gt; | Promise that returns no value.|
3944
3945**Example**
3946
3947```ts
3948import { BusinessError } from '@kit.BasicServicesKit';
3949
3950inputMethodSetting.displayOptionalInputMethod().then(() => {
3951  console.info('Succeeded in displaying optionalInputMethod.');
3952}).catch((err: BusinessError) => {
3953  console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`);
3954})
3955```
3956
3957### getInputMethodState<sup>15+</sup>
3958
3959getInputMethodState(): Promise&lt;EnabledState&gt;
3960
3961Obtains the input method state. This API uses a promise to return the result.
3962
3963**System capability**: SystemCapability.MiscServices.InputMethodFramework
3964
3965**Return value**
3966
3967| Type                                   | Description                                                        |
3968| --------------------------------------- | ------------------------------------------------------------ |
3969| Promise\<[EnabledState](#enabledstate15)> | Promise used to return the result. **EnabledState.DISABLED** indicates that the input method is disabled, **EnabledState.BASIC_MODE** indicates that the input method is in basic mode, and **EnabledState.FULL_EXPERIENCE_MODE** indicates that the input method is in full experience mode.|
3970
3971**Error codes**
3972
3973For details about the error codes, see [Input Method Framework Error Codes](errorcode-inputmethod-framework.md) and [Universal Error Codes](../errorcode-universal.md).
3974
3975| ID| Error Message                           |
3976| -------- | ----------------------------------- |
3977| 12800004 | not an input method application.    |
3978| 12800008 | input method manager service error. Possible cause: a system error, such as null pointer, IPC exception. |
3979
3980**Example**
3981
3982```ts
3983import { BusinessError } from '@kit.BasicServicesKit';
3984
3985inputMethodSetting.getInputMethodState().then((status: inputMethod.EnabledState) => {
3986  console.info(`Succeeded in getInputMethodState, status: ${status}`);
3987}).catch((err: BusinessError) => {
3988  console.error(`Failed to getInputMethodState: ${JSON.stringify(err)}`);
3989})
3990```
3991