• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.inputMethodEngine (Input Method Service) (System API)
2<!--Kit: IME Kit-->
3<!--Subsystem: MiscServices-->
4<!--Owner: @illybyy-->
5<!--Designer: @andeszhang-->
6<!--Tester: @murphy1984-->
7<!--Adviser: @zhang_yixin13-->
8
9The **inputMethodEngine** module provides management capabilities for system input method applications. With the APIs of this module, input method applications are able to create soft keyboard windows, insert or delete characters, select text, and listen for physical keyboard events.
10
11> **NOTE**
12>
13> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
14
15## Modules to Import
16
17```ts
18import { inputMethodEngine } from '@kit.IMEKit';
19```
20
21## SizeUpdateCallback<sup>14+</sup>
22
23type SizeUpdateCallback = (size: window.Size, keyboardArea: KeyboardArea) => void
24
25Callback triggered when the size of the input method panel changes.
26
27**System capability**: SystemCapability.MiscServices.InputMethodFramework
28
29**System API**: This is a system API.
30
31| Name      | Type                                                | Mandatory| Description                            |
32| ------------ | ---------------------------------------------------- | ---- | -------------------------------- |
33| size         | [window.Size](../apis-arkui/arkts-apis-window-i.md#size7) | Yes  | Panel size.                  |
34| keyboardArea | [KeyboardArea](./js-apis-inputmethodengine.md#keyboardarea15)    | Yes  | Size of the keyboard area.|
35
36## Panel<sup>10+</sup>
37
38You need to use [createPanel](./js-apis-inputmethodengine.md#createpanel10) to obtain the panel instance and then call the following APIs through the instance.
39
40### on('sizeUpdate')<sup>14+</sup>
41
42on(type: 'sizeUpdate', callback: SizeUpdateCallback): void
43
44Listens for the panel size change. This API uses an asynchronous callback to return the result.
45
46> **NOTE**
47>
48> This API applies only to the panels of the **SOFT_KEYBOARD** type in the **FLG_FIXED** or **FLG_FLOATING** state. When you call [adjustPanelRect](./js-apis-inputmethodengine.md#adjustpanelrect15) to adjust the panel size, the system calculates the final value based on certain rules (for example, whether the panel size exceeds the screen). This callback can be used to obtain the actual panel size to refresh the panel layout.
49
50**System capability**: SystemCapability.MiscServices.InputMethodFramework
51
52**System API**: This is a system API.
53
54**Parameters**
55
56| Name  | Type                                       | Mandatory| Description                                                  |
57| -------- | ------------------------------------------- | ---- | ------------------------------------------------------ |
58| type     | string                                      | Yes  | Event type, which is **'sizeUpdate'**.|
59| callback | [SizeUpdateCallback](#sizeupdatecallback14) | Yes  | Callback used to return the size of the soft keyboard panel, including the width and height.|
60
61**Example**
62
63```ts
64import { window } from '@kit.ArkUI';
65
66try {
67  panel.on('sizeUpdate', (windowSize: window.Size, keyboardArea: inputMethodEngine.KeyboardArea) => {
68    console.info(`panel size changed, windowSize: ${JSON.stringify(windowSize)}, keyboardArea: ${JSON.stringify(keyboardArea)}`);
69  });
70} catch(err) {
71  console.error(`Failed to subscribe sizeUpdate: ${JSON.stringify(err)}`);
72}
73```
74
75### off('sizeUpdate')<sup>14+</sup>
76
77off(type: 'sizeUpdate', callback?: SizeUpdateCallback): void
78
79Disables listening for the panel size change. This API uses an asynchronous callback to return the result.
80
81> **NOTE**
82>
83> This API applies only to the panels of the **SOFT_KEYBOARD** type in the **FLG_FIXED** or **FLG_FLOATING** state. When you call [adjustPanelRect](./js-apis-inputmethodengine.md#adjustpanelrect15) to adjust the panel size, the system calculates the final value based on certain rules (for example, whether the panel size exceeds the screen). This callback can be used to obtain the actual panel size to refresh the panel layout.
84
85**System capability**: SystemCapability.MiscServices.InputMethodFramework
86
87**System API**: This is a system API.
88
89**Parameters**
90
91| Name  | Type                                       | Mandatory| Description                                                    |
92| -------- | ------------------------------------------- | ---- | -------------------------------------------------------- |
93| type     | string                                      | Yes  | Event type, which is **'sizeUpdate'**.|
94| callback | [SizeUpdateCallback](#sizeupdatecallback14) | No  | Callback used to return the size of the soft keyboard panel, including the width and height.  |
95
96**Example**
97
98```ts
99import { window } from '@kit.ArkUI';
100
101try {
102  panel.off('sizeUpdate', (windowSize: window.Size, keyboardArea: inputMethodEngine.KeyboardArea) => {
103    console.info(`panel size changed, width: ${windowSize.width}, height: ${windowSize.height}`);
104  });
105} catch(err) {
106    console.error(`Failed to subscribe sizeUpdate: ${JSON.stringify(err)}`);
107}
108```
109## FluidLightMode<sup>20+</sup>
110
111Enumerates the fluid light modes of the input method.
112
113**System capability**: SystemCapability.MiscServices.InputMethodFramework
114
115**System API**: This is a system API.
116
117| Name        | Value| Description              |
118| ------------ | -- | ------------------ |
119| NONE | 0 | The fluid light mode is not used.|
120| BACKGROUND_FLUID_LIGHT  | 1 | The background fluid light mode is used.|
121
122## EditorAttribute
123
124Describes the attribute of the edit box.
125
126**System capability**: SystemCapability.MiscServices.InputMethodFramework
127
128**System API**: This is a system API.
129
130| Name        | Type| Read-Only| Optional| Description              |
131| ------------ | -------- | ---- | ---- | ------------------ |
132| fluidLightMode<sup>20+</sup> | [FluidLightMode](#fluidlightmode20) | Yes| Yes| Fluid light mode. If this attribute is not specified or is set to an invalid value, the fluid light mode is not used by default.<br>This attribute is available only to system applications.|
133
134## ImmersiveEffect<sup>20+</sup>
135
136Describes the immersive effect.
137
138**System capability**: SystemCapability.MiscServices.InputMethodFramework
139
140**System API**: This is a system API.
141
142| Name  | Type                                 | Read-Only| Optional| Description          |
143| ------ | ------------------------------------ | ---- | ---- | -------------- |
144| fluidLightMode | [FluidLightMode](#fluidlightmode20) | No  | Yes  | Fluid light mode. If this attribute is not set, the default value is **NONE**.<br>This attribute is available only to system applications.|
145<!--no_check-->
146