Skip to content

About

Touch-first embedded keyboard for Avalonia, built for small industrial touch screens.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

18 Commits

Folders and files

Repository files navigation

TouchKeyboard

English · 简体中文

Touch-first embedded software keyboard for small industrial touch screens. The input model is a pure .NET Standard 2.0 core; Avalonia 12 is the first frontend, and a WPF frontend is planned.

NuGet License: MIT

AnsiStyle full keyboard

Features

  • Field-aware surfaces. Ten input profiles decide which keys, separators, range checks and commit rules a field gets. A positive-integer field never shows a sign or a decimal point; a date field gets the matching separator.
  • Two keyboard geometries. AnsiStyle is a strict five-row, 15-unit ANSI layout and the default. PhoneHybrid is a four-row phone-style alternative with its own symbol page.
  • Numeric keypad. The 5×4 Numpad shares one grid across the general keypad and profile-restricted variants. Empty slots merge into their neighbour (0 widens, Confirm stretches) instead of rendering dead keys.
  • In-window overlay. The Avalonia host adds a scrim, field label/unit/error row, editor surface and a keyboard area that keeps its height between modes.
  • Touch-first interaction. No hover states; pointer capture, press feedback and long-press repeat for Backspace and caret keys.
  • Theming, fonts and sizing. Automatic light/dark follow, two built-in presets, a compact Style facade for scale, semantic colours and the font family, and a draggable panel. Platform-aware default font stacks keep Latin and CJK text readable on Windows, macOS and Linux, while hosts can plug in their own FontFamily.
  • Chinese or English key legends. KeyboardLanguage.English gives an all-English surface (Confirm, Clear, Symbols, CN/EN) for an English-only host; Auto follows the host culture. Geometry never changes.
  • Optional Chinese input. A managed pinyin engine, candidate bar, inline composition and language packs; the base package stays language-neutral.
  • Reusable core. Profiles, layouts, sessions, validation and IME composition are UI-free and testable without a display server.

Packages

Package Target framework Purpose
TouchKeyboard.Core netstandard2.0 Profiles, layouts, session, validation and IME composition. No UI dependencies.
TouchKeyboard.Avalonia net8.0;net10.0 Avalonia 12 overlay host, keys, editor surface, theme, localizer and adapters.
TouchKeyboard.Ime.Pinyin netstandard2.0 Optional managed pinyin engine and common lexicon.
TouchKeyboard.Ime.Pinyin.Extended netstandard2.0 Optional extended lexicon; reuses the common engine.

A WPF frontend is planned but not shipped.

Requirements

  • Avalonia 12.0.5 or newer (tested with 12.0.5 and 12.1.5) on .NET 8 or .NET 10.
  • TouchKeyboard.Core alone can be consumed from any netstandard2.0 project.
  • The default font is a platform-aware stack, but it does not bundle fonts. A CJK font is still required for Chinese characters in fields and candidates; minimal Linux images should install Noto Sans CJK SC (or another CJK face).

Quick start

1. Install

dotnet add package TouchKeyboard.Avalonia

2. Add the host and mark fields

Place TouchKeyboardHost last in the window's root grid so its scrim covers the page. The attached properties select a profile and provide the header text:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:tk="using:TouchKeyboard.Avalonia">
  <Grid>
    <StackPanel Margin="16" Spacing="12">
      <TextBox tk:TouchKeyboardInput.Profile="text"
               tk:TouchKeyboardInput.Label="Name" />

      <NumericUpDown tk:TouchKeyboardInput.Profile="positive-decimal"
                     tk:TouchKeyboardInput.Label="Temperature"
                     tk:TouchKeyboardInput.Unit="℃"
                     Minimum="0" Maximum="100" Value="25" />

      <TextBox tk:TouchKeyboardInput.Profile="password"
               tk:TouchKeyboardInput.Label="Password"
               PasswordChar="*" />
    </StackPanel>

    <tk:TouchKeyboardHost x:Name="KeyboardHost" />
  </Grid>
</Window>

AutoAttach is enabled by default: the host creates a controller that watches pointer presses, resolves the target field, opens the panel and restores focus when it closes.

3. Configure

KeyboardHost below is the code-behind field generated by the x:Name in the XAML above; the control type is TouchKeyboardHost.

using Avalonia.Controls;
using TouchKeyboard.Avalonia;
using TouchKeyboard.Core;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        KeyboardHost.Configure(options =>
        {
            options.FullKeyboardLayout = FullKeyboardLayoutKind.AnsiStyle;
            options.KeyHeight = 64;
            options.MaxPanelWidth = 1100;
            options.Culture = "zh-CN";
        });
    }
}

See Avalonia integration for every option, adapter, localizer and troubleshooting topic.

Language and fonts

The letter geometry is the same in both languages; only named key legends, chrome strings and validation messages change.

using Avalonia.Media;
using TouchKeyboard.Avalonia;

KeyboardHost.Configure(options =>
{
    // Auto follows Culture (or the current UI culture). Pin one for an app
    // whose UI language is independent of the operating system.
    options.KeyLanguage = KeyboardLanguage.English;

    // Use the platform default stack, or plug in any Avalonia FontFamily.
    options.Style.FontFamily = new FontFamily("Noto Sans CJK SC");
});
Setting Default Effect
KeyLanguage Auto Built-in language for key legends, chrome and validation messages. Chinese = zh-CN, English = en-US, Auto = Culture then the current UI culture. A custom Localizer still wins.
Style.FontFamily null Overrides the font for key caps, the label/unit/error row, the editor and IME candidates. null keeps the resolved theme family.
TouchKeyboardTheme.FontFamily TouchKeyboardFonts.Default Font of the full theme. Style.FontFamily is the small, theme-independent override.

Platform defaults come from TouchKeyboardFonts.Windows (Segoe UI, Microsoft YaHei UI, Microsoft YaHei), TouchKeyboardFonts.MacOS (Helvetica Neue, PingFang SC, Hiragino Sans GB) and TouchKeyboardFonts.Linux (Noto Sans, Noto Sans CJK SC, WenQuanYi Micro Hei, DejaVu Sans). The English surface uses Confirm/Clear/Symbols and the IME toggle shows CN/EN; the Chinese surface uses 确定/清空/符号 and 中/英.

Input profiles

Profile id Default surface Accepts
text Full keyboard Any text without control characters.
password Full keyboard Printable ASCII.
ascii-token Full keyboard A–Z a–z 0–9 / _ . : -, non-empty.
integer Numeric keypad Signed integer.
positive-integer Numeric keypad Digits only.
decimal Numeric keypad Signed decimal with ..
positive-decimal Numeric keypad Non-negative decimal with ..
date-slash Numeric keypad yyyy/M/d parts; commits yyyy/MM/dd.
date-dot Numeric keypad yyyy.M.d parts; commits yyyy/MM/dd.
ip-address Numeric keypad Four 1–3 digit parts, 0–255.

Only text allows the optional IME by default. Custom profiles can opt in with AllowsIme. See Input profiles for the contract, validation codes and numeric slot mapping.

Layouts

AnsiStyle is the default full keyboard: five rows of exactly 15 units, with Tab and Caps kept as non-interactive spacers and no F-keys, NumLock keypad block, Ctrl/Alt/Win combinations or system keys. When no IME key is present, Space expands over the IME slot. With an engine and an IME-capable profile, the slot holds an IME key (中/英, or CN/EN in English) and Space returns to its base width.

PhoneHybrid is a four-row phone-style letters keyboard with a symbol/numeric entry and a full-keyboard-owned symbol page. The symbol page is a 4×8 grid with the full 32-symbol ANSI set plus a function row (ABC 123 ← Space → Clear ⌫ Confirm). With an IME engine, the Clear slot becomes the IME toggle and mapped symbol caps follow the active language; the numeric mode uses the 5×4 Numpad; profile-restricted keypads omit invalid keys and merge the freed cells into 0 or Confirm.

Profile-restricted numeric keypad

Chinese pinyin composition

See Layouts for every row, the Numpad slot table, the symbol page and the theme metrics.

Optional Chinese input

dotnet add package TouchKeyboard.Ime.Pinyin
using TouchKeyboard.Avalonia;
using TouchKeyboard.Ime.Pinyin;

KeyboardHost.Configure(options => options.UseIme(new PinyinImeEngine()));

text fields get an IME key (中/英, or CN/EN in English), a fixed candidate row and inline composition. Numeric, date, password and ASCII profiles stay IME-free. Without an engine there is no IME key or candidate row and Space keeps the expanded no-IME width. The extended pack only changes the engine type:

using TouchKeyboard.Ime.Pinyin.Extended;

KeyboardHost.Configure(options => options.UseIme(new ExtendedPinyinImeEngine()));

The engine is managed and dictionary-based; it does not bridge the system IME or inject keys. See Chinese input for options, interaction rules, theming, localization and troubleshooting.

Behavior

  • Editing happens in the session buffer. Confirm/Enter validates and writes the value back; closing the panel, clicking the scrim or pressing Escape always discards.
  • The field label, unit and validation error are shown above the editor.
  • The overlay follows the window's light/dark variant by default; set options.Theme to pin a preset.
  • Physical keyboard input is handled while the panel is open when HandlePhysicalKeyboard is enabled (default).
  • Built-in adapters cover TextBox, NumericUpDown and CalendarDatePicker; custom controls can register an IEditorAdapter.
  • The default editor is custom-drawn, which keeps the platform on-screen keyboard from covering the panel. A host that needs native text semantics can inject its own IEditorSurface.

Customization

using Avalonia.Media;

KeyboardHost.Configure(options =>
{
    options.Style.Scale = 0.9;
    options.Style.FontScale = 1.0;
    options.Style.IconScale = 1.1;
    options.Style.AccentColor = Color.Parse("#FF0F766E");
    options.Style.ConfirmTextColor = Colors.White;
    options.EnablePanelDrag = true;
});

Style applies scale and semantic colours on top of the resolved preset. For full control over brushes and metrics use options.Theme. Long-press the title row to drag the panel inside the window; TouchKeyboardHost.ResetPanelPosition() restores the default position. See Appearance, fonts and sizing.

Documentation

  • Avalonia integration — setup, options, adapters, language, fonts, theming, troubleshooting.
  • Input profiles — built-in profiles, validation rules, numeric slots.
  • Layouts — AnsiStyle/PhoneHybrid geometry, symbol page, Numpad grid.
  • Chinese input — optional pinyin packs, candidate bar, data and licensing.
  • Appearance, fonts and sizing — scale, fonts, semantic colours, themes, panel dragging.
  • Public API — API inventory, compatibility policy and extension seams.
  • Architecture — projects, core model, data flow and frontend responsibilities.
  • Demo — runnable Avalonia sample.
  • Changelog.

For contributors: CONTRIBUTING.md, AGENTS.md (documentation language), release runbook, architecture decision records, device acceptance checklist and the roadmap.

Compatibility and limitations

  • Platforms: Windows, Linux and macOS through Avalonia desktop; touch and mouse input. Avalonia 11 is not supported. Basic real-device acceptance was completed on all three platforms in November 2026; platform-specific details should be reported through the GitHub issue templates and tracked against the device checklist.
  • Single-line editor: no selection, clipboard, undo/redo or multi-line layout. Editing is always confirmed or discarded as a whole.
  • No desktop key block: no F1–F12, NumLock keypad block, Ctrl/Alt/Win/Menu combinations or system keys.
  • Managed IME only: the optional pinyin engine covers full pinyin, word/sentence segmentation and common abbreviations. It does not provide Wubi, handwriting, fuzzy pinyin, cloud input, user learning or Traditional/Simplified conversion. Candidate quality is best-effort.
  • No system IME bridge or key injection. The keyboard edits its own session buffer and commits through the adapter.
  • WPF is not implemented. The core is UI-free so a second frontend can reuse it.
  • Validation: unit, pinyin and Avalonia headless suites run on every CI build. Basic real-device acceptance is complete on Windows, Linux and macOS. Platform-specific details, edge-case DPI/OSK behaviour and any remaining checklist items should be reported as GitHub issues before deployment.

License

Code is MIT; see LICENSE. Optional language data uses only permissive or attribution licences (Unicode License V3 for Unihan readings, MIT for the jieba word list) and ships with a NOTICE in each language package. No share-alike, copyleft, proprietary or unknown-provenance data is included.

The software and data are provided as-is; no input-quality or stability guarantee is made.

About

Touch-first embedded keyboard for Avalonia, built for small industrial touch screens.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages