Skip to content

KeyboardKit lets you create custom keyboards with a few lines of code, using Swift & SwiftUI.

License

Notifications You must be signed in to change notification settings

KeyboardKit/KeyboardKit

Repository files navigation

KeyboardKit Logo

Version Documentation Swift 5.9 MIT License

KeyboardKit

KeyboardKit lets you create amazing custom keyboard extensions with a few lines of code, using Swift & SwiftUI.

KeyboardKit extends Apple's limited keyboard APIs with more capabilities. It can be extended with KeyboardKit Pro, which unlocks localized keyboards, autocomplete, an emoji keyboard, AI support, themes, and much more.

Installation

KeyboardKit can be installed with the Swift Package Manager:

https://github.com/KeyboardKit/KeyboardKit.git

Getting Started

The easiest way to set up KeyboardKit is to first create a KeyboardApp value for your app:

extension KeyboardApp {

        static var keyboardKitDemo: KeyboardApp {
        .init(
            name: "KeyboardKit",
            licenseKey: "your-key-here",                // Sets up KeyboardKit Pro!
            appGroupId: "group.com.keyboardkit.demo",   // Sets up App Group data sync
            locales: .keyboardKitSupported,             // Sets up the enabled locales
            autocomplete: .init(                        // Sets up custom autocomplete  
                nextWordPredictionRequest: .claude(...) // Sets up AI-based prediction
            ),
            deepLinks: .init(app: "kkdemo://", ...)     // Defines how to open the app
        )
    }
}

Next, let your KeyboardController inherit KeyboardInputViewController instead of UIInputViewController:

class KeyboardController: KeyboardInputViewController {}

This unlocks additional functions and capabilities, and injects services and observable state to the controller.

Next, override viewDidLoad() and call setup(for:), or setupPro(for:) if you use KeyboardKit Pro:

class KeyboardViewController: KeyboardInputViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // KeyboardKit
        setup(for: .keyboardKitDemo)
        
        // 👑 KeyboardKit Pro
        setup(for: .keyboardKitDemo) { result in
            // If result is successful, KeyboardKit Pro is now active
            // You can now customize your keyboard and tweak features 
        }
    }
}

To replace or customize the standard KeyboardView view, just override viewWillSetupKeyboardView() and call setupKeyboardView(with:) with the view that you want to use:

class KeyboardViewController: KeyboardInputViewController {

    override func viewWillSetupKeyboardView() {
        setupKeyboardView { [weak self] controller in // <-- Use weak or unknowned self!
            KeyboardView(
                state: controller.state,
                services: controller.services,
                buttonContent: { $0.view },
                buttonView: { $0.view },
                collapsedView: { $0.view },
                emojiKeyboard: { $0.view },
                toolbar: { $0.view }
            )
        }
    }
}

To set up your main app with the same keyboard configuration, just wrap the content view in a KeyboardAppView:

@main
struct MyApp: App {

    var body: some Scene {
        WindowGroup {
            KeyboardAppView(for: .keyboardKitDemo) {
                ContentView()
            }
        }
    }
}

For more information, see the getting started guide and essentials articles.

Localization

KeyboardKit supports 71 keyboard-specific locales:

🇺🇸 🇦🇱 🇦🇪 🇦🇲 🇧🇾 🇧🇬 🇦🇩 🏳️ 🏳️ 🇭🇷
🇨🇿 🇩🇰 🇳🇱 🇧🇪 🇦🇺 🇨🇦 🇬🇧 🇺🇸 🇪🇪 🇫🇴
🇵🇭 🇫🇮 🇫🇷 🇨🇦 🇧🇪 🇨🇭 🇬🇪 🇩🇪 🇦🇹 🇨🇭
🇬🇷 🇺🇸 🇮🇱 🇭🇺 🇮🇸 🏳️ 🇮🇩 🇮🇪 🇮🇹 🇰🇿
🇹🇯 🇹🇯 🇹🇯 🇱🇻 🇱🇹 🇲🇰 🇲🇾 🇲🇹 🇲🇳 🏳️
🇳🇴 🇳🇴 🇮🇷 🇵🇱 🇵🇹 🇧🇷 🇷🇴 🇷🇺 🇷🇸 🇷🇸
🇸🇰 🇸🇮 🇪🇸 🇦🇷 🇲🇽 🇸🇪 🇰🇪 🇹🇷 🇺🇦 🇺🇿
🏴󠁧󠁢󠁷󠁬󠁳󠁿

KeyboardKit only includes localized strings, while KeyboardKit Pro unlocks localized keyboards, layouts, callouts and behaviors for all supported locales.

Features

KeyboardKit provides a free, open-source keyboard engine. KeyboardKit Pro unlocks more powerful pro features.

Open-Source

  • 🌱 Essentials - Essential keyboard utilities, models, services & views.
  • ⌨️ Essentials-KeyboardView - A native-looking, customizable keyboard.
  • 💥 Actions - Trigger & handle keyboard-related actions.
  • 📱 App - Set up your app, keyboard, sync settings, etc.
  • 🗯 Callouts - Show input & secondary action callouts.
  • 🖥️ Device - Identify device type, device capabilities, etc.
  • 😀 Emojis - Emojis, categories, versions, skin tones, etc.
  • 🔉 Feedback - Trigger audio & haptic feedback.
  • 👆 Gestures - Handle a rich set of gestures on any key.
  • 🔣 Layout - Define and customize dynamic keyboard layouts.
  • 🌐 Localization - Localize your keyboard in 71 locales.
  • 🗺️ Navigation - Open urls and other apps from the keyboard.
  • 👁 Previews - Extensive SwiftUI preview support.
  • 📄 Proxy - Extend the text document proxy with more capabilities.
  • ⚙️ Settings - Provide keyboard settings & link to System Settings.
  • 🩺 Status - Detect if a keyboard is enabled, has full access, etc.
  • 🎨 Styling - Style your keyboard to great extent.

KeyboardKit Pro

  • 🌱 Essentials - More essential tools, previews, toolbars, etc.
  • ⌨️ Essentials-KeyboardView - Make the keyboard view do a lot more.
  • 🤖 AI - Features that are needed for AI.
  • 📱 App - App-specific screens & views.
  • 💡 Autocomplete - Local & remote autocomplete, next word prediction, etc.
  • 🗯 Callouts - Localized callout actions for all supported locales.
  • 🎤 Dictation - Dictate text from the keyboard.
  • 😀 Emojis - A powerful emoji keyboard, search, etc.
  • ⌨️ External - Auto-detect if an external keyboard is connected.
  • 🏠 Host - Identify and open specific host applications.
  • 🔣 Layout - More input sets and layouts for all supported locales.
  • 🌐 Localization - Services & views for all supported locales.
  • 👁 Previews - Keyboard & theme previews for in-app use.
  • 📄 Proxy - Allow UITextDocumentProxy to read the full document.
  • 📝 Text - Allow users to type within the keyboard.
  • 🍭 Themes - A theme engine with many pre-defined themes.

Documentation

The online documentation has a thorough getting-started guide, a detailed article for each feature, code samples, etc. You can also build it from the source code to get better formatting.

Demo App

The Demo folder has a demo app that shows how to set up the main keyboard app, show keyboard status, provide in-app settings, link to system settings, apply custom styles, etc.

The app has two keyboards - a Keyboard that uses KeyboardKit and a KeyboardPro that uses KeyboardKit Pro.

Important

The demo isn't code signed and can therefore not use an App Group to sync settings between the app and its keyboards. As such, the KeyboardPro keyboard has keyboard settings in the keyboard as well.

KeyboardKit App

Download the KeyboardKit app from the App Store to try KeyboardKit without having to write any code or build the demo app from Xcode.

Support This Project

KeyboardKit is open-source and completely free, but you can support the project by becoming a GitHub Sponsor, upgrading to KeyboardKit Pro or get in touch for freelance work, paid support etc.

Contact

Feel free to reach out if you have questions or if you want to contribute in any way:

License

KeyboardKit is available under the MIT license. See the LICENSE file for more info.