KidsCareer.Controls.KeyBoard 1.0.2

dotnet add package KidsCareer.Controls.KeyBoard --version 1.0.2
                    
NuGet\Install-Package KidsCareer.Controls.KeyBoard -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KidsCareer.Controls.KeyBoard" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KidsCareer.Controls.KeyBoard" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="KidsCareer.Controls.KeyBoard" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KidsCareer.Controls.KeyBoard --version 1.0.2
                    
#r "nuget: KidsCareer.Controls.KeyBoard, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KidsCareer.Controls.KeyBoard@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KidsCareer.Controls.KeyBoard&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=KidsCareer.Controls.KeyBoard&version=1.0.2
                    
Install as a Cake Tool

KidsCareer.Controls.KeyBoard

专为儿童教育软件设计的轻量级 WPF 虚拟键盘控件,支持中英文输入、拼音候选词与手写识别。输入框获得焦点即自动弹出软键盘,无需外接物理键盘,非常适合触摸屏、一体机等儿童使用场景。

功能特性

  • 🅰️ 中英文输入:字母键盘 + 拼音候选词,可在中/英文模式间切换
  • ✍️ 手写识别:内置手写板,基于系统手写引擎识别汉字(依赖 Microsoft.Ink)
  • 🎯 焦点自动显隐:输入框获得焦点自动弹出,点击空白处或离开输入框自动收起
  • 🌲 全局一键启用:一个附加属性即可让 Window / Page / UserControl 下的所有输入框(含导航页、模板、运行时动态生成的控件)自动获得软键盘
  • 🎛️ 逐控件精确控制:也可只给指定 TextBox 启用
  • 🔠 完整按键:CapsLock / Shift / Backspace / Tab / Enter / Space 均可用
  • 📄 候选词分页:拼音候选词支持翻页浏览

系统要求

  • .NET Framework 4.7.2(NuGet 包目标框架 lib\net472)
  • WPF 应用程序
  • 手写识别需目标机器安装系统手写识别组件(Win10/11 默认含中文手写)

安装

通过 NuGet 包管理器:

Install-Package KidsCareer.Controls.KeyBoard

或在 Visual Studio 的 NuGet UI 中搜索 KidsCareer.Controls.KeyBoard 安装。

包内已随附 Microsoft.Ink.dll,一般无需额外引用。

快速开始

1. 引入命名空间

在 XAML 根元素上声明命名空间:

xmlns:kb="clr-namespace:KidsCareer.Controls.KeyBoard;assembly=KidsCareer.Controls.KeyBoard"

2. 全局启用(推荐)

把 AutoEnable 挂在根元素上,其下所有输入框都会自动弹出键盘。支持 Window、Page、UserControl:


<Window ...
        xmlns:kb="clr-namespace:KidsCareer.Controls.KeyBoard;assembly=KidsCareer.Controls.KeyBoard"
        kb:KeyboardHelper.AutoEnable="True">
    ...
</Window>

<Page ... kb:KeyboardHelper.AutoEnable="True"> ... </Page>
<UserControl ... kb:KeyboardHelper.AutoEnable="True"> ... </UserControl>

3. 逐控件启用

只想给个别输入框启用时:

<TextBox kb:KeyboardHelper.IsKeyboardEnabled="True" />

两种用法可共存,互不冲突。

4. 显示与隐藏

无需手动调用,均由焦点驱动:

  • 弹出:输入框获得焦点时自动弹出,并定位到输入框下方(超出屏幕时自动上移/贴边)
  • 收起:点击键盘和输入框以外的区域,或焦点离开输入框时自动隐藏

使用建议

  • 面向触摸屏 / 儿童一体机时,推荐直接在主窗口上开 AutoEnable="True",省去逐个控件配置。
  • 键盘窗口不抢占激活焦点(ShowActivated=false),不会与宿主窗体争夺前后顺序。
  • 目前文本回填支持 TextBox;PasswordBox / RichTextBox 会弹出键盘,但文本回填为既有限制。

常见问题

Q:Page / UserControl 里的 TextBox 弹不出键盘? A:确认 AutoEnable 已挂在该 Page / UserControl(或其所在 Window)的根元素上。当前实现基于冒泡的逻辑焦点路由事件,能覆盖导航页、模板与动态生成的控件。

Q:键盘弹出后闪烁或关不掉? A:请使用本包的自动显隐机制,不要对键盘窗口另行调用 Activate();显隐由逻辑焦点驱动,避免与宿主窗体争夺键盘焦点。

Q:手写识别不可用或不准? A:手写识别调用系统手写引擎,请确保目标系统已安装中文手写识别组件,并尽量规范书写。

Q:能否不依赖 Microsoft.Ink? A:识别层已抽象为 ICharactorRecognizer 接口,可替换为基于 WinRT InkRecognizerContainer 或 System.Windows.Ink.InkAnalyzer 的实现以移除该依赖(规划中)。

版本历史

1.0.2

  • 修复 CapsLock(大写锁定)按钮不生效的问题
  • 修复自动弹出键盘时可能出现的双实例 / 定位错乱问题
  • AutoEnable 全局启用改为基于逻辑焦点路由事件,现可覆盖 Page / UserControl / 导航页 / 模板 / 动态生成的输入控件
  • 修复弹出键盘闪烁、无法关闭的问题(不再抢占激活焦点)
  • 新增 KeyBoard.KeyPressed 事件,便于扩展自定义输入转发
  • 手写候选词保留词组结果(原实现仅保留单字)

1.0.0

  • 初始版本:中英文输入、拼音候选词、手写输入

许可证

本项目采用 MIT 许可证,详见 LICENSE。

Product Compatible and additional computed target framework versions.
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 115 7/23/2026
1.0.0 218 9/3/2025