harmony 鸿蒙@ohos.inputMethodEngine (Input Method Service) (System API)

  • 2025-06-12
  • 浏览 (4)

@ohos.inputMethodEngine (Input Method Service) (System API)

The 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.

NOTE

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.

Modules to Import

import { inputMethodEngine } from '@kit.IMEKit';

SizeUpdateCallback14+

type SizeUpdateCallback = (size: window.Size, keyboardArea: KeyboardArea) => void

Callback triggered when the size of the input method panel changes.

System capability: SystemCapability.MiscServices.InputMethodFramework

System API: This is a system API.

Name Type Mandatory Description
size window.Size Yes Panel size.
keyboardArea KeyboardArea Yes Size of the keyboard area.

Panel10+

You need to use createPanel to obtain the panel instance and then call the following APIs through the instance.

on(‘sizeUpdate’)14+

on(type: ‘sizeUpdate’, callback: SizeUpdateCallback): void

Listens for the panel size change. This API uses an asynchronous callback to return the result.

NOTE

This API applies only to the panels of the SOFT_KEYBOARD type in the FLG_FIXED or FLG_FLOATING state. When you call adjustPanelRect 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.

System capability: SystemCapability.MiscServices.InputMethodFramework

System API: This is a system API.

Parameters

Name Type Mandatory Description
type string Yes Event type, which is ‘sizeUpdate’.
callback SizeUpdateCallback Yes Callback used to return the result, the size of the soft keyboard panel, including the width and height.

Example

import { window } from '@kit.ArkUI';

try {
  panel.on('sizeUpdate', (windowSize: window.Size, keyboardArea: inputMethodEngine.KeyboardArea) => {
    console.info(`panel size changed, windowSize: ${JSON.stringify(windowSize)}, keyboardArea: ${JSON.stringify(keyboardArea)}`);
  });
} catch(err) {
  console.error(`Failed to subscribe sizeUpdate: ${JSON.stringify(err)}`);
}

off(‘sizeUpdate’)14+

off(type: ‘sizeUpdate’, callback?: SizeUpdateCallback): void

Disables listening for the panel size change. This API uses an asynchronous callback to return the result.

NOTE

This API applies only to the panels of the SOFT_KEYBOARD type in the FLG_FIXED or FLG_FLOATING state. When you call adjustPanelRect 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.

System capability: SystemCapability.MiscServices.InputMethodFramework

System API: This is a system API.

Parameters

Name Type Mandatory Description
type string Yes Event type, which is ‘sizeUpdate’.
callback SizeUpdateCallback No Callback used to return the result, the size of the soft keyboard panel, including the width and height.

Example

import { window } from '@kit.ArkUI';

try {
  panel.off('sizeUpdate', (windowSize: window.Size, keyboardArea: inputMethodEngine.KeyboardArea) => {
    console.info(`panel size changed, width: ${windowSize.width}, height: ${windowSize.height}`);
  });
} catch(err) {
    console.error(`Failed to subscribe sizeUpdate: ${JSON.stringify(err)}`);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙IME Kit

harmony 鸿蒙InputMethod

harmony 鸿蒙Input Method Framework Error Codes

harmony 鸿蒙inputmethod_attach_options_capi.h

harmony 鸿蒙inputmethod_controller_capi.h

harmony 鸿蒙inputmethod_cursor_info_capi.h

harmony 鸿蒙inputmethod_inputmethod_proxy_capi.h

harmony 鸿蒙inputmethod_private_command_capi.h

harmony 鸿蒙inputmethod_text_avoid_info_capi.h

harmony 鸿蒙inputmethod_text_config_capi.h

0  赞