A modern, privacy-respecting custom keyboard (input method editor) for Android, built with Kotlin and Jetpack Compose. ZnKeyboard pairs a fast custom typing surface with a built‑in AI rewrite assistant that polishes your text in place using your own OpenAI (or OpenAI‑compatible) API key.
Status: actively developed. Built and maintained in the open.
Most "AI keyboards" send your keystrokes to a vendor's cloud. ZnKeyboard takes the opposite stance:
- Bring your own key. AI features call your own OpenAI / OpenAI‑compatible endpoint. There is no ZnKeyboard backend in the middle.
- Keys never leave the device in plaintext. API keys are encrypted at rest with the Android Keystore (AES/GCM). A user-created backup can include them only inside a password-encrypted file.
- AI is opt‑in. The keyboard is fully usable with the agent disabled; nothing is sent anywhere unless you turn it on and trigger it.
ZnKeyboard learns how your thumbs actually hit each key and decodes every tap with that, instead of plain rectangles. The full research and numbers are in docs/typing-accuracy.md.
- Key decided at touch-down with roll hysteresis, so finger drift on lift no longer types the neighbouring key.
- A personal touch model for each key (per orientation), with hierarchical shrinkage so rare keys learn from their neighbours.
- Learns from your corrections: backspacing a letter and typing its neighbour teaches the model where that tap really belonged. There is no calibration step.
- Anchored letter prior: context only settles taps that fall between keys. A tap on the centre of a key always types that key. The prior adapts to how you write, Hinglish included.
- Haptics and a key popup so you can feel and see each keystroke. Shift tap/double-tap caps lock, auto-capitalisation, and double-space period.
- See what it learned: Settings → Typing has a "Try it" field and a per-key touch map showing each key's learned centre and spread.
- In simulation, letter errors drop from about 8% to about 1.3%. Learning stays on the device, is never backed up, and is skipped in password and incognito fields.
Type kaise ho and get कैसे हो, entirely on the device, with Lekhani by Udgam Labs: a 0.88 MB transliteration model with a 200,000-word list.
- One switch: add the
अkey to a shortcut row (or use Settings → Typing). The spacebar readsहिन्दीwhile Hindi mode is on. It's skipped in password, URL and email fields. - Converts as you finish each word: the Latin word stays underlined while you type it. Space, punctuation or Enter swaps in the best Devanagari spelling.
- Fix a word in one tap: the suggestion strip shows the best spelling and the runner-up. Tapping one replaces the word, even right after it was converted. Backspace right after a conversion brings the Latin word back.
- Learns your picks: the spelling you last picked for a word comes first next time. Learned picks are stored in no-backup storage and are included in encrypted exports.
- Only in memory while it's on: the model loads in the background when you switch Hindi mode on and is unloaded when you switch it off.
- Limits: it handles one word at a time (
mainandmeinboth giveमें; pickमैंfrom the strip), Hindi only, and gets about two words in three right as its first choice on a hard benchmark.
Add the Scan text key to a shortcut row. Tapping it turns the keys into a camera viewfinder; tap the shutter and the text in view is typed into the field.
- On the device: PP-OCRv6 Small on LiteRT (CPU), about 1–1.5 s per capture. Strong on printed text, numbers and handwriting.
- Downloads on first use: the 77 MB model isn't in the APK. The first Scan offers a one-time download from a pinned Hugging Face revision, SHA-256 verified and kept in no-backup storage. Delete it from Settings → Tools → Scan text.
- Only in memory while the camera is open: the camera and model are released as soon as you leave the viewfinder or switch fields.
- Line breaks are kept in multi-line fields and become spaces in single-line ones.
- English only: the recognizer can only emit English letters, digits and common symbols, and drops low-confidence lines, so other scripts don't turn into noise.
- Freezes on tap: the viewfinder freezes the moment you tap (zero-shutter-lag capture), so you can move the phone away while it reads.
- Limits: no Hindi/Devanagari or other scripts, and reading order across multiple columns can get mixed up.
- Compare OCR engines (Settings → Tools → Scan text) compares PP-OCRv6 on CPU and GPU with Google ML Kit on the same capture, in a separate process.
- Rewrite, polish, or restructure the text in the current field with one tap, then review the result before it replaces anything.
- Use your own provider: OpenAI by default (
api.openai.com/v1), or any OpenAI‑compatible endpoint such as OpenRouter, with a configurable model (defaultgpt-4o-mini). - App‑aware prompts: rewrites adapt to where you are typing — e.g. a dedicated WhatsApp profile that preserves casual Romanized Hindi/Urdu code‑switching instead of flattening it.
- Structured, safe output: the model is constrained to a JSON
{ "text": ... }contract, with optional reasoning modes for compatible models. - Encrypted key storage via the Android Keystore.
Turn the keyboard into your keyboard. Add and arrange extra shortcut rows from a deep menu of keys most keyboards never give you:
- Cursor & navigation: arrow keys,
Home/End,PgUp/PgDn,Del. - Modifiers & control:
Ctrl,Alt,Tab,Esc(latched only for the dispatched action). - Custom macros: chain any key combos (
Ctrl/Alt/Shift+ letters, digits, F-keys, arrows…) and typed text into one key, e.g. tmuxC-b nor VimEsc›:wq›Enter. tmuxC-b,C-b n,C-b pship as editable starters. - Every symbol: all ASCII punctuation plus
€,£,¥,•. - Panel shortcuts: jump straight to emoji, GIF, clipboard, or snippets, or Save snippet to store the current field in one tap.
- Dedicated Shortcuts screen with a live preview of both rows, a categorized key palette (tap to add, tap again to remove), swappable row order, and a confirmation before a row is reset to defaults.
- A suggestion strip is always reserved above the shortcut rows, so the keyboard never jumps when suggestions appear. It shows up to three snippet completions, or in Hindi mode the best spelling, the runner-up and one snippet.
- Shortcut rows and the suggestion strip never change the height of the letter keys, so your muscle memory stays put.
- Assign your own tags to any emoji (e.g. tag 🫡 as "ok", "done", "got it").
- Tagged emojis surface in search and as a one‑tap contextual suggestion right on the keyboard, so the emojis you actually use are always a tap away — no scrolling.
- Tap the suggestion right after the word to swap the word for the emoji (
done|→ ✅); add a space first to keep both (done |→done ✅). - Plus a full emoji panel with search, skin‑tone variants, and recents.
- Recent copies are kept on a dedicated panel for quick re‑pasting — no more re‑copying the same address, code, or link.
- On‑device only.
- Optional Ferry integration: with the Ferry companion app installed, swipe a history item to Send to Mac, and clips sent from your Mac show up labelled with the Mac's name. Without Ferry, nothing changes.
- Save reusable phrases, templates, and boilerplate from settings, the snippet panel, or a Save snippet shortcut key.
- Snippets autocomplete as you type: start typing a saved snippet and tap the suggestion to finish it.
- Tag and search snippets so the right one is instantly findable — ideal for canned replies, email sign‑offs, addresses, or code stubs.
- Custom high‑performance typing
View(not a WebView, not Compose on the hot path) with press feedback tuned to feel like a stock key. - Gboard‑style spacebar cursor dragging for precise caret movement, with a haptic tick per character.
- Material You theme that follows your wallpaper and light/dark mode, or a true-black Classic black theme. Adjustable key height (extra rows add to the keyboard instead of shrinking keys), space below the keys, and optional filled modifier keys.
- Selection‑aware deletion and correct editor‑action handling (
Done,Go,Next,Search,Send, etc.). - GIF picker powered by KLIPY, with on‑device caching and content filtering.
- Password-encrypted backup & restore for settings, clipboard history, learned typing, and configured API credentials.
The settings app is edge-to-edge: content scrolls behind a floating title pill and a floating nav bar. The selected tab is its own accent pill. Switching tabs makes it pinch off like a drop of liquid, and the old tab flows back into its group.
- No built-in API could do this. Android's shape morphing only turns one outline into another, and a drop goes from one shape to two. So the bar has a small engine of its own, now its own open-source library: Meniscus.
- Based on how real liquid behaves: the neck between pills is drawn as circular arcs, which is the shape liquid takes in 2D. The neck thins faster just before it snaps, and a new bridge grows fast at first when two pills merge.
- Pure-Kotlin physics core: exact damped springs on a fixed 500 Hz step, so the motion is the same on 60, 90 and 120 Hz screens. Tapping another tab mid-animation continues smoothly from wherever it is.
- AGSL shader renderer: crisp 1px anti-aliased edges and a thin outline that wraps the neck as it stretches. Icons and labels sit in a separate layer, so they stay sharp. No per-frame allocation.
- The bar's outer bottom corners follow your phone's rounded screen corners. It respects the system animation scale, TalkBack tab semantics, RTL, and light/dark themes.
- Tune the motion in the Meniscus playground, which runs the same engine and shader in a browser.
Single‑module Android app (:app), package dev.zain.znkeyboard.
| Layer | What it does |
|---|---|
ime/ZnKeyboardInputMethodService |
The InputMethodService entry point; owns the input lifecycle and InputConnection. |
ime/ZnKeyboardView |
The custom keyboard surface — drawing, touch handling, gestures. |
ime/AgentReviewView + prompt assets |
AI rewrite UI and the OpenAI request/response flow. |
ime/*PanelView (emoji, GIF, clipboard, snippet) |
The expression and productivity panels. |
ime/OcrCameraPanelView + ocrlab/ppocr/ |
Camera text scanning: CameraX viewfinder panel, the model downloader (OcrModelStore), and the PP-OCRv6 LiteRT runtime (PpOcrEngine) with OpenCV-free box/crop geometry (TextGeometry). ocrlab/OcrLabActivity is the engine comparison screen. |
SettingsActivity (Jetpack Compose, Material 3) |
Edge-to-edge settings app with a floating title pill, five tabs (Typing, Layout, Tools (AI / GIF), Snippets, Backup) and the Meniscus nav bar. |
ShortcutsScreen + ShortcutMacros |
Shortcut row editor, key palette, and macro definitions/dispatch. |
translit/ |
Hindi transliteration: LekhaniTransliterator (pure-Kotlin port of the Lekhani runner), HindiPicks (learned spellings), and HindiTransliterationEngine (asset loading, background thread, load/unload). ime/HindiComposer handles composing, conversion and undo. |
typing/ |
Adaptive touch decoding (TouchModel, CharLanguageModel, TouchDecoder, TypingLearner) in pure Kotlin, wired up by AdaptiveTypingEngine. |
KeyboardSettings |
Single source of truth for persisted settings and encrypted secrets. |
integrations/ |
Optional companion-app hooks (KeyboardIntegrations), currently Ferry's "Send to Mac". The keyboard works the same without them. |
constants/ |
Centralized dimensions, colors, and defaults. |
Hot paths (onDraw, onTouchEvent, input dispatch) deliberately avoid allocation, I/O, and blocking work.
Requirements:
- Android Studio (recent stable) or the Android SDK command‑line tools
- JDK 17
- Android SDK with API 36;
minSdkis 36 (Android 16)
# Point Gradle at your SDK
echo "sdk.dir=$HOME/Library/Android/sdk" > local.properties
# Build a debug APK
./gradlew :app:assembleDebug
# Verify the adaptive typing engine (unit checks + simulated-typist comparison)
curl -sSLO https://norvig.com/ngrams/count_1w.txt
tools/typing/verify_engine.sh count_1w.txt
Install on a connected device/emulator with ./gradlew :app:installDebug (or adb install -r).
Release builds are signed from ~/.android/keystores/zn-keyboard-release.properties (storeFile, storePassword, keyAlias, keyPassword; storeFile is relative to that file). Without it, ./gradlew :app:assembleRelease produces an unsigned APK. An update only installs over an existing app signed with the same key.
- Open the ZnKeyboard app and follow the prompt, or go to Settings → System → Languages & input → On‑screen keyboard → Manage keyboards and enable ZnKeyboard.
- Switch to it from any text field via the keyboard switcher.
- Tap any editable field to start typing.
- Open ZnKeyboard settings → Tools tab.
- Choose a provider (OpenAI or OpenRouter), paste your API key, and pick a model.
- The key is encrypted with the Android Keystore and stored only on your device.
- Tap the Rewrite key on the shortcut row (there by default; re-add it from Layout → Shortcut rows & macros) and review the suggestion before it's applied.
You are billed directly by your chosen provider for your own usage; ZnKeyboard never proxies requests.
- No analytics, no telemetry, no third‑party SDKs for tracking.
- AI requests go straight from your device to the endpoint you configured, using your key.
- GIF search talks to KLIPY only while the GIF panel is open.
- Adaptive-touch learning stores only aggregate statistics (per-key touch offsets, letter-trigram counts) in no-backup storage (excluded from cloud backup, included only in password-encrypted exports), never in password or incognito fields, and can be reset from Settings → Typing.
- Hindi transliteration runs entirely on the device. Learned spellings are stored like adaptive-touch data (no-backup storage, encrypted exports only) and are never learned in password or incognito fields.
- Scan text runs entirely on the device; the only network use is the one-time model download from Hugging Face. Captures are never stored; the Camera OCR test screen saves its captures to
Download/ZnOcrLab/only while its "Save to Downloads" switch is on. - Settings and secrets stay on-device; secrets are encrypted at rest. User-created backups are encrypted with a password that is never saved by the app.
Issues and pull requests are welcome. Please:
- Keep changes aligned with the existing
InputMethodService+ customViewarchitecture. - Treat keyboard changes as device‑facing — verify typing behavior on a real field/device.
- Follow Kotlin / AndroidX / Material 3 conventions already in the codebase.
ZnKeyboard is licensed under the GNU General Public License v3.0. See LICENSE.
Copyright (C) 2026 Mohammad Zain Shaikh
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.




