• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.inputMethodEngine (Input Method Service) (System API)
2
3The **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.
4
5> **NOTE**
6>
7> 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.
8
9## Modules to Import
10
11```ts
12import { inputMethodEngine } from '@kit.IMEKit';
13```
14
15## SizeUpdateCallback<sup>14+</sup>
16
17type SizeUpdateCallback = (size: window.Size, keyboardArea: KeyboardArea) => void
18
19Callback triggered when the size of the input method panel changes.
20
21**System capability**: SystemCapability.MiscServices.InputMethodFramework
22
23**System API**: This is a system API.
24
25| Name      | Type                                                | Mandatory| Description                            |
26| ------------ | ---------------------------------------------------- | ---- | -------------------------------- |
27| size         | [window.Size](../apis-arkui/js-apis-window.md#size7) | Yes  | Panel size.                  |
28| keyboardArea | [KeyboardArea](./js-apis-inputmethodengine.md#keyboardarea15)    | Yes  | Size of the keyboard area.|
29
30## Panel<sup>10+</sup>
31
32You need to use [createPanel](./js-apis-inputmethodengine.md#createpanel10) to obtain the panel instance and then call the following APIs through the instance.
33
34### on('sizeUpdate')<sup>14+</sup>
35
36on(type: 'sizeUpdate', callback: SizeUpdateCallback): void
37
38Listens for the panel size change. This API uses an asynchronous callback to return the result.
39
40> **NOTE**
41>
42> 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.
43
44**System capability**: SystemCapability.MiscServices.InputMethodFramework
45
46**System API**: This is a system API.
47
48**Parameters**
49
50| Name  | Type                                       | Mandatory| Description                                                  |
51| -------- | ------------------------------------------- | ---- | ------------------------------------------------------ |
52| type     | string                                      | Yes  | Event type, which is **'sizeUpdate'**.|
53| callback | [SizeUpdateCallback](#sizeupdatecallback14) | Yes  | Callback used to return the result, the size of the soft keyboard panel, including the width and height.|
54
55**Example**
56
57```ts
58import { window } from '@kit.ArkUI';
59
60try {
61  panel.on('sizeUpdate', (windowSize: window.Size, keyboardArea: inputMethodEngine.KeyboardArea) => {
62    console.info(`panel size changed, windowSize: ${JSON.stringify(windowSize)}, keyboardArea: ${JSON.stringify(keyboardArea)}`);
63  });
64} catch(err) {
65  console.error(`Failed to subscribe sizeUpdate: ${JSON.stringify(err)}`);
66}
67```
68
69### off('sizeUpdate')<sup>14+</sup>
70
71off(type: 'sizeUpdate', callback?: SizeUpdateCallback): void
72
73Disables listening for the panel size change. This API uses an asynchronous callback to return the result.
74
75> **NOTE**
76>
77> 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.
78
79**System capability**: SystemCapability.MiscServices.InputMethodFramework
80
81**System API**: This is a system API.
82
83**Parameters**
84
85| Name  | Type                                       | Mandatory| Description                                                    |
86| -------- | ------------------------------------------- | ---- | -------------------------------------------------------- |
87| type     | string                                      | Yes  | Event type, which is **'sizeUpdate'**.|
88| callback | [SizeUpdateCallback](#sizeupdatecallback14) | No  | Callback used to return the result, the size of the soft keyboard panel, including the width and height.  |
89
90**Example**
91
92```ts
93import { window } from '@kit.ArkUI';
94
95try {
96  panel.off('sizeUpdate', (windowSize: window.Size, keyboardArea: inputMethodEngine.KeyboardArea) => {
97    console.info(`panel size changed, width: ${windowSize.width}, height: ${windowSize.height}`);
98  });
99} catch(err) {
100    console.error(`Failed to subscribe sizeUpdate: ${JSON.stringify(err)}`);
101}
102```
103<!--no_check-->
104