[InputMethodExtensionAbility](../reference/apis/js-apis-inputmethod-extension-ability.md) is an ExtensionAbility component of the inputMethod type that provides extension capabilities for the input method framework.
InputMethodExtensionAbility can be started or connected by other application components to process transactions in the background based on the request of the caller.
InputMethodExtensionAbility provides related capabilities through the [InputMethodExtensionContext](../reference/apis/js-apis-inputmethod-extension-context.md).
## Implementing an Input Method Application
InputMethodExtensionAbility provides the **onCreate()** and **onDestory()** callbacks, as described below. Override them as required.
-**onCreate**
This callback is triggered when a service is created for the first time. You can perform initialization operations, for example, registering a common event listener.
> **NOTE**
>
> If a service has been created, starting it again does not trigger the **onCreate()** callback.
-**onDestroy**
This callback is triggered when the service is no longer used and the instance is ready for destruction. You can clear resources in this callback, for example, deregister the listener.
## How to Develop
To implement an input method application, manually create an InputMethodExtensionAbility component in DevEco Studio. The procedure is as follows:
In the **ets** directory of the target module, right-click and choose **New** > **Extention Ability** > **InputMethod** to a minimum template of InputMethodExtensionAbility.
> **NOTE**
>
> When compiling the input method application, use the signature at the system_core level. Otherwise, the application will not be able to start the keyboard.
The minimum template implements an input method application with the most basic features, such as starting the keyboard, entering text, and deleting input. You can diversify the feature set of the application by, for example, adding the feature to hide the keyboard.
The minimum template contains four files: **KeyboardController.ts**, **InputMethodService.ts**, **Index.ets**, and **KeyboardKeyData.ts**. The file directory is as follows:
```
/src/main/
├── ets/inputmethodextability
│ └──model/KeyboardController.ts # Shows the keyboard.
│ └──InputMethodService.ts # Customizes a class that inherits from InputMethodExtensionAbility and add the required lifecycle callbacks.
│ └──pages
│ └── Index.ets # Draws the keyboard and adds the input and deletion features.
In this file, add the dependency package for importing InputMethodExtensionAbility. Customize a class that inherits from InputMethodExtensionAbility and add the required lifecycle callbacks.
mContext;// Save the context attribute in InputMethodExtensionAbility.
WINDOW_TYPE_INPUT_METHOD_FLOAT=2105;// Define the window type. The value 2105 indicates the input method window type, which is used to create an input method application window.
windowName='inputApp';
privatewindowHeight:number=0;
privatewindowWidth:number=0;
privatenonBarPosition:number=0;
privateisWindowShowing:boolean=false;
constructor(context){
this.mContext=context;
}
publiconCreate():void
{
this.initWindow();// Initialize the window.
this.registerListener();// Register an event listener for the input method framework.
}
publiconDestroy():void// Destroy the instance.
{
this.unRegisterListener();// Deregister the event listener.
letwin=windowManager.findWindow(this.windowName);
win.destroyWindow();// Destroy the window.
this.mContext.terminateSelf();// Terminate the InputMethodExtensionAbility service.
}
privateinitWindow():void// Initialize the window.
{
letdis=display.getDefaultDisplaySync();
letdWidth=dis.width;
letdHeight=dis.height;
letkeyHeightRate=0.47;
letkeyHeight=dHeight*keyHeightRate;
this.windowWidth=dWidth;
this.windowHeight=keyHeight;
this.nonBarPosition=dHeight-keyHeight;
letconfig={
name:this.windowName,
windowType:this.WINDOW_TYPE_INPUT_METHOD_FLOAT,
ctx:this.mContext
}
windowManager.createWindow(config).then((win)=>{// Create a window of the specified type.
globalThis.textInputClient=textInputClient;// This is an input method client instance, based on which you can call the functional APIs that the input method framework provides for the input method application.
Register the InputMethodExtensionAbility in the [module.json5 file](../quick-start/module-configuration-file.md) corresponding to the target module. Set **type** to **"inputMethod"** and **srcEntrance** to the code path of the InputMethodExtensionAbility component.