{"_id":"@capacitor-ohos/keyboard","_rev":"2-164dce30e6707e5d17a5931182e41a2f","name":"@capacitor-ohos/keyboard","dist-tags":{"latest":"8.0.2"},"versions":{"8.0.1":{"name":"@capacitor-ohos/keyboard","version":"8.0.1","keywords":["capacitor","plugin","native"],"author":{"url":"Group","name":"Huawei Device Co., Ltd and iSoftStone Information Technology"},"license":"MIT","_id":"@capacitor-ohos/keyboard@8.0.1","maintainers":[{"name":"luqi_tan","email":"295099422@qq.com"}],"bugs":{"url":"https://gitcode.com/CPF-Ionic/capacitor-keyboard/issues"},"dist":{"shasum":"04fad416c002a58b6d1c1a8249249f9ae822ec5b","tarball":"https://registry.npmjs.org/@capacitor-ohos/keyboard/-/keyboard-8.0.1.tgz","fileCount":10,"integrity":"sha512-J+Yu47aoaqgA9OnqybO04bwSyJej8M2m9oMnnQvAPpBTMWv/GvfQno9fBOf5cr1flihzv1b9TL6Yououv03haA==","signatures":[{"sig":"MEUCIQDBovHzGFzBi/GJOdrDmXCdCQxQwLpDTwK2onRItIvEfwIgP1EVSBJNyvG5c94O5y60tbZcrLqFL5UR3a0390Js00E=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":48895},"gitHead":"f7afceb98bf8386cfc8cfe330201acf282287d5b","_npmUser":{"name":"luqi_tan","email":"295099422@qq.com"},"capacitor":{"id":"@capacitor/keyboard","platforms":["openharmony"]},"repository":{"url":"gitcode:CPF-Ionic/capacitor-keyboard","type":"git"},"_npmVersion":"10.5.1","description":"The Keyboard API provides keyboard display and visibility control, along with event tracking when the keyboard shows and hides.","directories":{},"_nodeVersion":"22.0.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/keyboard_8.0.1_1777540259303_0.3149701368386477","host":"s3://npm-registry-packages-npm-production"}},"8.0.2":{"name":"@capacitor-ohos/keyboard","version":"8.0.2","description":"The Keyboard API provides keyboard display and visibility control, along with event tracking when the keyboard shows and hides.","capacitor":{"id":"@capacitor/keyboard","platforms":["openharmony"]},"repository":{"type":"git","url":"gitcode:CPF-Ionic/capacitor-keyboard"},"bugs":{"url":"https://gitcode.com/CPF-Ionic/capacitor-keyboard/issues"},"keywords":["capacitor","plugin","native"],"author":{"name":"Huawei Device Co., Ltd and iSoftStone Information Technology","url":"Group"},"license":"MIT","_id":"@capacitor-ohos/keyboard@8.0.2","gitHead":"05058c56db2c159b19092311ca3fe3ef03d4c1e8","_nodeVersion":"22.0.0","_npmVersion":"10.5.1","dist":{"integrity":"sha512-Crr0cfV/MKRf4uVTB+QLQS2+rctV6LIInyaPPJyjoF402RzI7NuQ+86PlJD5VXgStLzgN+RgaVjYtUQBMOM6eg==","shasum":"158e3f2af3e20fef27fc205f6eddbee8850e4442","tarball":"https://registry.npmjs.org/@capacitor-ohos/keyboard/-/keyboard-8.0.2.tgz","fileCount":10,"unpackedSize":48919,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDaKeYzVVg//h6OCZKchENp1sGc4HHOB/8BQuJ0F3krqAIgDB56MvxEBufVgsHev+uD/Q9tHI+xE4jdna550jFgQa4="}]},"_npmUser":{"name":"luqi_tan","email":"295099422@qq.com"},"directories":{},"maintainers":[{"name":"luqi_tan","email":"295099422@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/keyboard_8.0.2_1784790472785_0.828787293528372"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-30T09:10:59.185Z","modified":"2026-07-23T07:07:53.250Z","8.0.1":"2026-04-30T09:10:59.434Z","8.0.2":"2026-07-23T07:07:52.929Z"},"bugs":{"url":"https://gitcode.com/CPF-Ionic/capacitor-keyboard/issues"},"author":{"name":"Huawei Device Co., Ltd and iSoftStone Information Technology","url":"Group"},"license":"MIT","keywords":["capacitor","plugin","native"],"repository":{"type":"git","url":"gitcode:CPF-Ionic/capacitor-keyboard"},"description":"The Keyboard API provides keyboard display and visibility control, along with event tracking when the keyboard shows and hides.","maintainers":[{"name":"luqi_tan","email":"295099422@qq.com"}],"readme":"# <center>@capacitor/keyboard</center>\r\n[![zh-CN](https://img.shields.io/badge/lang-中文-blue.svg)](README.md)\r\n[![en](https://img.shields.io/badge/lang-English-blue.svg)](README.en.md)\r\n\r\n本项目基于 [@capacitor/keyboard@8.0.0](https://www.npmjs.com/package/@capacitor/keyboard/v/8.0.0) 开发。\r\n\r\n## 简介\r\n\r\n@capacitor/keyboard是capacitor生态系统中的核心插件，提供完善的键盘控制API，支持对设备键盘进行显示、隐藏操作，同时可监听键盘弹出、收起相关事件，为跨平台应用开发提供设备差异化适配能力，兼容capacitor的Android、iOS等主流移动平台及浏览器环境，本文档只说明在OpenHarmony系统中的使用。\r\n\r\nAPI 允许对设备键盘进行显示与隐藏控制，同时支持监听键盘弹出和收起时的事件，满足应用中键盘交互的各类场景需求。\r\n\r\n## 支持平台\r\n\r\n- **OpenHarmony**：5.0+\r\n\r\n## 下载安装\r\n\r\n通过命令行或手动引入即可快速安装插件，支持从npm仓库获取。\r\n\r\n### 命令行安装（推荐）\r\n\r\n安装hionic CLI：\r\n\r\n```bash\r\nnpm install -g hionic\r\n```\r\n\r\n以下两种方式中**任选其一**即可，无需重复操作：\r\n\r\nnpm安装：\r\n\r\n```bash\r\n# 安装插件\r\nnpm i @capacitor/keyboard\r\n\r\n# 同步插件\r\nhionic sync openharmony\r\n```\r\n\r\nhionic CLI安装：\r\n\r\n```bash\r\nhionic plugin add @capacitor/keyboard\r\n```\r\n\r\n### 手动引入安装\r\n\r\n根据插件源码中 `plugin.xml` 配置在项目中引入插件：\r\n\r\n#### 1. 添加插件配置\r\n\r\n根据 `plugin.xml` 的 `config-json` 项，通过 `target` 字段找到 `entry` 模块中 `capacitor.plugins.json` 文件，并根据 `param`\r\n标签添加配置如下：\r\n\r\n```json\r\n[\r\n  {\r\n    \"pkg\": \"@capacitor/keyboard\",\r\n    \"classpath\": \"Keyboard\"\r\n  }\r\n]\r\n```\r\n\r\n#### 2. 修改 CMake 配置\r\n\r\n根据 `plugin.xml` 的 `CMakeLists` 项，通过 `modules-name` 字段找到模块 `capacitor`，路径为 `target` 字段的\r\n`CMakeLists.txt` 文件，并添加 `add_subdirectory` 和 `target_link_libraries` 如下：\r\n\r\n```cmake\r\n#START_ADD_SUBDIRECTORY\r\n// ...\r\nadd_subdirectory(Keyboard)\r\n// ...\r\n#END_ADD_SUBDIRECTORY\r\n\r\n// ...\r\n\r\ntarget_link_libraries(capacitor PUBLIC\r\n  \"-Wl,--whole-archive\"\r\n  // ...\r\n  Keyboard\r\n  // ...\r\n  \"-Wl,--no-whole-archive\"\r\n)\r\n```\r\n\r\n#### 3. 复制源码文件\r\n\r\n根据 `plugin.xml` 的 `source-file` 项，根据 `src` 字段找到需要复制的文件，并根据 `modules-name` 字段和 `target-dir`\r\n字段找到文件复制的具体模块和目录：\r\n\r\n将源码中src/main/cpp/Keyboard目录下的Keyboard.h、Keyboard.cpp、CMakeLists.txt文件引入到capacitor模块中src/main/cpp/Keyboard目录下。\r\n\r\n将源码中src/main/ets/components/Keyboard目录下的Keyboard.ets文件引入到capacitor模块中src/main/ets/components/Keyboard目录下。\r\n\r\n#### 4. 添加 ArkTS 配置\r\n\r\n在`capacitor`模块的`build-profile.json5`文件中，`buildOption/arkOptions/runtimeOnly/sources`配置项数组中加入步骤 3 中拷贝的\r\nets 文件路径：\r\n\r\n```json\r\n{\r\n  \"buildOption\": {\r\n    // ...\r\n    \"arkOptions\": {\r\n      \"runtimeOnly\": [\r\n        // ...\r\n        \"./src/main/ets/components/Keyboard/Keyboard.ets\"\r\n        // ...\r\n      ]\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n## 卸载\r\n\r\n```bash\r\n# 卸载 keyboard 插件\r\nhionic plugin remove @capacitor/keyboard\r\n```\r\n\r\n## 约束与限制\r\n\r\n### 兼容性\r\n\r\n在以下版本中已测试通过：\r\n\r\n- capacitor: 8.0.0-ohos-8.0.0; SDK: 5.0.5(17); IDE: DevEco Studio: 6.0.0; ROM: 5.1.0.150;\r\n\r\n### 权限要求\r\n\r\nOpenHarmony系统中，键盘控制相关操作无需额外申请权限，插件可直接调用相关API实现功能。\r\n\r\n## 使用示例\r\n\r\n### 示例1：显示键盘\r\n\r\n```typescript\r\nimport { Keyboard } from '@capacitor/keyboard';\r\n\r\nconst handleShowKeyboard = async () => {\r\n  try {\r\n    // 使用capacitor Keyboard插件显示键盘\r\n    await Keyboard.show();\r\n\r\n    apiButtonSectionRef.value?.updateButtonResult('show-keyboard', {\r\n      message: '键盘显示命令已发送（仅Android支持）',\r\n      status: 'success'\r\n    });\r\n  } catch (error) {\r\n    const errorMsg = error instanceof Error ? error.message : String(error);\r\n    apiButtonSectionRef.value?.updateButtonResult('show-keyboard', {\r\n      message: `显示键盘失败: ${errorMsg}`,\r\n      status: 'error'\r\n    });\r\n  }\r\n};\r\n```\r\n\r\n### 示例2：隐藏键盘\r\n\r\n```typescript\r\nimport { Keyboard } from '@capacitor/keyboard';\r\n\r\nconst handleHideKeyboard = async () => {\r\n  try {\r\n    // 使用capacitor Keyboard插件隐藏键盘\r\n    await Keyboard.hide();\r\n\r\n    apiButtonSectionRef.value?.updateButtonResult('hide-keyboard', {\r\n      message: '键盘隐藏命令已发送',\r\n      status: 'success'\r\n    });\r\n  } catch (error) {\r\n    const errorMsg = error instanceof Error ? error.message : String(error);\r\n    apiButtonSectionRef.value?.updateButtonResult('hide-keyboard', {\r\n      message: `隐藏键盘失败: ${errorMsg}`,\r\n      status: 'error'\r\n    });\r\n  }\r\n};\r\n```\r\n\r\n### 示例3：添加键盘监听事件\r\n\r\n```typescript\r\nimport { Keyboard } from '@capacitor/keyboard';\r\n\r\nconst handleAddListeners = async () => {\r\n  try {\r\n    // 使用capacitor Keyboard插件添加键盘事件监听器\r\n    Keyboard.addListener('keyboardWillShow', (info) => {\r\n      console.log('键盘即将显示:', info);\r\n    });\r\n\r\n    Keyboard.addListener('keyboardDidShow', (info) => {\r\n      console.log('键盘已显示:', info);\r\n    });\r\n\r\n    Keyboard.addListener('keyboardWillHide', () => {\r\n      console.log('键盘即将隐藏');\r\n    });\r\n\r\n    Keyboard.addListener('keyboardDidHide', () => {\r\n      console.log('键盘已隐藏');\r\n    });\r\n\r\n    apiButtonSectionRef.value?.updateButtonResult('add-listeners', {\r\n      message: '键盘事件监听器已添加',\r\n      status: 'success'\r\n    });\r\n  } catch (error) {\r\n    const errorMsg = error instanceof Error ? error.message : String(error);\r\n    apiButtonSectionRef.value?.updateButtonResult('add-listeners', {\r\n      message: `添加键盘事件监听器失败: ${errorMsg}`,\r\n      status: 'error'\r\n    });\r\n  }\r\n};\r\n```\r\n\r\n### 示例4：移除所有键盘监听事件\r\n\r\n```typescript\r\nimport { Keyboard } from '@capacitor/keyboard';\r\n\r\nconst handleRemoveAllListeners = async () => {\r\n  try {\r\n    // 使用capacitor Keyboard插件移除所有键盘事件监听器\r\n    await Keyboard.removeAllListeners();\r\n\r\n    apiButtonSectionRef.value?.updateButtonResult('remove-listeners', {\r\n      message: '所有键盘事件监听器已移除',\r\n      status: 'success'\r\n    });\r\n  } catch (error) {\r\n    const errorMsg = error instanceof Error ? error.message : String(error);\r\n    apiButtonSectionRef.value?.updateButtonResult('remove-listeners', {\r\n      message: `移除键盘事件监听器失败: ${errorMsg}`,\r\n      status: 'error'\r\n    });\r\n  }\r\n};\r\n```\r\n\r\n## 使用说明\r\n\r\nKeyboard是插件导出对象，可直接导入使用，导入后即可调用插件提供的所有方法，调用便捷高效，所有API均基于Promise实现，支持异步调用。\r\n\r\n| 方法名                                                                                    | 返回类型                                                         | 描述            | 备注           |\r\n|----------------------------------------------------------------------------------------|--------------------------------------------------------------|---------------|--------------|\r\n| show()                                                                                 | Promise&lt;void&gt;                                          | 显示键盘          | 仅Android支持   |\r\n| hide()                                                                                 | Promise&lt;void&gt;                                          | 隐藏键盘          | 无            |\r\n| addListener(eventName: 'keyboardWillShow', listenerFunc: (info: KeyboardInfo) => void) | Promise&lt;[PluginListenerHandle](#pluginlistenerhandle)&gt; | 监听键盘即将弹出的事件   | 从API20之后开始支持 |\r\n| addListener(eventName: 'keyboardDidShow', listenerFunc: (info: KeyboardInfo) => void)  | Promise&lt;[PluginListenerHandle](#pluginlistenerhandle)&gt; | 监听键盘弹出的事件     | 从API18之后开始支持 |\r\n| addListener(eventName: 'keyboardWillHide', listenerFunc: (info: KeyboardInfo) => void) | Promise&lt;[PluginListenerHandle](#pluginlistenerhandle)&gt; | 监听键盘即将隐藏的事件   | 从API20之后开始支持 |\r\n| addListener(eventName: 'keyboardDidHide', listenerFunc: (info: KeyboardInfo) => void)  | Promise&lt;[PluginListenerHandle](#pluginlistenerhandle)&gt; | 监听键盘隐藏的事件     | 从API18之后开始支持 |\r\n| removeAllListeners()                                                                   | Promise&lt;void&gt;                                          | 移除该插件的所有原生监听器 | 无            |\r\n\r\n### 数据结构\r\n\r\n#### PluginListenerHandle\r\n\r\n| 属性     | 类型                        | 描述         |\r\n|--------|---------------------------|------------|\r\n| remove | () => Promise&lt;void&gt; | 移除当前监听器的方法 |\r\n\r\n#### KeyboardInfo\r\n\r\n| 属性             | 类型     | 描述           |\r\n|----------------|--------|--------------|\r\n| keyboardHeight | number | 键盘的高度（单位：像素） |\r\n\r\n## 目录结构\r\n\r\n```plaintext\r\n|---- 目录\r\n|     |---- src/main  # 插件的实现代码\r\n|           |----cpp  # C++ 代码\r\n|           |----ets   # ArkTS 代码\r\n|     |---- README.md          # 说明文档\r\n|     |---- package.json       # 配置文件\r\n|     |---- plugin.xml         # 插件配置文件\r\n```\r\n\r\n## 贡献代码\r\n\r\n使用过程中发现任何问题都可以提 [Issue](https://gitcode.com/CPF-Ionic/capacitor-keyboard/issues)\r\n，当然，也非常欢迎发 [PR](https://gitcode.com/CPF-Ionic/capacitor-keyboard/pulls) 共建。\r\n\r\n## 许可证\r\n\r\n本插件基于 **MIT License** 开源，详见 [LICENSE](./LICENSE) 文件。","readmeFilename":"README.md"}